[OpenWrt-Devel] [PATCH 1/2] base-files: add network_get_ipaddrs_all()

Mathias Kresin openwrt at kresin.me
Mon Oct 6 13:46:29 EDT 2014


Return all IPv4 and IPv6 addresses.

Signed-off-by: Mathias Kresin <openwrt at kresin.me>
---
 package/base-files/files/lib/functions/network.sh | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh
index 3a6903f..1b0c717 100644
--- a/package/base-files/files/lib/functions/network.sh
+++ b/package/base-files/files/lib/functions/network.sh
@@ -94,6 +94,29 @@ network_get_ipaddrs6() {
 	return 1
 }
 
+# determine all IP addresses of given logical interface
+# 1: destination variable
+# 2: interface
+network_get_ipaddrs_all() {
+	local __addr
+	local __list=""
+
+	if __network_ifstatus "__addr" "$2" "['ipv4-address','ipv6-address','ipv6-prefix-assignment'][*].address"; then
+		for __addr in $__addr; do
+			case "$__addr" in
+				*:) __list="${__list:+$__list }${__addr}1" ;;
+				*)  __list="${__list:+$__list }${__addr}"  ;;
+			esac
+		done
+
+		export "$1=$__list"
+		return 0
+	fi
+
+	unset "$1"
+	return 1
+}
+
 # determine all IPv4 subnets of given logical interface
 # 1: destination variable
 # 2: interface
-- 
1.9.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list