Index: nse_nmaplib.cc =================================================================== --- nse_nmaplib.cc (revision 16844) +++ nse_nmaplib.cc (working copy) @@ -448,6 +448,40 @@ return p; } +static int aux_get_ports (lua_State *L) +{ + Target *target = (Target *) lua_touserdata(L, lua_upvalueindex(1)); + Port temp, *port = (Port *) lua_touserdata(L, lua_upvalueindex(2)); + int p = lua_tointeger(L, lua_upvalueindex(3)), + s = lua_tointeger(L, lua_upvalueindex(4)); + if (target->ports.nextPort(port, &temp, p, s) == NULL) + lua_pushnil(L); + else + { + *port = temp; /* copy */ + lua_newtable(L); + set_portinfo(L, target, port); + } + return 1; +} + +static int l_get_ports (lua_State *L) +{ + static const char *op1[] = {"tcp", "udp", "sctp", "all", NULL}; + static const int states1[] = {IPPROTO_TCP, IPPROTO_UDP, IPPROTO_SCTP, + TCPANDUDPANDSCTP}; + static const char *op2[] = {"open", "filtered", "unfiltered", "closed", + "open|filtered", "closed|filtered", NULL}; + static const int states2[] = {PORT_OPEN, PORT_FILTERED, PORT_UNFILTERED, + PORT_CLOSED, PORT_OPENFILTERED, PORT_CLOSEDFILTERED}; + lua_pushlightuserdata(L, get_target(L, 1)); + lua_newuserdata(L, sizeof(Port)); /* First Port == NULL */ + lua_pushinteger(L, states1[luaL_checkoption(L, 2, NULL, op1)]); + lua_pushinteger(L, states2[luaL_checkoption(L, 3, NULL, op2)]); + lua_pushcclosure(L, aux_get_ports, 4); + return 1; +} + /* this function can be called from lua to obtain the port state * of a port different from the one the script rule is matched * against @@ -661,6 +695,7 @@ int luaopen_nmap (lua_State *L) { static const luaL_reg nmaplib [] = { + {"get_ports", l_get_ports}, {"get_port_state", l_get_port_state}, {"set_port_state", l_set_port_state}, {"set_port_version", l_set_port_version},