From 8c1e5f9500eae292e936aa524e7e0e3bba2c99f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sun, 22 Aug 2021 09:50:25 +0200 Subject: [PATCH 1/2] 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). --- miniupnpd/testgetifaddr.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/miniupnpd/testgetifaddr.sh b/miniupnpd/testgetifaddr.sh index 7ad56d9..90a9628 100755 --- a/miniupnpd/testgetifaddr.sh +++ b/miniupnpd/testgetifaddr.sh @@ -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 From 2087e14b8e7874dd7581c78e6b06c55daf538630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sun, 22 Aug 2021 09:53:31 +0200 Subject: [PATCH 2/2] testgetifaddr.sh: Always use the first IP addr from 'ip -4 addr' Terminate the awk after getting the first interface name and IP address from 'ip -4 addr' output. Otherwise, the test fails if the interface in question has multiple IP addresses, as the test program returns the first address, while awk prints all. --- miniupnpd/testgetifaddr.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/miniupnpd/testgetifaddr.sh b/miniupnpd/testgetifaddr.sh index 90a9628..2a26a24 100755 --- a/miniupnpd/testgetifaddr.sh +++ b/miniupnpd/testgetifaddr.sh @@ -12,8 +12,8 @@ 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`" + EXTIF="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/[0-9]+:/ { print $2; exit 0 }' | cut -d ":" -f 1`" + EXTIP="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/inet/ { print $2; exit 0 }' | cut -d "/" -f 1`" ;; esac