diff options
author | Steven Barth <cyrus@openwrt.org> | 2014-10-09 07:16:29 +0000 |
---|---|---|
committer | Steven Barth <cyrus@openwrt.org> | 2014-10-09 07:16:29 +0000 |
commit | 14e6559eee9202d17f99493b5c7603b369c56294 (patch) | |
tree | 77b7c02f14d8ef59ba6f36af2ce2a03d6096e346 /package/base-files/files/lib/functions/network.sh | |
parent | 8a4c2890c8a312c6692611d66c5963d8691b635c (diff) | |
download | upstream-14e6559eee9202d17f99493b5c7603b369c56294.tar.gz upstream-14e6559eee9202d17f99493b5c7603b369c56294.tar.bz2 upstream-14e6559eee9202d17f99493b5c7603b369c56294.zip |
base-files: add network_get_ipaddrs_all()
Return all IPv4 and IPv6 addresses.
Signed-off-by: Mathias Kresin <openwrt@kresin.me>
SVN-Revision: 42856
Diffstat (limited to 'package/base-files/files/lib/functions/network.sh')
-rw-r--r-- | package/base-files/files/lib/functions/network.sh | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh index 3a6903f2de..1b0c717204 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 |