aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2005-05-06 04:45:38 +0000
committerMike Frysinger <vapier@gentoo.org>2005-05-06 04:45:38 +0000
commit60a5c38a4b7e223dda52baf943b8edac7eeccb59 (patch)
treedbb31dab0efc295d0c4839f8f7e7d51aa6684908 /networking
parent4f65360a5f36e1841b13dc50108c290010347e7f (diff)
downloadbusybox-w32-60a5c38a4b7e223dda52baf943b8edac7eeccb59.tar.gz
busybox-w32-60a5c38a4b7e223dda52baf943b8edac7eeccb59.tar.bz2
busybox-w32-60a5c38a4b7e223dda52baf943b8edac7eeccb59.zip
In bug 247, haveaniceday writes:
The option "-w secs" adds a timeout for writing.
Diffstat (limited to 'networking')
-rw-r--r--networking/nc.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/networking/nc.c b/networking/nc.c
index 3099763b1..bbcbc0d13 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -30,6 +30,7 @@
30#include <stdlib.h> 30#include <stdlib.h>
31#include <string.h> 31#include <string.h>
32#include <unistd.h> 32#include <unistd.h>
33#include <signal.h>
33 34
34#include <sys/types.h> 35#include <sys/types.h>
35#include <sys/socket.h> 36#include <sys/socket.h>
@@ -42,9 +43,14 @@
42 43
43#define GAPING_SECURITY_HOLE 44#define GAPING_SECURITY_HOLE
44 45
46static void timeout(int signum)
47{
48 bb_error_msg_and_die("Timed out");
49}
50
45int nc_main(int argc, char **argv) 51int nc_main(int argc, char **argv)
46{ 52{
47 int do_listen = 0, lport = 0, delay = 0, tmpfd, opt, sfd, x; 53 int do_listen = 0, lport = 0, delay = 0, wsecs = 0, tmpfd, opt, sfd, x;
48 char buf[BUFSIZ]; 54 char buf[BUFSIZ];
49#ifdef GAPING_SECURITY_HOLE 55#ifdef GAPING_SECURITY_HOLE
50 char * pr00gie = NULL; 56 char * pr00gie = NULL;
@@ -55,7 +61,7 @@ int nc_main(int argc, char **argv)
55 61
56 fd_set readfds, testfds; 62 fd_set readfds, testfds;
57 63
58 while ((opt = getopt(argc, argv, "lp:i:e:")) > 0) { 64 while ((opt = getopt(argc, argv, "lp:i:e:w:")) > 0) {
59 switch (opt) { 65 switch (opt) {
60 case 'l': 66 case 'l':
61 do_listen++; 67 do_listen++;
@@ -71,6 +77,9 @@ int nc_main(int argc, char **argv)
71 pr00gie = optarg; 77 pr00gie = optarg;
72 break; 78 break;
73#endif 79#endif
80 case 'w':
81 wsecs = atoi(optarg);
82 break;
74 default: 83 default:
75 bb_show_usage(); 84 bb_show_usage();
76 } 85 }
@@ -94,6 +103,11 @@ int nc_main(int argc, char **argv)
94 bb_perror_msg_and_die ("reuseaddr failed"); 103 bb_perror_msg_and_die ("reuseaddr failed");
95 address.sin_family = AF_INET; 104 address.sin_family = AF_INET;
96 105
106 if (wsecs) {
107 signal(SIGALRM, timeout);
108 alarm(wsecs);
109 }
110
97 if (lport != 0) { 111 if (lport != 0) {
98 memset(&address.sin_addr, 0, sizeof(address.sin_addr)); 112 memset(&address.sin_addr, 0, sizeof(address.sin_addr));
99 address.sin_port = lport; 113 address.sin_port = lport;
@@ -123,6 +137,11 @@ int nc_main(int argc, char **argv)
123 bb_perror_msg_and_die("connect"); 137 bb_perror_msg_and_die("connect");
124 } 138 }
125 139
140 if (wsecs) {
141 alarm(0);
142 signal(SIGALRM, SIG_DFL);
143 }
144
126#ifdef GAPING_SECURITY_HOLE 145#ifdef GAPING_SECURITY_HOLE
127 /* -e given? */ 146 /* -e given? */
128 if (pr00gie) { 147 if (pr00gie) {