From 59e681eea1fbf969ff6f2da315f18142b70424bd Mon Sep 17 00:00:00 2001 From: "Leon M. Busch-George" Date: Fri, 16 Jun 2023 14:58:48 +0200 Subject: [PATCH] base-files: ipcalc.sh: don't print broadcast addr for prefix > 30 Printing a broadcast address doesn't make any sense for /31 and /32 prefixes. Strictly speaking, the same goes for the network address but it is useful to get the first address in the prefix, e.g. to create a canonical CIDR notation "$NETWORK/$PREFIX". Signed-off-by: Leon M. Busch-George --- package/base-files/files/bin/ipcalc.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package/base-files/files/bin/ipcalc.sh b/package/base-files/files/bin/ipcalc.sh index c852b5163f49..ffcdfc02d8b5 100755 --- a/package/base-files/files/bin/ipcalc.sh +++ b/package/base-files/files/bin/ipcalc.sh @@ -50,12 +50,14 @@ BEGIN { network=and(ipaddr,netmask) prefix=32-bitcount(compl32(netmask)) - broadcast=or(network,compl32(netmask)) print "IP="int2ip(ipaddr) print "NETMASK="int2ip(netmask) - print "BROADCAST="int2ip(broadcast) print "NETWORK="int2ip(network) + if (prefix<=30) { + broadcast=or(network,compl32(netmask)) + print "BROADCAST="int2ip(broadcast) + } print "PREFIX="prefix # range calculations: -- 2.30.2