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

Make packet.in_cksum more efficient by not making lots of substring

copies.
This commit is contained in:
david
2009-10-29 00:28:29 +00:00
parent 9817ee470d
commit bef983abdd

View File

@@ -74,16 +74,16 @@ end
-- @return Checksum.
function in_cksum(b)
local sum = 0
local c
local x = b
local i
while x:len() > 1 do
c = x:sub(1,2)
x = x:sub(3)
sum = sum + u16(c, 0)
-- Note we are using 0-based indexes here.
i = 0
while i < b:len() - 1 do
sum = sum + u16(b, i)
i = i + 2
end
if x:len() == 1 then
sum = sum + u8(x, 0) * 256
if i < b:len() then
sum = sum + u8(b, i) * 256
end
sum = bit.rshift(sum, 16) + bit.band(sum, 0xffff)