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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user