mirror of
https://github.com/nmap/nmap.git
synced 2025-12-09 22:21:29 +00:00
Fix UDP checksum for IPv6 in packet.lua
This commit is contained in:
@@ -974,6 +974,7 @@ end
|
|||||||
-- @return Whether the parsing succeeded.
|
-- @return Whether the parsing succeeded.
|
||||||
function Packet:udp_parse(force_continue)
|
function Packet:udp_parse(force_continue)
|
||||||
self.udp = true
|
self.udp = true
|
||||||
|
self.ip_p = self.ip_p or IPPROTO_UDP
|
||||||
self.udp_offset = self.ip_data_offset or self.ip6_data_offset
|
self.udp_offset = self.ip_data_offset or self.ip6_data_offset
|
||||||
if #self.buf < self.udp_offset + 4 then
|
if #self.buf < self.udp_offset + 4 then
|
||||||
return false
|
return false
|
||||||
@@ -1035,15 +1036,17 @@ end
|
|||||||
-- Count and save the UDP checksum field.
|
-- Count and save the UDP checksum field.
|
||||||
function Packet:udp_count_checksum()
|
function Packet:udp_count_checksum()
|
||||||
self:udp_set_checksum(0)
|
self:udp_set_checksum(0)
|
||||||
local proto = self.ip_p
|
local pseudo_header
|
||||||
local length = self.buf:len() - self.udp_offset
|
local payload = self.buf:sub(self.udp_offset+1)
|
||||||
local b = self.ip_bin_src ..
|
if self.ip_v == 4 then
|
||||||
self.ip_bin_dst ..
|
pseudo_header = (">c4 c4 x B I2"):pack(self.ip_bin_src, self.ip_bin_dst,
|
||||||
"\0" ..
|
IPPROTO_UDP, #payload)
|
||||||
(">BI2"):pack(proto, length) ..
|
elseif self.ip_v == 6 then
|
||||||
self.buf:sub(self.udp_offset+1)
|
pseudo_header = (">c16 c16 I4 xxx B"):pack(self.ip_bin_src, self.ip_bin_dst,
|
||||||
|
#payload, IPPROTO_UDP)
|
||||||
|
end
|
||||||
|
|
||||||
self:udp_set_checksum(in_cksum(b))
|
self:udp_set_checksum(in_cksum(pseudo_header .. payload))
|
||||||
end
|
end
|
||||||
|
|
||||||
if not unittest.testing() then
|
if not unittest.testing() then
|
||||||
|
|||||||
Reference in New Issue
Block a user