base-files: ipcalc.sh: don't print broadcast addr for prefix > 30
authorLeon M. Busch-George <leon@georgemail.eu>
Fri, 16 Jun 2023 12:58:48 +0000 (14:58 +0200)
committerLeon M. Busch-George <leon@georgemail.eu>
Mon, 25 Sep 2023 13:02:49 +0000 (15:02 +0200)
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 <leon@georgemail.eu>
package/base-files/files/bin/ipcalc.sh

index c852b5163f493b25f95aea38368fe509d517736d..ffcdfc02d8b5f57cef2455a6e1932691c51158c2 100755 (executable)
@@ -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: