Browse Source

base-files: ipcalc.sh: correctly set limit for prefix > 30

For /31 and /32 prefixes, there are only host addresses - no network and
broadcast address with all-zero and all-one bits.
Reflect this when setting the limit.

Signed-off-by: Leon M. Busch-George <[email protected]>
Leon M. Busch-George 2 years ago
parent
commit
9b2f8a33b6
1 changed files with 10 additions and 2 deletions
  1. 10 2
      package/base-files/files/bin/ipcalc.sh

+ 10 - 2
package/base-files/files/bin/ipcalc.sh

@@ -64,13 +64,21 @@ BEGIN {
 	if (ARGC <= 3)
 		exit(0)
 
+	if (prefix<=30)
+		limit=network+1
+	else
+		limit=network
+
 	start=or(network,and(ip2int(ARGV[3]),compl32(netmask)))
-	limit=network+1
 	if (start<limit) start=limit
 	if (start==ipaddr) start=ipaddr+1
 
+	if (prefix<=30)
+		limit=or(network,compl32(netmask))-1
+	else
+		limit=or(network,compl32(netmask))
+
 	end=start+ARGV[4]-1
-	limit=or(network,compl32(netmask))-1
 	if (end>limit) end=limit
 	if (end==ipaddr) end=ipaddr-1