mirror of
https://github.com/nmap/nmap.git
synced 2025-12-16 12:49: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 )
|
local first, last, err = ipOps.get_ips_from_range( range )
|
||||||
if err then return nil end
|
if err then return nil end
|
||||||
|
|
||||||
first = ipOps.ip_to_bin( first ):reverse()
|
first = ipOps.ip_to_bin(first)
|
||||||
last = ipOps.ip_to_bin( last ):reverse()
|
last = ipOps.ip_to_bin(last)
|
||||||
|
|
||||||
local hostbits = 0
|
for pos = 1, #first do
|
||||||
for pos = 1, # first , 1 do
|
if first:sub(pos, pos) ~= last:sub(pos, pos) then
|
||||||
|
return pos - 1
|
||||||
if first:sub( pos, pos ) == "0" and last:sub( pos, pos ) == "1" then
|
end
|
||||||
hostbits = hostbits + 1
|
|
||||||
else
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
return #first
|
||||||
|
|
||||||
return ( # first - hostbits )
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -434,21 +434,16 @@ function get_prefix_length( range )
|
|||||||
local first, last, err = ipOps.get_ips_from_range( range )
|
local first, last, err = ipOps.get_ips_from_range( range )
|
||||||
if err then return nil end
|
if err then return nil end
|
||||||
|
|
||||||
first = ipOps.ip_to_bin( first ):reverse()
|
first = ipOps.ip_to_bin(first)
|
||||||
last = ipOps.ip_to_bin( last ):reverse()
|
last = ipOps.ip_to_bin(last)
|
||||||
|
|
||||||
local hostbits = 0
|
for pos = 1, #first do
|
||||||
for pos = 1, string.len( first ), 1 do
|
if first:sub(pos, pos) ~= last:sub(pos, pos) then
|
||||||
|
return pos - 1
|
||||||
if first:sub( pos, pos ) == "0" and last:sub( pos, pos ) == "1" then
|
end
|
||||||
hostbits = hostbits + 1
|
|
||||||
else
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
return #first
|
||||||
|
|
||||||
return ( string.len( first ) - hostbits )
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user