aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-05-06 04:45:38 +0000
committervapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-05-06 04:45:38 +0000
commit47353430391435241f22ccbb15a9dbe4d48ea186 (patch)
treedbb31dab0efc295d0c4839f8f7e7d51aa6684908
parente6d6f9ae25e0fae2cdefbd3e1e7903b69cdced08 (diff)
downloadbusybox-w32-47353430391435241f22ccbb15a9dbe4d48ea186.tar.gz
busybox-w32-47353430391435241f22ccbb15a9dbe4d48ea186.tar.bz2
busybox-w32-47353430391435241f22ccbb15a9dbe4d48ea186.zip
In bug 247, haveaniceday writes:
The option "-w secs" adds a timeout for writing. git-svn-id: svn://busybox.net/trunk/busybox@10253 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--include/usage.h1
-rw-r--r--networking/nc.c23
2 files changed, 22 insertions, 2 deletions
diff --git a/include/usage.h b/include/usage.h
index b57644bc1..d731957f1 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1832,6 +1832,7 @@
1832 "\t-l\t\tlisten mode, for inbound connects\n" \ 1832 "\t-l\t\tlisten mode, for inbound connects\n" \
1833 "\t-p PORT\t\tlocal port number\n" \ 1833 "\t-p PORT\t\tlocal port number\n" \
1834 "\t-i SECS\t\tdelay interval for lines sent\n" \ 1834 "\t-i SECS\t\tdelay interval for lines sent\n" \
1835 "\t-w SECS\t\ttimeout for connects and final net reads\n" \
1835 "\t-e PROG\t\tprogram to exec after connect (dangerous!)" 1836 "\t-e PROG\t\tprogram to exec after connect (dangerous!)"
1836#define nc_example_usage \ 1837#define nc_example_usage \
1837 "$ nc foobar.somedomain.com 25\n" \ 1838 "$ nc foobar.somedomain.com 25\n" \
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) {