In bug 247, haveaniceday writes:

The option "-w secs" adds a timeout for writing.
This commit is contained in:
Mike Frysinger 2005-05-06 04:45:38 +00:00
parent 4f65360a5f
commit 60a5c38a4b
2 changed files with 22 additions and 2 deletions

View File

@ -1832,6 +1832,7 @@
"\t-l\t\tlisten mode, for inbound connects\n" \ "\t-l\t\tlisten mode, for inbound connects\n" \
"\t-p PORT\t\tlocal port number\n" \ "\t-p PORT\t\tlocal port number\n" \
"\t-i SECS\t\tdelay interval for lines sent\n" \ "\t-i SECS\t\tdelay interval for lines sent\n" \
"\t-w SECS\t\ttimeout for connects and final net reads\n" \
"\t-e PROG\t\tprogram to exec after connect (dangerous!)" "\t-e PROG\t\tprogram to exec after connect (dangerous!)"
#define nc_example_usage \ #define nc_example_usage \
"$ nc foobar.somedomain.com 25\n" \ "$ nc foobar.somedomain.com 25\n" \

View File

@ -30,6 +30,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -42,9 +43,14 @@
#define GAPING_SECURITY_HOLE #define GAPING_SECURITY_HOLE
static void timeout(int signum)
{
bb_error_msg_and_die("Timed out");
}
int nc_main(int argc, char **argv) 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]; char buf[BUFSIZ];
#ifdef GAPING_SECURITY_HOLE #ifdef GAPING_SECURITY_HOLE
char * pr00gie = NULL; char * pr00gie = NULL;
@ -55,7 +61,7 @@ int nc_main(int argc, char **argv)
fd_set readfds, testfds; 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) { switch (opt) {
case 'l': case 'l':
do_listen++; do_listen++;
@ -71,6 +77,9 @@ int nc_main(int argc, char **argv)
pr00gie = optarg; pr00gie = optarg;
break; break;
#endif #endif
case 'w':
wsecs = atoi(optarg);
break;
default: default:
bb_show_usage(); bb_show_usage();
} }
@ -94,6 +103,11 @@ int nc_main(int argc, char **argv)
bb_perror_msg_and_die ("reuseaddr failed"); bb_perror_msg_and_die ("reuseaddr failed");
address.sin_family = AF_INET; address.sin_family = AF_INET;
if (wsecs) {
signal(SIGALRM, timeout);
alarm(wsecs);
}
if (lport != 0) { if (lport != 0) {
memset(&address.sin_addr, 0, sizeof(address.sin_addr)); memset(&address.sin_addr, 0, sizeof(address.sin_addr));
address.sin_port = lport; address.sin_port = lport;
@ -123,6 +137,11 @@ int nc_main(int argc, char **argv)
bb_perror_msg_and_die("connect"); bb_perror_msg_and_die("connect");
} }
if (wsecs) {
alarm(0);
signal(SIGALRM, SIG_DFL);
}
#ifdef GAPING_SECURITY_HOLE #ifdef GAPING_SECURITY_HOLE
/* -e given? */ /* -e given? */
if (pr00gie) { if (pr00gie) {