浏览代码

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 <[email protected]>
Leon M. Busch-George 2 年之前
父节点
当前提交
59e681eea1
共有 1 个文件被更改,包括 4 次插入2 次删除
  1. 4 2
      package/base-files/files/bin/ipcalc.sh

+ 4 - 2
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: