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-60a5c38a4b7e223dda52baf943b8edac7eeccb59.tar.gz
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 @@
#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 @@ int nc_main(int argc, char **argv)
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 @@ int nc_main(int argc, char **argv)
pr00gie = optarg;
break;
#endif
+ case 'w':
+ wsecs = atoi(optarg);
+ break;
default:
bb_show_usage();
}
@@ -94,6 +103,11 @@ int nc_main(int argc, char **argv)
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 @@ int nc_main(int argc, char **argv)
bb_perror_msg_and_die("connect");
}
+ if (wsecs) {
+ alarm(0);
+ signal(SIGALRM, SIG_DFL);
+ }
+
#ifdef GAPING_SECURITY_HOLE
/* -e given? */
if (pr00gie) {