mirror of
https://github.com/nmap/nmap.git
synced 2026-01-04 21:59:02 +00:00
Add the stdnse.sleep function.
This commit is contained in:
@@ -252,6 +252,7 @@ int init_lua (lua_State *L)
|
||||
#ifdef HAVE_OPENSSL
|
||||
{OPENSSLLIBNAME, luaopen_openssl}, // openssl bindings
|
||||
#endif
|
||||
{"stdnse.c", luaopen_stdnse_c},
|
||||
};
|
||||
|
||||
luaL_openlibs(L); // opens all standard libraries
|
||||
|
||||
@@ -562,3 +562,17 @@ int luaopen_nmap (lua_State *L)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Register C functions that belong in the stdnse namespace. They are loaded
|
||||
from here in stdnse.lua. */
|
||||
int luaopen_stdnse_c (lua_State *L)
|
||||
{
|
||||
static const luaL_reg stdnse_clib [] = {
|
||||
{"sleep", l_nsock_sleep},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
luaL_register(L, "stdnse.c", stdnse_clib);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class Target;
|
||||
class Port;
|
||||
|
||||
int luaopen_nmap(lua_State* l);
|
||||
int luaopen_stdnse_c (lua_State *L);
|
||||
void set_hostinfo(lua_State* l, Target* currenths);
|
||||
void set_portinfo(lua_State* l, Port* port);
|
||||
|
||||
|
||||
19
nse_nsock.cc
19
nse_nsock.cc
@@ -950,6 +950,25 @@ void l_nsock_clear_buf(lua_State *L, l_nsock_udata* udata){
|
||||
udata->bufused=0;
|
||||
}
|
||||
|
||||
static void l_nsock_sleep_handler(nsock_pool nsp, nsock_event nse, void *udata) {
|
||||
lua_State *L = (lua_State*) udata;
|
||||
assert(nse_status(nse) == NSE_STATUS_SUCCESS);
|
||||
process_waiting2running(L, 0);
|
||||
}
|
||||
|
||||
int l_nsock_sleep(lua_State *L) {
|
||||
double secs = luaL_checknumber(L, 1);
|
||||
int msecs;
|
||||
|
||||
if (secs < 0)
|
||||
luaL_error(L, "Argument to sleep (%f) must not be negative\n", secs);
|
||||
/* Convert to milliseconds for nsock_timer_create. */
|
||||
msecs = (int) (secs * 1000 + 0.5);
|
||||
nsock_timer_create(nsp, l_nsock_sleep_handler, msecs, L);
|
||||
|
||||
return lua_yield(L, 0);
|
||||
}
|
||||
|
||||
/****************** NCAP_SOCKET ***********************************************/
|
||||
#ifdef WIN32
|
||||
/* From tcpip.cc. Gets pcap device name from dnet name. */
|
||||
|
||||
@@ -10,6 +10,7 @@ extern "C" {
|
||||
int luaopen_nsock(lua_State *);
|
||||
int l_nsock_new(lua_State *);
|
||||
int l_nsock_loop(int tout);
|
||||
int l_nsock_sleep(lua_State *L);
|
||||
|
||||
int l_dnet_new(lua_State *);
|
||||
int l_dnet_open(lua_State *);
|
||||
|
||||
@@ -17,10 +17,31 @@ local concat = table.concat;
|
||||
|
||||
local nmap = require "nmap";
|
||||
|
||||
local c_funcs = require "stdnse.c";
|
||||
|
||||
local EMPTY = {}; -- Empty constant table
|
||||
|
||||
module(... or "stdnse");
|
||||
|
||||
-- Load C functions from stdnse.c into this namespace.
|
||||
for k, v in pairs(c_funcs) do
|
||||
_M[k] = v
|
||||
end
|
||||
-- Remove visibility of the stdnse.c table.
|
||||
c = nil
|
||||
|
||||
--- Sleeps for a given amount of time.
|
||||
--
|
||||
-- This causes the program to yield control and not regain it until the time
|
||||
-- period has elapsed. The time may have a fractional part. Internally, the
|
||||
-- timer provides millisecond resolution.
|
||||
-- @name sleep
|
||||
-- @class function
|
||||
-- @param t Time to sleep, in seconds.
|
||||
-- @usage stdnse.sleep(1.5)
|
||||
|
||||
-- sleep is a C function defined in nse_nmaplib.cc.
|
||||
|
||||
--- Prints a formatted debug message if the current verbosity level is greater
|
||||
-- than or equal to a given level.
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user