base-files: ipcalc.sh: check for params before calculating start/end
authorLeon M. George <leon@georgemail.eu>
Thu, 5 May 2022 21:19:53 +0000 (23:19 +0200)
committerChristian Marangi <ansuelsmth@gmail.com>
Tue, 7 Feb 2023 20:05:52 +0000 (21:05 +0100)
With this patch, ipcalc only calculates range boundaries if the
corresponding parameters are supplied.

Signed-off-by: Leon M. George <leon@georgemail.eu>
package/base-files/files/bin/ipcalc.sh

index 5d5eac3ea80b8e0b9a11ff6139d701a9618a8149..9b2c4d2afc851f32ad90b73f0bf15761278615e9 100755 (executable)
@@ -46,14 +46,6 @@ BEGIN {
        network=and(ipaddr,netmask)
        broadcast=or(network,compl32(netmask))
 
-       start=or(network,and(ip2int(ARGV[3]),compl32(netmask)))
-       limit=network+1
-       if (start<limit) start=limit
-
-       end=start+ARGV[4]
-       limit=or(network,compl32(netmask))-1
-       if (end>limit) end=limit
-
        print "IP="int2ip(ipaddr)
        print "NETMASK="int2ip(netmask)
        print "BROADCAST="int2ip(broadcast)
@@ -63,9 +55,18 @@ BEGIN {
        # range calculations:
        # ipcalc <ip> <netmask> <start> <num>
 
-       if (ARGC > 3) {
-               print "START="int2ip(start)
-               print "END="int2ip(end)
-       }
+       if (ARGC <= 3)
+               exit(0)
+
+       start=or(network,and(ip2int(ARGV[3]),compl32(netmask)))
+       limit=network+1
+       if (start<limit) start=limit
+
+       end=start+ARGV[4]
+       limit=or(network,compl32(netmask))-1
+       if (end>limit) end=limit
+
+       print "START="int2ip(start)
+       print "END="int2ip(end)
 }
 EOF