aboutsummaryrefslogtreecommitdiffstats
path: root/package
diff options
context:
space:
mode:
authorLeon M. Busch-George <leon@georgemail.eu>2023-06-16 14:58:48 +0200
committerLeon M. Busch-George <leon@georgemail.eu>2023-09-25 15:02:49 +0200
commit59e681eea1fbf969ff6f2da315f18142b70424bd (patch)
treeaf993b5520ec23f4037aa3cbac9cccb3abb13650 /package
parent9b2f8a33b6b247d4232d48a1d18aea3769590083 (diff)
downloadupstream-59e681eea1fbf969ff6f2da315f18142b70424bd.tar.gz
upstream-59e681eea1fbf969ff6f2da315f18142b70424bd.tar.bz2
upstream-59e681eea1fbf969ff6f2da315f18142b70424bd.zip
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>
Diffstat (limited to 'package')
-rwxr-xr-xpackage/base-files/files/bin/ipcalc.sh6
1 files changed, 4 insertions, 2 deletions
diff --git a/package/base-files/files/bin/ipcalc.sh b/package/base-files/files/bin/ipcalc.sh
index c852b5163f4..ffcdfc02d8b 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: