aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files/files/bin/ipcalc.sh
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2007-03-17 13:31:13 +0000
committerFelix Fietkau <nbd@openwrt.org>2007-03-17 13:31:13 +0000
commite1bb37f2ec7aea568eee32a0c88f937a2b963c3f (patch)
tree7cae95af53894ba1bee5fa8f2c70856b4825c503 /package/base-files/files/bin/ipcalc.sh
parentf1432e60f0fbfbf3d43eea51fd0d718c241b0d76 (diff)
downloadupstream-e1bb37f2ec7aea568eee32a0c88f937a2b963c3f.tar.gz
upstream-e1bb37f2ec7aea568eee32a0c88f937a2b963c3f.tar.bz2
upstream-e1bb37f2ec7aea568eee32a0c88f937a2b963c3f.zip
upgrade dnsmasq to latest version, rewrite dnsmasq init script for uci, rename /bin/ipcalc to /bin/ipcalc.sh (fixes #1452)
SVN-Revision: 6595
Diffstat (limited to 'package/base-files/files/bin/ipcalc.sh')
-rwxr-xr-xpackage/base-files/files/bin/ipcalc.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/package/base-files/files/bin/ipcalc.sh b/package/base-files/files/bin/ipcalc.sh
new file mode 100755
index 0000000000..e8efa6b96c
--- /dev/null
+++ b/package/base-files/files/bin/ipcalc.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+awk -f /usr/lib/common.awk -f - $* <<EOF
+BEGIN {
+ ipaddr=ip2int(ARGV[1])
+ netmask=ip2int(ARGV[2])
+ network=and(ipaddr,netmask)
+ broadcast=or(network,compl(netmask))
+
+ start=or(network,and(ip2int(ARGV[3]),compl(netmask)))
+ limit=network+1
+ if (start<limit) start=limit
+
+ end=start+ARGV[4]
+ limit=or(network,compl(netmask))-1
+ if (end>limit) end=limit
+
+ print "IP="int2ip(ipaddr)
+ print "NETMASK="int2ip(netmask)
+ print "BROADCAST="int2ip(broadcast)
+ print "NETWORK="int2ip(network)
+ print "PREFIX="32-bitcount(compl(netmask))
+
+ # range calculations:
+ # ipcalc <ip> <netmask> <start> <num>
+
+ if (ARGC > 3) {
+ print "START="int2ip(start)
+ print "END="int2ip(end-1)
+ }
+}
+EOF