mirror of
https://github.com/nmap/nmap.git
synced 2025-12-18 13:39:02 +00:00
Use string packing instead of bitwise operators in ipOps.lua
This commit is contained in:
@@ -3,8 +3,6 @@
|
|||||||
--
|
--
|
||||||
-- @copyright Same as Nmap--See https://nmap.org/book/man-legal.html
|
-- @copyright Same as Nmap--See https://nmap.org/book/man-legal.html
|
||||||
|
|
||||||
local bin = require "bin"
|
|
||||||
local bit = require "bit"
|
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
local string = require "string"
|
local string = require "string"
|
||||||
local table = require "table"
|
local table = require "table"
|
||||||
@@ -163,13 +161,7 @@ fromdword = function( ip )
|
|||||||
stdnse.debug1("Error in ipOps.fromdword: Expected 32-bit number.")
|
stdnse.debug1("Error in ipOps.fromdword: Expected 32-bit number.")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
return string.format("%d.%d.%d.%d", string.unpack("BBBB", string.pack(">I4", ip)))
|
||||||
local n1 = bit.band(bit.rshift(ip, 0), 0x000000FF)
|
|
||||||
local n2 = bit.band(bit.rshift(ip, 8), 0x000000FF)
|
|
||||||
local n3 = bit.band(bit.rshift(ip, 16), 0x000000FF)
|
|
||||||
local n4 = bit.band(bit.rshift(ip, 24), 0x000000FF)
|
|
||||||
|
|
||||||
return string.format("%d.%d.%d.%d", n1, n2, n3, n4)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
Reference in New Issue
Block a user