1
0
mirror of https://git.openwrt.org/openwrt/openwrt.git synced 2024-10-19 05:58:53 +02:00

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 <leon@georgemail.eu>
This commit is contained in:
Leon M. Busch-George 2023-06-16 14:58:48 +02:00
parent 9b2f8a33b6
commit 59e681eea1

@ -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: