[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [BusyBox] [PATCH] nc -w
From:       Jonas Holmberg <jonas.holmberg () axis ! com>
Date:       2004-10-25 19:24:40
Message-ID: 20041025192439.GA11616 () axis ! com
[Download RAW message or body]

On Mon, Oct 25, 2004 at 10:10:26AM -0400, Paul Fox wrote:
>  > +			case 'w':
>  > +				wsecs = atoi(optarg);
>  > +				break;
>  >  			default:
>  >  				bb_show_usage();
>  >  		}
>  > @@ -94,6 +103,9 @@
>  >  		bb_perror_msg_and_die ("reuseaddr failed");
>  >  	address.sin_family = AF_INET;
>  >  
>  > +	signal(SIGALRM, timeout);
>  > +	alarm(wsecs);
> 
> shouldn't this be conditioned on "if (wsecs)"?
> 
>  > +
>  >  	if (lport != 0) {
>  >  		memset(&address.sin_addr, 0, sizeof(address.sin_addr));
>  >  		address.sin_port = lport;
>  > @@ -123,6 +135,9 @@
>  >  			bb_perror_msg_and_die("connect");
>  >  	}
>  >  
>  > +	alarm(0);
>  > +	signal(SIGALRM, SIG_DFL);
>  > +
> 
> this too, of course.

Yes, of course, that's better. New patch attached.

/Jonas

["nc.diff" (text/plain)]

diff --exclude CVS -Nur busybox-1.00/include/usage.h busybox/include/usage.h
--- busybox-1.00/include/usage.h	2004-10-15 11:19:25.000000000 +0200
+++ busybox/include/usage.h	2004-10-25 13:07:37.646861679 +0200
@@ -1787,7 +1787,8 @@
 	"\t-l\t\tlisten mode, for inbound connects\n" \
 	"\t-p PORT\t\tlocal port number\n" \
 	"\t-i SECS\t\tdelay interval for lines sent\n" \
-	"\t-e PROG\t\tprogram to exec after connect (dangerous!)"
+	"\t-e PROG\t\tprogram to exec after connect (dangerous!)\n" \
+	"\t-w SECS\t\ttimeout for connects"
 #define nc_example_usage \
 	"$ nc foobar.somedomain.com 25\n" \
 	"220 foobar ESMTP Exim 3.12 #1 Sat, 15 Apr 2000 00:03:02 -0600\n" \
diff --exclude CVS -Nur busybox-1.00/networking/nc.c busybox/networking/nc.c
--- busybox-1.00/networking/nc.c	2004-05-28 13:38:17.000000000 +0200
+++ busybox/networking/nc.c	2004-10-25 21:10:14.876683296 +0200
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <signal.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -42,9 +43,14 @@
 
 #define GAPING_SECURITY_HOLE
 
+static void timeout(int signum)
+{
+	bb_error_msg_and_die("Timed out");
+}
+
 int nc_main(int argc, char **argv)
 {
-	int do_listen = 0, lport = 0, delay = 0, tmpfd, opt, sfd, x;
+	int do_listen = 0, lport = 0, delay = 0, wsecs = 0, tmpfd, opt, sfd, x;
 	char buf[BUFSIZ];
 #ifdef GAPING_SECURITY_HOLE
 	char * pr00gie = NULL;
@@ -55,7 +61,7 @@
 
 	fd_set readfds, testfds;
 
-	while ((opt = getopt(argc, argv, "lp:i:e:")) > 0) {
+	while ((opt = getopt(argc, argv, "lp:i:e:w:")) > 0) {
 		switch (opt) {
 			case 'l':
 				do_listen++;
@@ -71,6 +77,9 @@
 				pr00gie = optarg;
 				break;
 #endif
+			case 'w':
+				wsecs = atoi(optarg);
+				break;
 			default:
 				bb_show_usage();
 		}
@@ -94,6 +103,11 @@
 		bb_perror_msg_and_die ("reuseaddr failed");
 	address.sin_family = AF_INET;
 
+	if (wsecs) {
+		signal(SIGALRM, timeout);
+		alarm(wsecs);
+	}
+
 	if (lport != 0) {
 		memset(&address.sin_addr, 0, sizeof(address.sin_addr));
 		address.sin_port = lport;
@@ -123,6 +137,11 @@
 			bb_perror_msg_and_die("connect");
 	}
 
+	if (wsecs) {
+		alarm(0);
+		signal(SIGALRM, SIG_DFL);
+	}
+
 #ifdef GAPING_SECURITY_HOLE
 	/* -e given? */
 	if (pr00gie) {


_______________________________________________
busybox mailing list
busybox@mail.busybox.net
http://codepoet.org/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic