From cb50c3c74b87cd5fd85ec5de66646f84e3d62c3d Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 4 Apr 2017 16:26:08 +0000 Subject: [PATCH] Make ncat -i not timeout while waiting for initial connection --- CHANGELOG | 4 ++++ ncat/ncat_listen.c | 10 ++++++++-- ncat/ncat_proxy.c | 10 +--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index edfdf3c73..c9e699258 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ # Nmap Changelog ($Id$); -*-text-*- +o [Ncat] Made -i/--idle-timeout not cause Ncat in server mode to close while + waiting for an initial connection. This was also causing -i to interfere with + the HTTP proxy server mode. [Carlos Manso, Daniel Miller] + o [NSE][GH#766] The HTTP Host header will now include the port unless it is the default one for a given scheme. [nnposter] diff --git a/ncat/ncat_listen.c b/ncat/ncat_listen.c index e41369df9..3ce60dc0a 100644 --- a/ncat/ncat_listen.c +++ b/ncat/ncat_listen.c @@ -344,7 +344,10 @@ static int ncat_listen_stream(int proto) if (o.idletimeout > 0) ms_to_timeval(tvp, o.idletimeout); - fds_ready = fselect(client_fdlist.fdmax + 1, &readfds, &writefds, NULL, tvp); + if (get_conn_count()) + fds_ready = fselect(client_fdlist.fdmax + 1, &readfds, &writefds, NULL, tvp); + else + fds_ready = fselect(client_fdlist.fdmax + 1, &readfds, &writefds, NULL, NULL); if (o.debug > 1) logdebug("select returned %d fds ready\n", fds_ready); @@ -806,7 +809,10 @@ static int ncat_listen_dgram(int proto) if (o.idletimeout > 0) ms_to_timeval(tvp, o.idletimeout); - fds_ready = fselect(listen_fdlist.fdmax + 1, &fds, NULL, NULL, tvp); + if (get_conn_count()) + fds_ready = fselect(listen_fdlist.fdmax + 1, &fds, NULL, NULL, tvp); + else + fds_ready = fselect(listen_fdlist.fdmax + 1, &fds, NULL, NULL, NULL); if (o.debug > 1) logdebug("select returned %d fds ready\n", fds_ready); diff --git a/ncat/ncat_proxy.c b/ncat/ncat_proxy.c index 433c7fe59..e89599fe8 100644 --- a/ncat/ncat_proxy.c +++ b/ncat/ncat_proxy.c @@ -196,8 +196,6 @@ int ncat_http_server(void) int listen_socket[NUM_LISTEN_ADDRS]; socklen_t sslen; union sockaddr_u conn; - struct timeval tv; - struct timeval *tvp = NULL; unsigned int num_sockets; #ifndef WIN32 @@ -248,9 +246,6 @@ int ncat_http_server(void) bye("Unable to open any listening sockets."); } - if (o.idletimeout > 0) - tvp = &tv; - for (;;) { fd_set read_fds; @@ -262,10 +257,7 @@ int ncat_http_server(void) logdebug("selecting, fdmax %d\n", listen_fdlist.fdmax); read_fds = listen_fds; - if (o.idletimeout > 0) - ms_to_timeval(tvp, o.idletimeout); - - int fds_ready = fselect(listen_fdlist.fdmax + 1, &read_fds, NULL, NULL, tvp); + int fds_ready = fselect(listen_fdlist.fdmax + 1, &read_fds, NULL, NULL, NULL); if (o.debug > 1) logdebug("select returned %d fds ready\n", fds_ready);