From e87c25a435dccc3ef23453ae9ad096c0fc6b2686 Mon Sep 17 00:00:00 2001 From: Michael Gebetsroither Date: Tue, 8 Nov 2005 18:16:33 +0100 Subject: [PATCH] added netGetIfaces() --- debian/changelog | 4 +++- debian/control | 2 +- sh-lib | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index d1a57f2..01ee267 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,10 @@ sh-lib (1.02.04) unstable; urgency=low * added TODO + * added iproute to dependencies (ip) + * added netGetIfaces() - -- Michael Gebetsroither Wed, 5 Oct 2005 18:42:31 +0200 + -- Michael Gebetsroither Tue, 8 Nov 2005 18:10:49 +0100 sh-lib (1.02.03) unstable; urgency=low diff --git a/debian/control b/debian/control index 1f4e966..19a6d4d 100644 --- a/debian/control +++ b/debian/control @@ -7,6 +7,6 @@ Standards-Version: 3.6.1 Package: sh-lib Architecture: all -Depends: ${misc:Depends}, procps, net-tools, gawk +Depends: ${misc:Depends}, procps, net-tools, gawk, iproute Description: Generic shell library The sh-lib is developed on zsh, only partially tested on bash. diff --git a/sh-lib b/sh-lib index 2183b56..4d858a9 100644 --- a/sh-lib +++ b/sh-lib @@ -428,6 +428,28 @@ function netValidIp return $ret_ } +function netGetIfaces +{ + local error_function_=${1:-"eprint"} # function to call on error + local message_="$2" # user supplied error message + local if_='' + local ret_='' + + #ip a|grep 'inet ' |awk '$NF !~ /lo/{print $NF}' + if_="`ip a|grep 'inet ' |awk '{print $NF}'`" + ret_=$? + if [ -z "$if_" ]; then + if [ -z "$message_" ]; then + "$error_function_" "no interfaces found" $ret_ + else + "$error_function_" "$message_" $ret_ + fi + return 1 + fi + dprint "interfaces found" $ret_ + echo "$if_" +} + # FIXME function netGetDefaultGateway { -- 2.1.4