source: trunk/package/base-files/files/bin/ipcalc.sh @ 16619

Last change on this file since 16619 was 16619, checked in by jow, 7 years ago

[package] base-files: ipcalc.sh: fix off-by-one in range-calculation

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 686 bytes
Line 
1#!/bin/sh
2
3awk -f /usr/lib/common.awk -f - $* <<EOF
4BEGIN {
5        ipaddr=ip2int(ARGV[1])
6        netmask=ip2int(ARGV[2])
7        network=and(ipaddr,netmask)
8        broadcast=or(network,compl(netmask))
9       
10        start=or(network,and(ip2int(ARGV[3]),compl(netmask)))
11        limit=network+1
12        if (start<limit) start=limit
13       
14        end=start+ARGV[4]
15        limit=or(network,compl(netmask))-1
16        if (end>limit) end=limit
17
18        print "IP="int2ip(ipaddr)
19        print "NETMASK="int2ip(netmask)
20        print "BROADCAST="int2ip(broadcast)
21        print "NETWORK="int2ip(network)
22        print "PREFIX="32-bitcount(compl(netmask))
23       
24        # range calculations:
25        # ipcalc <ip> <netmask> <start> <num>
26       
27        if (ARGC > 3) {
28                print "START="int2ip(start)
29                print "END="int2ip(end)
30        }
31}
32EOF
Note: See TracBrowser for help on using the repository browser.