Skip to content

Commit

Permalink
Use string packing instead of bitwise operators in ipOps.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Mar 9, 2017
1 parent 5fe8df5 commit a2e2252
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions nselib/ipOps.lua
Expand Up @@ -3,8 +3,6 @@
--
-- @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 string = require "string"
local table = require "table"
Expand Down Expand Up @@ -163,13 +161,7 @@ fromdword = function( ip )
stdnse.debug1("Error in ipOps.fromdword: Expected 32-bit number.")
return nil
end

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)
return string.format("%d.%d.%d.%d", string.unpack("BBBB", string.pack(">I4", ip)))
end

---
Expand Down

0 comments on commit a2e2252

Please sign in to comment.