mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 12:41:29 +00:00
Collapse Packet.ether_parse() into the constructor.
It was called from there anyway and never called on its own from elsewhere. Furthermore, its documentation did not match its behavior.
This commit is contained in:
@@ -147,18 +147,20 @@ ETHER_TYPE_ATAOE = 0x88a2
|
|||||||
Frame = {}
|
Frame = {}
|
||||||
|
|
||||||
function Frame:new(frame, force_continue)
|
function Frame:new(frame, force_continue)
|
||||||
local packet = nil
|
local mac_dst, mac_src, ether_type, packet
|
||||||
local packet_len = 0
|
if frame and #frame >= 14 then
|
||||||
if frame and #frame > 14 then
|
local pos
|
||||||
packet = string.sub(frame, 15, -1)
|
mac_dst, mac_src, ether_type, pos = ("c6c6>I2"):unpack(frame)
|
||||||
packet_len = #frame - 14
|
packet = frame:sub(pos, -1)
|
||||||
|
if #packet == 0 then packet = nil end
|
||||||
end
|
end
|
||||||
local o = Packet:new(packet, packet_len, force_continue)
|
local o = Packet:new(packet, packet and #packet or 0, force_continue)
|
||||||
|
|
||||||
o.build_ether_frame = self.build_ether_frame
|
o.build_ether_frame = self.build_ether_frame
|
||||||
o.ether_parse = self.ether_parse
|
|
||||||
o.frame_buf = frame
|
o.frame_buf = frame
|
||||||
o:ether_parse()
|
o.mac_dst = mac_dst
|
||||||
|
o.mac_src = mac_src
|
||||||
|
o.ether_type = ether_type
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
--- Build an Ethernet frame.
|
--- Build an Ethernet frame.
|
||||||
@@ -177,19 +179,6 @@ function Frame:build_ether_frame(mac_dst, mac_src, ether_type, packet)
|
|||||||
end
|
end
|
||||||
self.frame_buf = self.mac_dst..self.mac_src..(">I2"):pack(self.ether_type)..self.buf
|
self.frame_buf = self.mac_dst..self.mac_src..(">I2"):pack(self.ether_type)..self.buf
|
||||||
end
|
end
|
||||||
--- Parse an Ethernet frame.
|
|
||||||
-- @param frame string of the Ether frame.
|
|
||||||
-- @return mac_dst six-byte string of the destination MAC address.
|
|
||||||
-- @return mac_src six-byte string of the source MAC address.
|
|
||||||
-- @return packet string of the payload.
|
|
||||||
function Frame:ether_parse()
|
|
||||||
if not self.frame_buf or #self.frame_buf < 14 then -- too short
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
self.mac_dst = string.sub(self.frame_buf, 1, 6)
|
|
||||||
self.mac_src = string.sub(self.frame_buf, 7, 12)
|
|
||||||
self.ether_type = u16(self.frame_buf, 12)
|
|
||||||
end
|
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------
|
||||||
-- Packet is a class
|
-- Packet is a class
|
||||||
|
|||||||
Reference in New Issue
Block a user