1 From: Aron Xu <aron@debian.org>
2 Date: Mon, 13 Feb 2012 15:16:04 +0800
3 Subject: [PATCH] quit timer
7 netcat.c | 39 ++++++++++++++++++++++++++++++++++-----
8 2 files changed, 39 insertions(+), 5 deletions(-)
14 .Op Fl P Ar proxy_username
15 .Op Fl p Ar source_port
18 .Op Fl T Ar toskeyword
21 Specifies the source port
23 should use, subject to privilege restrictions and availability.
25 +after EOF on stdin, wait the specified number of seconds and then quit. If
27 +is negative, wait forever.
29 Specifies that source and/or destination ports should be chosen randomly
30 instead of sequentially within a range or in the order that the system
42 int nflag; /* Don't do name look up */
43 char *Pflag; /* Proxy username */
44 char *pflag; /* Localport flag */
45 +int qflag = 0; /* Quit after some secs */
46 int rflag; /* Random ports flag */
47 char *sflag; /* Source Address */
48 int tflag; /* Telnet Emulation */
51 static int connect_with_timeout(int fd, const struct sockaddr *sa,
52 socklen_t salen, int ctimeout);
56 main(int argc, char *argv[])
60 while ((ch = getopt(argc, argv,
61 - "46CDdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) {
62 + "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:z")) != -1) {
71 + qflag = strtonum(optarg, (long long)INT_MIN, (long long)INT_MAX, &errstr);
73 + errx(1, "quit timer %s: %s", errstr, optarg);
80 else if (pfd[1].revents & POLLHUP) {
82 + /* if the user asked to exit on EOF, do it */
84 shutdown(nfd, SHUT_WR);
89 + /* if user asked to die after a while, arrange for it */
91 + signal(SIGALRM, quit);
100 \t-O length TCP send buffer length\n\
101 \t-P proxyuser\tUsername for proxy authentication\n\
102 \t-p port\t Specify local port for remote connects\n\
103 + \t-q secs\t quit after EOF on stdin and delay of secs\n\
104 \t-r Randomize remote ports\n\
105 \t-S Enable the TCP MD5 signature option\n\
106 \t-s addr\t Local source address\n\
107 @@ -1186,9 +1204,19 @@
110 "usage: nc [-46CDdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n"
111 - "\t [-P proxy_username] [-p source_port] [-s source] [-T toskeyword]\n"
112 - "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
113 + "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n"
114 + "\t [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]\n"
115 "\t [-x proxy_address[:port]] [destination] [port]\n");
122 + * handler for a "-q" timeout (exit 0 instead of 1)
126 + /* XXX: should explicitly close fds here */