99269fff066f99176ad5802d7005eb53e6e29fca
4 c
=and
(rshift
(c
, 1),0x55555555)+and
(c
,0x55555555)
5 c
=and
(rshift
(c
, 2),0x33333333)+and
(c
,0x33333333)
6 c
=and
(rshift
(c
, 4),0x0f0f0f0f)+and
(c
,0x0f0f0f0f)
7 c
=and
(rshift
(c
, 8),0x00ff00ff)+and
(c
,0x00ff00ff)
8 c
=and
(rshift
(c
,16),0x0000ffff)+and
(c
,0x0000ffff)
16 ret
=or
(lshift
(ret
,8),a
[x
])
20 function int2ip
(ip
,ret
,x
) {
31 ret
=xor
(v
, 0xffffffff)
36 slpos
=index
(ARGV
[1],"/")
38 ipaddr
=ip2int
(ARGV
[1])
39 dotpos
=index
(ARGV
[2],".")
41 netmask
=compl32
(2**(32-int(ARGV
[2]))-1)
43 netmask
=ip2int
(ARGV
[2])
45 ipaddr
=ip2int
(substr
(ARGV
[1],0,slpos-1
))
46 netmask
=compl32
(2**(32-int(substr
(ARGV
[1],slpos
+1)))-1)
51 network
=and
(ipaddr
,netmask
)
52 prefix
=32-bitcount(compl32
(netmask
))
53 broadcast
=or
(network
,compl32
(netmask
))
55 print
"IP="int2ip
(ipaddr
)
56 print
"NETMASK="int2ip
(netmask
)
57 print
"BROADCAST="int2ip
(broadcast
)
58 print
"NETWORK="int2ip
(network
)
62 # ipcalc <ip> <netmask> <start> <num>
67 start
=or
(network
,and
(ip2int
(ARGV
[3]),compl32
(netmask
)))
69 if (start
<limit
) start
=limit
70 if (start
==ipaddr
) start
=ipaddr
+1
73 limit
=or
(network
,compl32
(netmask
))-1
74 if (end
>limit
) end
=limit
75 if (end
==ipaddr
) end
=ipaddr-1
78 print
"network ("int2ip
(network
)"/"prefix
") too small" > "/dev/stderr"
82 if (ipaddr
> start
&& ipaddr
< end
) {
83 print
"ipaddr inside range" > "/dev/stderr"
87 print
"START="int2ip
(start
)
88 print
"END="int2ip
(end
)