1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-15 20:29:03 +00:00

Utility function to sort a table by IP address

This commit is contained in:
dmiller
2018-01-25 16:12:50 +00:00
parent b7b29b0145
commit b39cac1d7f

View File

@@ -260,7 +260,17 @@ compare_ip = function( left, op, right )
return nil, "Error in ipOps.compare_ip: Invalid Operator."
end
--- Sorts a table of IP addresses
--
-- An in-place sort using <code>table.sort</code> to sort by IP address.
-- Sorting non-IP addresses is likely to result in a bad sort and possibly an infinite loop.
--
-- @param ips The table of IP addresses to sort
-- @param op The comparison operation to use. Default: "lt" (ascending)
ip_sort = function (ips, op)
op = op or "lt"
return table.sort(ips, function(a, b) return compare_ip(a, op, b) end)
end
---
-- Checks whether the supplied IP address is within the supplied range of IP