base-files: ipcalc.sh: support bit length as netmask parameter
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 16 Dec 2013 16:29:23 +0000 (16:29 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 16 Dec 2013 16:29:23 +0000 (16:29 +0000)
SVN-Revision: 39100

package/base-files/files/bin/ipcalc.sh

index 27a52d6f83d72d56c7a74e08c0dd8f7b445c341f..5d5eac3ea80b8e0b9a11ff6139d701a9618a8149 100755 (executable)
@@ -31,7 +31,11 @@ BEGIN {
        slpos=index(ARGV[1],"/")
        if (slpos == 0) {
                ipaddr=ip2int(ARGV[1])
        slpos=index(ARGV[1],"/")
        if (slpos == 0) {
                ipaddr=ip2int(ARGV[1])
-               netmask=ip2int(ARGV[2])
+               dotpos=index(ARGV[2],".")
+               if (dotpos == 0)
+                       netmask=compl32(2**(32-int(ARGV[2]))-1)
+               else
+                       netmask=ip2int(ARGV[2])
        } else {
                ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
                netmask=compl32(2**(32-int(substr(ARGV[1],slpos+1)))-1)
        } else {
                ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
                netmask=compl32(2**(32-int(substr(ARGV[1],slpos+1)))-1)