diff --git a/nse_nsock.cc b/nse_nsock.cc index 2841033da..f04fa5147 100644 --- a/nse_nsock.cc +++ b/nse_nsock.cc @@ -50,6 +50,7 @@ typedef struct nse_nsock_udata { nsock_iod nsiod; int timeout; + bool eof; lua_State *thread; @@ -656,11 +657,19 @@ static int l_sendto (lua_State *L) } +static int l_eof (lua_State *L) +{ + nse_nsock_udata *nu = check_nsock_udata(L, 1, false); + lua_pushboolean(L, nu->eof); + return 1; +} + static void receive_callback (nsock_pool nsp, nsock_event nse, void *udata) { nse_nsock_udata *nu = (nse_nsock_udata *) udata; lua_State *L = nu->thread; assert(nse_type(nse) == NSE_TYPE_READ); + nu->eof = nse_eof(nse); if (nse_status(nse) == NSE_STATUS_SUCCESS) { int len; @@ -1179,6 +1188,7 @@ LUALIB_API int luaopen_nsock (lua_State *L) {"receive_lines", l_receive_lines}, {"reconnect_ssl", l_reconnect_ssl}, {"set_timeout", l_set_timeout}, + {"eof", l_eof}, {NULL, NULL} }; diff --git a/nselib/nmap.luadoc b/nselib/nmap.luadoc index 92becafac..e284c9c59 100644 --- a/nselib/nmap.luadoc +++ b/nselib/nmap.luadoc @@ -657,6 +657,14 @@ function receive_buf(delimiter, keeppattern) -- @usage socket:close() function close() +--- Check whether the socket has seen EOF +-- +-- @return Status (true or false). +-- @return Error code (if status is false). +-- @see new_socket +-- @usage socket:eof() +function eof() + --- Gets information about a socket. -- -- This function returns information about a socket object. It returns five