From f02cddd7808478104c21fc33a934d5e7c136d552 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 14 Jun 2009 13:40:27 -0700 Subject: [PATCH] Restore find_first_interface_address and find_first_interface_address_if_any --- Shorewall/lib.base | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Shorewall/lib.base b/Shorewall/lib.base index 43e0af5bf..837b52f94 100644 --- a/Shorewall/lib.base +++ b/Shorewall/lib.base @@ -598,6 +598,40 @@ chain_exists() # $1 = chain name qt $IPTABLES -L $1 -n } +# +# Find interface address--returns the first IP address assigned to the passed +# device +# +find_first_interface_address() # $1 = interface +{ + # + # get the line of output containing the first IP address + # + addr=$(ip -f inet addr show $1 2> /dev/null | grep 'inet .* global' | head -n1) + # + # If there wasn't one, bail out now + # + [ -n "$addr" ] || fatal_error "Can't determine the IP address of $1" + # + # Strip off the trailing VLSM mask (or the peer IP in case of a P-t-P link) + # along with everything else on the line + # + echo $addr | sed 's/\s*inet //;s/\/.*//;s/ peer.*//' +} + +find_first_interface_address_if_any() # $1 = interface +{ + # + # get the line of output containing the first IP address + # + addr=$(ip -f inet addr show $1 2> /dev/null | grep 'inet .* global' | head -n1) + # + # Strip off the trailing VLSM mask (or the peer IP in case of a P-t-P link) + # along with everything else on the line + # + [ -n "$addr" ] && echo $addr | sed 's/\s*inet //;s/\/.*//;s/ peer.*//' || echo 0.0.0.0 +} + # # Internal version of 'which' #