base-files: ipcalc.sh: fail when network is too small
It's possible to move range boundaries in a way that the start address lies behind the end address. Detect this condition and exit with an error message. Signed-off-by: Leon M. George <leon@georgemail.eu>
This commit is contained in:
parent
4fe106afd1
commit
a40a96e54b
@ -44,13 +44,14 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
|
|
||||||
network=and(ipaddr,netmask)
|
network=and(ipaddr,netmask)
|
||||||
|
prefix=32-bitcount(compl32(netmask))
|
||||||
broadcast=or(network,compl32(netmask))
|
broadcast=or(network,compl32(netmask))
|
||||||
|
|
||||||
print "IP="int2ip(ipaddr)
|
print "IP="int2ip(ipaddr)
|
||||||
print "NETMASK="int2ip(netmask)
|
print "NETMASK="int2ip(netmask)
|
||||||
print "BROADCAST="int2ip(broadcast)
|
print "BROADCAST="int2ip(broadcast)
|
||||||
print "NETWORK="int2ip(network)
|
print "NETWORK="int2ip(network)
|
||||||
print "PREFIX="32-bitcount(compl32(netmask))
|
print "PREFIX="prefix
|
||||||
|
|
||||||
# range calculations:
|
# range calculations:
|
||||||
# ipcalc <ip> <netmask> <start> <num>
|
# ipcalc <ip> <netmask> <start> <num>
|
||||||
@ -68,6 +69,11 @@ BEGIN {
|
|||||||
if (end>limit) end=limit
|
if (end>limit) end=limit
|
||||||
if (end==ipaddr) end=ipaddr-1
|
if (end==ipaddr) end=ipaddr-1
|
||||||
|
|
||||||
|
if (start>end) {
|
||||||
|
print "network ("int2ip(network)"/"prefix") too small" > "/dev/stderr"
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
if (ipaddr > start && ipaddr < end) {
|
if (ipaddr > start && ipaddr < end) {
|
||||||
print "ipaddr inside range" > "/dev/stderr"
|
print "ipaddr inside range" > "/dev/stderr"
|
||||||
exit(1)
|
exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user