diff options
author | Leon M. George <leon@georgemail.eu> | 2022-05-05 23:19:53 +0200 |
---|---|---|
committer | Christian Marangi <ansuelsmth@gmail.com> | 2023-02-07 21:05:52 +0100 |
commit | 00a20335ba2bac4cc33048464ba4bab070309db7 (patch) | |
tree | ec8c6579a2553ad0e300873a78634475a515b768 /package | |
parent | 4970dd027bced78f8a72aa2baed22c962d3b587b (diff) | |
download | upstream-00a20335ba2bac4cc33048464ba4bab070309db7.tar.gz upstream-00a20335ba2bac4cc33048464ba4bab070309db7.tar.bz2 upstream-00a20335ba2bac4cc33048464ba4bab070309db7.zip |
base-files: ipcalc.sh: check for params before calculating start/end
With this patch, ipcalc only calculates range boundaries if the
corresponding parameters are supplied.
Signed-off-by: Leon M. George <leon@georgemail.eu>
Diffstat (limited to 'package')
-rwxr-xr-x | package/base-files/files/bin/ipcalc.sh | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/package/base-files/files/bin/ipcalc.sh b/package/base-files/files/bin/ipcalc.sh index 5d5eac3ea8..9b2c4d2afc 100755 --- a/package/base-files/files/bin/ipcalc.sh +++ b/package/base-files/files/bin/ipcalc.sh @@ -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 |