From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4db,1dabe28e508bc1a7,start X-Google-Attributes: gid10d4db,public From: doolitt@recycle.cebaf.gov (Larry Doolittle) Subject: Linux tcp_scan patch for Satan Date: 1995/04/17 Message-ID: <3mtsc6$m02@myntti.helsinki.fi>#1/1 X-Deja-AN: 101366031 sender: wirzeniu@cc.helsinki.fi followup-to: comp.os.linux.setup content-type: text/plain; charset=ISO-8859-1 organization: ? keywords: patch, Satan, networking, security mime-version: 1.0 newsgroups: comp.os.linux.announce Here are my patches to Wietse Venema's tcp_scan.c, as shipped in satan-1.0 and satan-1.1.1. Without this patch, tcp_scan on Linux 1.2.0 (and presumably all other rev's) will stall on the first port that gives ECONNREFUSED. With this patch, it looks like it works fine. Your Mileage May Vary. - Larry Doolittle ldoolitt@cebaf.gov --- tcp_scan.c.orig Mon Apr 10 08:35:49 1995 +++ tcp_scan.c Mon Apr 10 16:16:41 1995 @@ -3,6 +3,7 @@ * and detect telnet options * * Author: Wietse Venema. + * Linux modifications to use exceptfds in select() call: Larry Doolittle */ #include @@ -62,6 +63,7 @@ struct timeval now; /* banner_info last update time */ fd_set write_socket_mask; /* sockets with connect() in progress */ fd_set read_socket_mask; /* sockets with connect() finished */ +fd_set except_socket_mask; /* sockets with either of above */ int ports_busy; /* number of open sockets */ int ports_done; /* number of finished sockets */ int max_sock; /* max socket file descriptor */ @@ -159,6 +161,7 @@ FD_ZERO(&write_socket_mask); FD_ZERO(&read_socket_mask); + FD_ZERO(&except_socket_mask); ports_busy = 0; /* @@ -256,6 +259,7 @@ { fd_set read_mask; fd_set write_mask; + fd_set except_mask; static struct timeval waitsome = {1, 1,}; static struct timeval waitnot = {0, 0,}; int sock; @@ -266,15 +270,16 @@ /* * When a connect() completes, report the socket and get rid of it. */ - write_mask = write_socket_mask; - read_mask = read_socket_mask; - if (select(max_sock + 1, &read_mask, &write_mask, (fd_set *) 0, + write_mask = write_socket_mask; + read_mask = read_socket_mask; + except_mask = except_socket_mask; + if (select(max_sock + 1, &read_mask, &write_mask, &except_mask, wait ? (struct timeval *) 0 : &waitnot) < 0) error("select: %m"); if (FD_ISSET(icmp_sock, &read_mask)) receive_icmp(icmp_sock); for (sock = 0; ports_busy > 0 && sock <= max_sock; sock++) { - if (FD_ISSET(sock, &write_mask)) { + if (FD_ISSET(sock, &write_mask) || FD_ISSET(sock,&except_mask)) { if (read(sock, &ch, 1) < 0 && errno != EWOULDBLOCK && errno != EAGAIN) { report_and_drop_socket(sock, errno); } else { @@ -289,9 +294,10 @@ * banner_time seconds. Assume we have received all banner data when * a socket stops sending for BANNER_IDLE seconds. */ - write_mask = write_socket_mask; - read_mask = read_socket_mask; - if (select(max_sock + 1, &read_mask, &write_mask, (fd_set *) 0, + write_mask = write_socket_mask; + read_mask = read_socket_mask; + except_mask = except_socket_mask; + if (select(max_sock + 1, &read_mask, &write_mask, &except_mask, wait ? &waitsome : &waitnot) < 0) error("select: %m"); if (FD_ISSET(icmp_sock, &read_mask)) @@ -316,6 +322,12 @@ report_and_drop_socket(sock, 0); break; } + } else if (FD_ISSET(sock, &except_mask)) { + if (read(sock, &ch, 1) < 0 && errno != EWOULDBLOCK && errno != EAGAIN) { + report_and_drop_socket(sock, errno); + } else { + report_and_drop_socket(sock, 0); + } } else if (FD_ISSET(sock, &read_socket_mask)) { if (time_since_connect(sock) > banner_time || time_since_read(sock) > BANNER_IDLE) @@ -417,6 +429,7 @@ bp->flags = 0; } FD_SET(sock, &write_socket_mask); + FD_SET(sock, &except_socket_mask); if (sock > max_sock) max_sock = sock; ports_busy++; @@ -434,6 +447,7 @@ close(sock); FD_CLR(sock, &read_socket_mask); FD_CLR(sock, &write_socket_mask); + FD_CLR(sock, &except_socket_mask); ports_busy--; ports_done++; } -- Send submissions for comp.os.linux.announce to: linux-announce@news.ornl.gov PLEASE remember Keywords: and a short description of the software.