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

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