aboutsummaryrefslogtreecommitdiff
path: root/network/netcat-openbsd/patches/0006-quit-timer.patch
diff options
context:
space:
mode:
authorDonald Cooley <chytraeus@protonmail.com>2020-02-08 02:00:33 +0700
committerWilly Sudiarto Raharjo <willysr@slackbuilds.org>2020-02-08 02:00:33 +0700
commitd1958c4a94b3ae2f24faeb8aa828d2065b36ee13 (patch)
tree11ce09c8e8aa00f7122923cf830a8f807d0ac328 /network/netcat-openbsd/patches/0006-quit-timer.patch
parent960bca1643f56ff4393a9339847467a8f8a7c361 (diff)
network/netcat-openbsd: Updated for version 1.206.
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
Diffstat (limited to 'network/netcat-openbsd/patches/0006-quit-timer.patch')
-rw-r--r--network/netcat-openbsd/patches/0006-quit-timer.patch156
1 files changed, 83 insertions, 73 deletions
diff --git a/network/netcat-openbsd/patches/0006-quit-timer.patch b/network/netcat-openbsd/patches/0006-quit-timer.patch
index 40d6a2a3a5..4d64cc100a 100644
--- a/network/netcat-openbsd/patches/0006-quit-timer.patch
+++ b/network/netcat-openbsd/patches/0006-quit-timer.patch
@@ -3,120 +3,132 @@ 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(-)
+ nc.1 | 10 ++++++++++
+ netcat.c | 50 +++++++++++++++++++++++++++++++++++++++++---------
+ 2 files changed, 51 insertions(+), 9 deletions(-)
-diff --git a/nc.1 b/nc.1
-index af44976..0d92b74 100644
--- a/nc.1
+++ b/nc.1
-@@ -40,6 +40,7 @@
+@@ -41,6 +41,7 @@
.Op Fl O Ar length
.Op Fl P Ar proxy_username
.Op Fl p Ar source_port
+.Op Fl q Ar seconds
.Op Fl s Ar source
- .Op Fl T Ar toskeyword
+ .Op Fl T Ar keyword
.Op Fl V Ar rtable
-@@ -148,6 +149,10 @@ Proxy authentication is only supported for HTTP CONNECT proxies at present.
- Specifies the source port
+@@ -167,6 +168,15 @@ Proxy authentication is only supported f
+ Specify the source port
.Nm
should use, subject to privilege restrictions and availability.
+.It Fl q Ar seconds
-+after EOF on stdin, wait the specified number of seconds and then quit. If
++after EOF on stdin, wait the specified number of
+.Ar seconds
-+is negative, wait forever.
++and then quit. If
++.Ar seconds
++is negative, wait forever (default). Specifying a non-negative
++.Ar seconds
++implies
++.Fl N .
.It Fl r
- Specifies that source and/or destination ports should be chosen randomly
+ Choose source and/or destination ports randomly
instead of sequentially within a range or in the order that the system
-diff --git a/netcat.c b/netcat.c
-index 4f4d2bf..29ecf1a 100644
--- a/netcat.c
+++ b/netcat.c
-@@ -86,6 +86,7 @@
- #include <errno.h>
- #include <netdb.h>
- #include <poll.h>
-+#include <signal.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
-@@ -120,6 +121,7 @@ int lflag; /* Bind to local port */
+@@ -139,6 +139,7 @@ int Nflag; /* shutdown() network soc
int nflag; /* Don't do name look up */
char *Pflag; /* Proxy username */
char *pflag; /* Localport flag */
-+int qflag = 0; /* Quit after some secs */
++int qflag = -1; /* Quit after some secs */
int rflag; /* Random ports flag */
char *sflag; /* Source Address */
int tflag; /* Telnet Emulation */
-@@ -158,6 +160,7 @@ void usage(int);
-
+@@ -224,6 +225,8 @@ ssize_t fillbuf(int, unsigned char *, si
static int connect_with_timeout(int fd, const struct sockaddr *sa,
socklen_t salen, int ctimeout);
-+static void quit();
++static void quit();
++
int
main(int argc, char *argv[])
-@@ -181,7 +184,7 @@ main(int argc, char *argv[])
- sv = NULL;
+ {
+@@ -256,9 +259,9 @@ main(int argc, char *argv[])
while ((ch = getopt(argc, argv,
-- "46CDdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) {
-+ "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:z")) != -1) {
+ # if defined(TLS)
+- "46C:cDde:FH:hI:i:K:klM:m:NnO:o:P:p:R:rSs:T:tUuV:vW:w:X:x:Z:z"))
++ "46C:cDde:FH:hI:i:K:klM:m:NnO:o:P:p:q:R:rSs:T:tUuV:vW:w:X:x:Z:z"))
+ # else
+- "46CDdFhI:i:klM:m:NnO:P:p:rSs:T:tUuV:vW:w:X:x:z"))
++ "46CDdFhI:i:klM:m:NnO:P:p:q:rSs:T:tUuV:vW:w:X:x:z"))
+ # endif
+ != -1) {
switch (ch) {
- case '4':
- family = AF_INET;
-@@ -235,6 +238,11 @@ main(int argc, char *argv[])
+@@ -350,6 +353,13 @@ main(int argc, char *argv[])
case 'p':
pflag = optarg;
break;
-+ case 'q':
++ case 'q':
+ qflag = strtonum(optarg, INT_MIN, INT_MAX, &errstr);
+ if (errstr)
+ errx(1, "quit timer %s: %s", errstr, optarg);
++ if (qflag >= 0)
++ Nflag = 1;
+ break;
- case 'r':
- rflag = 1;
- break;
-@@ -924,9 +932,18 @@ readwrite(int nfd)
- }
- else if (pfd[1].revents & POLLHUP) {
- shutdown_wr:
-+ /* if the user asked to exit on EOF, do it */
-+ if (qflag == 0) {
- shutdown(nfd, SHUT_WR);
-- pfd[1].fd = -1;
-- pfd[1].events = 0;
-+ close(wfd);
-+ }
-+ /* if user asked to die after a while, arrange for it */
-+ if (qflag > 0) {
-+ signal(SIGALRM, quit);
-+ alarm(qflag);
-+ }
-+ pfd[1].fd = -1;
-+ pfd[1].events = 0;
- }
- }
- }
-@@ -1164,6 +1181,7 @@ help(void)
+ # if defined(TLS)
+ case 'R':
+ tls_cachanged = 1;
+@@ -1320,15 +1330,27 @@ readwrite(int net_fd)
+ while (1) {
+ /* both inputs are gone, buffers are empty, we are done */
+ if (pfd[POLL_STDIN].fd == -1 && pfd[POLL_NETIN].fd == -1 &&
+- stdinbufpos == 0 && netinbufpos == 0)
+- return;
++ stdinbufpos == 0 && netinbufpos == 0) {
++ if (qflag <= 0)
++ return;
++ goto delay_exit;
++ }
+ /* both outputs are gone, we can't continue */
+- if (pfd[POLL_NETOUT].fd == -1 && pfd[POLL_STDOUT].fd == -1)
+- return;
++ if (pfd[POLL_NETOUT].fd == -1 && pfd[POLL_STDOUT].fd == -1) {
++ if (qflag <= 0)
++ return;
++ goto delay_exit;
++ }
+ /* listen and net in gone, queues empty, done */
+ if (lflag && pfd[POLL_NETIN].fd == -1 &&
+- stdinbufpos == 0 && netinbufpos == 0)
+- return;
++ stdinbufpos == 0 && netinbufpos == 0) {
++ if (qflag <= 0)
++ return;
++delay_exit:
++ close(net_fd);
++ signal(SIGALRM, quit);
++ alarm(qflag);
++ }
+
+ /* poll */
+ num_fds = poll(pfd, 4, timeout);
+@@ -2053,6 +2075,7 @@ help(void)
\t-O length TCP send buffer length\n\
\t-P proxyuser\tUsername for proxy authentication\n\
\t-p port\t Specify local port for remote connects\n\
-+ \t-q secs\t quit after EOF on stdin and delay of secs\n\
++ \t-q secs\t quit after EOF on stdin and delay of secs\n\
\t-r Randomize remote ports\n\
\t-S Enable the TCP MD5 signature option\n\
- \t-s addr\t Local source address\n\
-@@ -1186,9 +1204,19 @@ usage(int ret)
- {
+ \t-s source Local source address\n\
+@@ -2077,10 +2100,19 @@ usage(int ret)
fprintf(stderr,
- "usage: nc [-46CDdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n"
-- "\t [-P proxy_username] [-p source_port] [-s source] [-T toskeyword]\n"
-- "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
-+ "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n"
-+ "\t [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]\n"
- "\t [-x proxy_address[:port]] [destination] [port]\n");
+ "usage: nc [-46CDdFhklNnrStUuvz] [-I length] [-i interval] [-M ttl]\n"
+ "\t [-m minttl] [-O length] [-P proxy_username] [-p source_port]\n"
+- "\t [-s source] [-T keyword] [-V rtable] [-W recvlimit] "
++ "\t [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] "
+ "[-w timeout]\n"
+ "\t [-X proxy_protocol] [-x proxy_address[:port]] "
+ "\t [destination] [port]\n");
if (ret)
exit(1);
}
@@ -127,7 +139,5 @@ index 4f4d2bf..29ecf1a 100644
+ */
+static void quit()
+{
-+ /* XXX: should explicitly close fds here */
-+ exit(0);
++ exit(0);
+}
---