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>
This commit is contained in:
parent
4970dd027b
commit
00a20335ba
1 changed files with 13 additions and 12 deletions
|
@ -46,14 +46,6 @@ BEGIN {
|
||||||
network=and(ipaddr,netmask)
|
network=and(ipaddr,netmask)
|
||||||
broadcast=or(network,compl32(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 "IP="int2ip(ipaddr)
|
||||||
print "NETMASK="int2ip(netmask)
|
print "NETMASK="int2ip(netmask)
|
||||||
print "BROADCAST="int2ip(broadcast)
|
print "BROADCAST="int2ip(broadcast)
|
||||||
|
@ -63,9 +55,18 @@ BEGIN {
|
||||||
# range calculations:
|
# range calculations:
|
||||||
# ipcalc <ip> <netmask> <start> <num>
|
# ipcalc <ip> <netmask> <start> <num>
|
||||||
|
|
||||||
if (ARGC > 3) {
|
if (ARGC <= 3)
|
||||||
print "START="int2ip(start)
|
exit(0)
|
||||||
print "END="int2ip(end)
|
|
||||||
}
|
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
|
EOF
|
||||||
|
|
Loading…
Reference in a new issue