source:
npl/overig/netcat_openbsd/patches/0006-quit-timer.patch
@
e013060
Last change on this file since e013060 was c5c522c, checked in by , 8 years ago | |
---|---|
|
|
File size: 3.8 KB |
-
nc.1
From: Aron Xu <aron@debian.org> Date: Mon, 13 Feb 2012 15:16:04 +0800 Subject: quit timer --- nc.1 | 5 +++++ netcat.c | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/nc.1 b/nc.1 index af44976..0d92b74 100644
a b 40 40 .Op Fl O Ar length 41 41 .Op Fl P Ar proxy_username 42 42 .Op Fl p Ar source_port 43 .Op Fl q Ar seconds 43 44 .Op Fl s Ar source 44 45 .Op Fl T Ar toskeyword 45 46 .Op Fl V Ar rtable … … Proxy authentication is only supported for HTTP CONNECT proxies at present. 148 149 Specifies the source port 149 150 .Nm 150 151 should use, subject to privilege restrictions and availability. 152 .It Fl q Ar seconds 153 after EOF on stdin, wait the specified number of seconds and then quit. If 154 .Ar seconds 155 is negative, wait forever. 151 156 .It Fl r 152 157 Specifies that source and/or destination ports should be chosen randomly 153 158 instead of sequentially within a range or in the order that the system -
netcat.c
diff --git a/netcat.c b/netcat.c index 4f4d2bf..29ecf1a 100644
a b 86 86 #include <errno.h> 87 87 #include <netdb.h> 88 88 #include <poll.h> 89 #include <signal.h> 89 90 #include <stdarg.h> 90 91 #include <stdio.h> 91 92 #include <stdlib.h> … … int lflag; /* Bind to local port */ 120 121 int nflag; /* Don't do name look up */ 121 122 char *Pflag; /* Proxy username */ 122 123 char *pflag; /* Localport flag */ 124 int qflag = 0; /* Quit after some secs */ 123 125 int rflag; /* Random ports flag */ 124 126 char *sflag; /* Source Address */ 125 127 int tflag; /* Telnet Emulation */ … … void usage(int); 158 160 159 161 static int connect_with_timeout(int fd, const struct sockaddr *sa, 160 162 socklen_t salen, int ctimeout); 163 static void quit(); 161 164 162 165 int 163 166 main(int argc, char *argv[]) … … main(int argc, char *argv[]) 181 184 sv = NULL; 182 185 183 186 while ((ch = getopt(argc, argv, 184 "46CDdhI:i:jklnO:P:p: rSs:tT:UuV:vw:X:x:z")) != -1) {187 "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:z")) != -1) { 185 188 switch (ch) { 186 189 case '4': 187 190 family = AF_INET; … … main(int argc, char *argv[]) 235 238 case 'p': 236 239 pflag = optarg; 237 240 break; 241 case 'q': 242 qflag = strtonum(optarg, INT_MIN, INT_MAX, &errstr); 243 if (errstr) 244 errx(1, "quit timer %s: %s", errstr, optarg); 245 break; 238 246 case 'r': 239 247 rflag = 1; 240 248 break; … … readwrite(int nfd) 924 932 } 925 933 else if (pfd[1].revents & POLLHUP) { 926 934 shutdown_wr: 935 /* if the user asked to exit on EOF, do it */ 936 if (qflag == 0) { 927 937 shutdown(nfd, SHUT_WR); 928 pfd[1].fd = -1; 929 pfd[1].events = 0; 938 close(wfd); 939 } 940 /* if user asked to die after a while, arrange for it */ 941 if (qflag > 0) { 942 signal(SIGALRM, quit); 943 alarm(qflag); 944 } 945 pfd[1].fd = -1; 946 pfd[1].events = 0; 930 947 } 931 948 } 932 949 } … … help(void) 1164 1181 \t-O length TCP send buffer length\n\ 1165 1182 \t-P proxyuser\tUsername for proxy authentication\n\ 1166 1183 \t-p port\t Specify local port for remote connects\n\ 1184 \t-q secs\t quit after EOF on stdin and delay of secs\n\ 1167 1185 \t-r Randomize remote ports\n\ 1168 1186 \t-S Enable the TCP MD5 signature option\n\ 1169 1187 \t-s addr\t Local source address\n\ … … usage(int ret) 1186 1204 { 1187 1205 fprintf(stderr, 1188 1206 "usage: nc [-46CDdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n" 1189 "\t [-P proxy_username] [-p source_port] [- s source] [-T toskeyword]\n"1190 "\t [- V rtable] [-w timeout] [-X proxy_protocol]\n"1207 "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n" 1208 "\t [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]\n" 1191 1209 "\t [-x proxy_address[:port]] [destination] [port]\n"); 1192 1210 if (ret) 1193 1211 exit(1); 1194 1212 } 1213 1214 /* 1215 * quit() 1216 * handler for a "-q" timeout (exit 0 instead of 1) 1217 */ 1218 static void quit() 1219 { 1220 /* XXX: should explicitly close fds here */ 1221 exit(0); 1222 }
Note: See TracBrowser
for help on using the repository browser.