base-files: ipcalc.sh: correctly set limit for prefix > 30
authorLeon M. Busch-George <leon@georgemail.eu>
Fri, 16 Jun 2023 12:56:39 +0000 (14:56 +0200)
committerLeon M. Busch-George <leon@georgemail.eu>
Mon, 25 Sep 2023 13:02:49 +0000 (15:02 +0200)
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 <leon@georgemail.eu>
package/base-files/files/bin/ipcalc.sh

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