testgetifaddr.sh: Implement EXTIF fallback to 'ip -4 addr'

Fall back to getting the interface name from 'ip -4 addr' when there
is no default route.  In this case, the test simply uses the interface
providing the IP address for 'ip -4 addr' (since the command is
implicitly called with no interface argument).
This commit is contained in:
Michał Górny 2021-08-22 09:50:25 +02:00
parent 2c4acd0d50
commit 8c1e5f9500
1 changed files with 1 additions and 0 deletions

View File

@ -12,6 +12,7 @@ case $OS in
*)
IP="`which ip`" || exit 1
EXTIF="`LC_ALL=C $IP -4 route | grep 'default' | sed -e 's/.*dev[[:space:]]*//' -e 's/[[:space:]].*//'`" || exit 1
EXTIF="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/[0-9]+:/ { print $2 }' | cut -d ":" -f 1`"
EXTIP="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/inet/ { print $2 }' | cut -d "/" -f 1`"
;;
esac