mirror of
https://github.com/nmap/nmap.git
synced 2026-10-20 19:01:56 +00:00
Simplifies code; possibly ipOps candidate
This commit is contained in:
parent
3fc825b15e
commit
1e1f7c80c2
2 changed files with 12 additions and 22 deletions
|
|
@ -366,21 +366,16 @@ function get_prefix_length( range )
|
|||
local first, last, err = ipOps.get_ips_from_range( range )
|
||||
if err then return nil end
|
||||
|
||||
first = ipOps.ip_to_bin( first ):reverse()
|
||||
last = ipOps.ip_to_bin( last ):reverse()
|
||||
first = ipOps.ip_to_bin(first)
|
||||
last = ipOps.ip_to_bin(last)
|
||||
|
||||
local hostbits = 0
|
||||
for pos = 1, # first , 1 do
|
||||
|
||||
if first:sub( pos, pos ) == "0" and last:sub( pos, pos ) == "1" then
|
||||
hostbits = hostbits + 1
|
||||
else
|
||||
break
|
||||
for pos = 1, #first do
|
||||
if first:sub(pos, pos) ~= last:sub(pos, pos) then
|
||||
return pos - 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return ( # first - hostbits )
|
||||
return #first
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -434,21 +434,16 @@ function get_prefix_length( range )
|
|||
local first, last, err = ipOps.get_ips_from_range( range )
|
||||
if err then return nil end
|
||||
|
||||
first = ipOps.ip_to_bin( first ):reverse()
|
||||
last = ipOps.ip_to_bin( last ):reverse()
|
||||
first = ipOps.ip_to_bin(first)
|
||||
last = ipOps.ip_to_bin(last)
|
||||
|
||||
local hostbits = 0
|
||||
for pos = 1, string.len( first ), 1 do
|
||||
|
||||
if first:sub( pos, pos ) == "0" and last:sub( pos, pos ) == "1" then
|
||||
hostbits = hostbits + 1
|
||||
else
|
||||
break
|
||||
for pos = 1, #first do
|
||||
if first:sub(pos, pos) ~= last:sub(pos, pos) then
|
||||
return pos - 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return ( string.len( first ) - hostbits )
|
||||
return #first
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue