From: Leon M. Busch-George Date: Fri, 16 Jun 2023 12:58:48 +0000 (+0200) Subject: base-files: ipcalc.sh: don't print broadcast addr for prefix > 30 X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=59e681eea1fbf969ff6f2da315f18142b70424bd;p=openwrt%2Fstaging%2Fdangole.git 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 --- diff --git a/package/base-files/files/bin/ipcalc.sh b/package/base-files/files/bin/ipcalc.sh index c852b5163f..ffcdfc02d8 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: