RHEL ships a special ipset[1] tool with different output in corner-cases than the common one[2]: * Reduced output with /32 netmasks: | # ipcalc 255.255.255.254/32 | Address: 255.255.255.254 | Address space: Reserved To cover for this, make net_last_addr() fall back to the 'Address:' line. Simply adding this keyword is fine as in normal output it appears first and thus the other recognized keywords' values take precedence. * No "Address:" line with all-zero addresses: | # ipcalc 0.0.0.0/1 | Network: 0.0.0.0/1 | Netmask: 128.0.0.0 = 1 | Broadcast: 127.255.255.255 | | Address space: This host on this network | HostMin: 0.0.0.1 | HostMax: 127.255.255.254 | Hosts/Net: 2147483646 Have net_first_addr() fall back to the 'HostMin:' line in this case. [1] https://gitlab.com/ipcalc/ipcalc [2] http://jodies.de/ipcalc Fixes: e24e7656b3dd9 ("tests: cidr.sh: Add ipcalc fallback") Signed-off-by: Phil Sutter <phil@xxxxxx> --- tests/cidr.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/cidr.sh b/tests/cidr.sh index ca01f063dee34..abb69b835ffd8 100755 --- a/tests/cidr.sh +++ b/tests/cidr.sh @@ -46,7 +46,7 @@ if which netmask >/dev/null 2>&1; then } elif which ipcalc >/dev/null 2>&1; then net_first_addr() { - ipcalc $1 | awk '/^Address:/{print $2}' + ipcalc $1 | awk '/^(Address|HostMin):/{print $2; exit}' } net_last_addr() { # Netmask tool prints broadcast address as last one, so @@ -54,6 +54,7 @@ elif which ipcalc >/dev/null 2>&1; then # being recognized as special by ipcalc. ipcalc $1 | awk '/^(Hostroute|HostMax):/{out=$2} /^Broadcast:/{out=$2} + /^Address:/{out=$2} END{print out}' } else -- 2.47.0