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

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