mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 12:41:29 +00:00
Adds Pong response, closes #383
This commit is contained in:
@@ -188,6 +188,26 @@ Request = {
|
||||
return bin.pack("<IAII", 0xD9B4BEF9, "verack\0\0\0\0\0\0", 0, 0xe2e0f65d)
|
||||
end,
|
||||
|
||||
},
|
||||
|
||||
-- The pong message is sent in response to a ping message.
|
||||
Pong = {
|
||||
new = function(self)
|
||||
local o = {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end,
|
||||
|
||||
__tostring = function(self)
|
||||
local magic = 0xD9B4BEF9
|
||||
local cmd = "pong\0\0\0\0\0\0\0\0"
|
||||
local len = 0
|
||||
local chksum = 0xe2e0f65d
|
||||
|
||||
return bin.pack("<IAII", magic, cmd, len, chksum)
|
||||
end,
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -384,12 +404,24 @@ Response = {
|
||||
local pos, magic, cmd, len, checksum = bin.unpack("<IA12II", header)
|
||||
local data = ""
|
||||
|
||||
-- the verack has no payload
|
||||
-- the verack and ping has no payload
|
||||
if ( 0 ~= len ) then
|
||||
status, data = socket:receive_buf(match.numbytes(len), true)
|
||||
if ( not(status) ) then
|
||||
return false, "Failed to read the packet header"
|
||||
end
|
||||
else
|
||||
-- The ping message is sent primarily to confirm that the TCP/IP connection is still valid.
|
||||
if( cmd == "ping\0\0\0\0\0\0\0\0" ) then
|
||||
local req = Request.Pong:new()
|
||||
|
||||
local status, err = socket:send(tostring(req))
|
||||
if ( not(status) ) then
|
||||
return false, "Failed to send \"Pong\" reply to server"
|
||||
else
|
||||
return Response.recvPacket(socket, version)
|
||||
end
|
||||
end
|
||||
end
|
||||
return Response.decode(header .. data, version)
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user