diff --git a/nselib/rpc.lua b/nselib/rpc.lua index 03955ceaa..0f434b4ca 100644 --- a/nselib/rpc.lua +++ b/nselib/rpc.lua @@ -164,26 +164,28 @@ Comm = { return status, err end if ( port.protocol == "tcp" ) then - socket = nmap.new_socket() if nmap.is_privileged() then -- Try to bind to a reserved port for resvport = 600, 1024, 1 do + socket = nmap.new_socket() status, err = socket:bind(nil, resvport) if status then status, err = socket:connect(host, port) if status then break end + socket:close() end end else status, err = socket:connect(host, port) end else - socket = nmap.new_socket("udp") if nmap.is_privileged() then -- Try to bind to a reserved port for resvport = 600, 1024, 1 do + socket = nmap.new_socket("udp") status, err = socket:bind(nil, resvport) if status then break end + socket:close() end end end