mirror of
https://github.com/nmap/nmap.git
synced 2025-12-24 16:39:03 +00:00
When nmap.connect gets a port table, let port.protocol be the default
protocol (instead of always "tcp"). You can still override it by providing an explicit protocol after the table.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
-- <code>"tcp"</code>, <code>"udp"</code> or <code>"ssl"</code>;
|
||||
-- <code>"tcp"</code> is the default.
|
||||
-- protocol must be one of <code>"tcp"</code>, <code>"udp"</code> or
|
||||
-- <code>"ssl"</code>. The default value for the protocol is
|
||||
-- <code>port.protocol</code> if <code>port</code> is a port table, otherwise
|
||||
-- <code>"tcp"</code>.
|
||||
--
|
||||
-- If <code>host</code> is a host table, it must contain at least one of the
|
||||
-- keys <code>addr</code> or <code>targetname</code>. If <code>targetname</code>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user