Blame SOURCES/0290-network-net-lib.sh-add-is_ip.patch

712866
From d5447330844a1f16d927d42cd1d96c5425133aad Mon Sep 17 00:00:00 2001
712866
From: Harald Hoyer <harald@redhat.com>
712866
Date: Wed, 12 Aug 2015 14:24:05 +0200
712866
Subject: [PATCH] network/net-lib.sh: add is_ip()
712866
712866
add function to test if string is a valid IP
712866
712866
(cherry picked from commit 01b23b6900eabefbfd1f589b9f12c8ff38c5afc0)
712866
---
712866
 modules.d/40network/net-lib.sh | 12 ++++++++++++
712866
 1 file changed, 12 insertions(+)
712866
712866
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
5c6c2a
index cfc06feb..44c1bf04 100755
712866
--- a/modules.d/40network/net-lib.sh
712866
+++ b/modules.d/40network/net-lib.sh
712866
@@ -2,6 +2,18 @@
712866
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
712866
 # ex: ts=8 sw=4 sts=4 et filetype=sh
712866
 
712866
+is_ip() {
712866
+    echo "$1" | {
712866
+        IFS=. read a b c d
712866
+        test "$a" -ge 0 -a "$a" -le 255 \
712866
+             -a "$b" -ge 0 -a "$b" -le 255 \
712866
+             -a "$c" -ge 0 -a "$c" -le 255 \
712866
+             -a "$d" -ge 0 -a "$d" -le 255 \
712866
+             2> /dev/null
712866
+    } && return 0
712866
+    return 1
712866
+}
712866
+
712866
 get_ip() {
712866
     local iface="$1" ip=""
712866
     ip=$(ip -o -f inet addr show $iface)