1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 20:51:30 +00:00

Adds Pong response, closes #383

This commit is contained in:
abhishek
2016-05-24 19:23:20 +00:00
parent 4d67d58d04
commit c7852c6ec0

View File

@@ -188,6 +188,26 @@ Request = {
return bin.pack("<IAII", 0xD9B4BEF9, "verack\0\0\0\0\0\0", 0, 0xe2e0f65d) return bin.pack("<IAII", 0xD9B4BEF9, "verack\0\0\0\0\0\0", 0, 0xe2e0f65d)
end, 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 pos, magic, cmd, len, checksum = bin.unpack("<IA12II", header)
local data = "" local data = ""
-- the verack has no payload -- the verack and ping has no payload
if ( 0 ~= len ) then if ( 0 ~= len ) then
status, data = socket:receive_buf(match.numbytes(len), true) status, data = socket:receive_buf(match.numbytes(len), true)
if ( not(status) ) then if ( not(status) ) then
return false, "Failed to read the packet header" return false, "Failed to read the packet header"
end 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 end
return Response.decode(header .. data, version) return Response.decode(header .. data, version)
end, end,