1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-14 19:59:02 +00:00

Simplifies code; possibly ipOps candidate

This commit is contained in:
nnposter
2018-08-05 21:29:37 +00:00
parent 3fc825b15e
commit 1e1f7c80c2
2 changed files with 12 additions and 22 deletions

View File

@@ -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

View File

@@ -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