base-files: ipcalc.sh: Should take netmask or prefix after slash
dnmasq.init now invokes ipcalc.sh as either: ipcalc.sh address/netmask ... or: ipcalc.sh address/prefix but the existing version doesn't accept the 2nd notation. We're trying to rationalize the usage of ipcalc.sh, and here we add support for the 2nd format. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
This commit is contained in:
parent
e9ac1b19e0
commit
1481d5cb0b
1 changed files with 10 additions and 10 deletions
|
@ -34,19 +34,19 @@ function compl32(v) {
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
slpos=index(ARGV[1],"/")
|
slpos=index(ARGV[1],"/")
|
||||||
if (slpos == 0) {
|
if (slpos != 0) {
|
||||||
|
# rearrange arguments to not use compound notation
|
||||||
|
ARGV[4]=ARGV[3]
|
||||||
|
ARGV[3]=ARGV[2]
|
||||||
|
ARGV[2]=substr(ARGV[1],slpos+1)
|
||||||
|
ARGV[1]=substr(ARGV[1],0,slpos-1)
|
||||||
|
}
|
||||||
ipaddr=ip2int(ARGV[1])
|
ipaddr=ip2int(ARGV[1])
|
||||||
dotpos=index(ARGV[2],".")
|
dotpos=index(ARGV[2],".")
|
||||||
if (dotpos == 0)
|
if (dotpos == 0)
|
||||||
netmask=compl32(2**(32-int(ARGV[2]))-1)
|
netmask=compl32(2**(32-int(ARGV[2]))-1)
|
||||||
else
|
else
|
||||||
netmask=ip2int(ARGV[2])
|
netmask=ip2int(ARGV[2])
|
||||||
} else {
|
|
||||||
ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
|
|
||||||
netmask=compl32(2**(32-int(substr(ARGV[1],slpos+1)))-1)
|
|
||||||
ARGV[4]=ARGV[3]
|
|
||||||
ARGV[3]=ARGV[2]
|
|
||||||
}
|
|
||||||
|
|
||||||
network=and(ipaddr,netmask)
|
network=and(ipaddr,netmask)
|
||||||
prefix=32-bitcount(compl32(netmask))
|
prefix=32-bitcount(compl32(netmask))
|
||||||
|
|
Loading…
Reference in a new issue