diff --git a/nse_nsock.cc b/nse_nsock.cc index 7c569128a..d9fda385e 100644 --- a/nse_nsock.cc +++ b/nse_nsock.cc @@ -652,6 +652,7 @@ static int l_nsock_connect(lua_State * L) { enum type {TCP, UDP, SSL}; static const char * const op[] = {"tcp", "udp", "ssl", NULL}; + const char *default_proto = "tcp"; l_nsock_udata *udata = (l_nsock_udata *) luaL_checkudata(L, 1, "nsock"); const char *addr, *targetname; @@ -696,12 +697,18 @@ static int l_nsock_connect(lua_State * L) luaL_error(L, "port.number is not numeric"); port = lua_tointeger(L, -1); lua_pop(L, 1); + + lua_getfield(L, 3, "protocol"); + /* Make this the default if the "proto" argument isn't given. */ + if (lua_isstring(L, -1)) + default_proto = lua_tostring(L, -1); + lua_pop(L, 1); } else { port = (unsigned short) luaL_checkint(L, 3); } /* proto argument. */ - what = luaL_checkoption(L, 4, "tcp", op); + what = luaL_checkoption(L, 4, default_proto, op); const char *error; struct addrinfo *dest; diff --git a/nselib/nmap.luadoc b/nselib/nmap.luadoc index 0cd94c01a..f02605de1 100644 --- a/nselib/nmap.luadoc +++ b/nselib/nmap.luadoc @@ -281,7 +281,7 @@ function condvar(object) -- socket:close() -- end -- try = nmap.new_try(catch) --- try(socket:connect(host.ip, port.number)) +-- try(socket:connect(host, port)) -- result = try(socket:receive_lines(1)) -- try(socket:send(result)) function new_try(handler) @@ -329,9 +329,10 @@ function bind(addr, port) -- This method puts a socket in a state ready for communication. It takes as -- arguments a host descriptor (a host table, IP address, or hostname), a port -- descriptor (a port table or number), and optionally a protocol. If given, the --- protocol must be one of --- "tcp", "udp" or "ssl"; --- "tcp" is the default. +-- protocol must be one of "tcp", "udp" or +-- "ssl". The default value for the protocol is +-- port.protocol if port is a port table, otherwise +-- "tcp". -- -- If host is a host table, it must contain at least one of the -- keys addr or targetname. If targetname @@ -367,7 +368,7 @@ function bind(addr, port) -- @return Error code (if status is false). -- @see new_socket -- @usage --- local status, err = socket:connect(host.ip, port, "udp") +-- local status, err = socket:connect(host, port) -- if not status then -- return string.format("Can't connect: %s", err) -- end