From abbe5324bd1fee4d3700a8ba8bbccb76eb157946 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 16 Aug 2010 17:41:57 +0000 Subject: [PATCH] Pass host and port tables instead of host.ip and port.number in http.lua and comm.lua. --- nselib/comm.lua | 20 ++++---------------- nselib/http.lua | 6 +----- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/nselib/comm.lua b/nselib/comm.lua index 34ab464ed..67caaf23a 100644 --- a/nselib/comm.lua +++ b/nselib/comm.lua @@ -40,23 +40,13 @@ end -- Sets up the socket and connects to host:port local setup_connect = function(host, port, opts) - if type(host) ~= "table" then - host = {ip = host} - end - - local target = host.ip - - if type(port) ~= "table" then - port = {number = port} - end - local sock = nmap.new_socket() if opts.timeout then sock:set_timeout(opts.timeout) end - local status, err = sock:connect(target, port.number, opts.proto) + local status, err = sock:connect(host, port, opts.proto) if not status then return status, err @@ -187,7 +177,7 @@ end -- -- Default timeout is set to 8000. -- --- @param ip The destination host IP +-- @param host The destination host IP -- @param port The destination host port -- @param protocol The protocol for the connection -- @param data The first data payload of the connection @@ -195,7 +185,7 @@ end -- @return response The response received for the payload -- @return early_resp If opt recv_before is true, returns the value -- of the first receive (before sending data) -local function opencon(ip, port, protocol, data, opts) +local function opencon(host, port, protocol, data, opts) local sd = nmap.new_socket() -- check for connect_timeout or timeout option @@ -208,7 +198,7 @@ local function opencon(ip, port, protocol, data, opts) sd:set_timeout(8000) end - local status = sd:connect(ip, port, protocol) + local status = sd:connect(host, port, protocol) if not status then sd:close() return nil, nil, nil @@ -263,8 +253,6 @@ end -- of the first receive (before sending data) function tryssl(host, port, data, opts) local opt1, opt2 = bestoption(port) - if type(port) == 'table' then port = port.number end - if type(host) == 'table' then host = host.ip end local best = opt1 local sd, response, early_resp = opencon(host, port, opt1, data, opts) if not sd then diff --git a/nselib/http.lua b/nselib/http.lua index 1d79cc9f4..5cb0528d1 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -978,10 +978,6 @@ request = function(host, port, data, options) options = options or {} - if type(host) == 'table' then - host = host.ip - end - if type(port) == 'table' then if port.protocol and port.protocol ~= 'tcp' then stdnse.print_debug(1, "http.request() supports the TCP protocol only, your request to %s cannot be completed.", host) @@ -1253,7 +1249,7 @@ pipeline = function(host, port, allReqs) -- Connect to host and send all the requests at once! if count >= limit or not socket:get_info() then - socket:connect(host.ip, port.number, bopt) + socket:connect(host, port, bopt) partial = "" count = 0 end