Hi,

this patch adds this option to nc(1):

-q timeout
        after end-of-file on stdin, wait timeout seconds and then quit.
        The default is no timeout.

This should be compatible with the -q option of the netcat-openbsd
package in debian (what the heck ?)
I use this to send simple udp datagrams:
echo 'Hello World!' |obj/nc -uq0 88.88.88.88 88

ok?

Christopher


Index: nc.1
===================================================================
RCS file: /cvs/src/usr.bin/nc/nc.1,v
retrieving revision 1.65
diff -u -p -r1.65 nc.1
--- nc.1        20 Aug 2013 21:05:20 -0000      1.65
+++ nc.1        5 Nov 2013 20:09:32 -0000
@@ -172,6 +172,11 @@ should use, subject to privilege restric
 It is an error to use this option in conjunction with the
 .Fl l
 option.
+.It Fl q Ar timeout
+after end-of-file on stdin, wait
+.Ar timeout
+seconds and then quit.
+The default is no timeout.
 .It Fl r
 Specifies that source and/or destination ports should be chosen
randomly instead of sequentially within a range or in the order that
the system Index: netcat.c
===================================================================
RCS file: /cvs/src/usr.bin/nc/netcat.c,v
retrieving revision 1.117
diff -u -p -r1.117 netcat.c
--- netcat.c    26 Oct 2013 21:33:29 -0000      1.117
+++ netcat.c    5 Nov 2013 20:09:33 -0000
@@ -90,6 +90,7 @@ int   Tflag =
-1;                             /* IP Type of Service int
rtableid = -1; 
 int timeout = -1;
+int fintime = -1;
 int family = AF_UNSPEC;
 char *portlist[PORT_MAX+1];
 char *unix_dg_tmp_socket;
@@ -136,7 +137,7 @@ main(int argc, char *argv[])
        rtableid = getrtable();
 
        while ((ch = getopt(argc, argv,
-           "46DdFhI:i:klNnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) {
+           "46DdFhI:i:klNnO:P:p:q:rSs:tT:UuV:vw:X:x:z")) != -1) {
                switch (ch) {
                case '4':
                        family = AF_INET;
@@ -216,6 +217,12 @@ main(int argc, char *argv[])
                                errx(1, "timeout %s: %s", errstr,
optarg); timeout *= 1000;
                        break;
+               case 'q':
+                       fintime = strtonum(optarg, 0, INT_MAX / 1000,
&errstr);
+                       if (errstr)
+                               errx(1, "timeout %s: %s", errstr,
optarg);
+                       fintime *= 1000;
+                       break;
                case 'x':
                        xflag = 1;
                        if ((proxy = strdup(optarg)) == NULL)
@@ -782,6 +789,8 @@ readwrite(int nfd)
                        else if (n == 0) {
                                if (Nflag)
                                        shutdown(nfd, SHUT_WR);
+                               if (fintime >= 0)
+                                       timeout = fintime;
                                pfd[1].fd = -1;
                                pfd[1].events = 0;
                        } else {
@@ -1090,6 +1099,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     Timeout for final net reads after EOF is
read on stdin\n\ \t-r           Randomize remote ports\n\
        \t-S            Enable the TCP MD5 signature option\n\
        \t-s addr\t     Local source address\n\
@@ -1113,7 +1123,7 @@ usage(int ret)
        fprintf(stderr,
            "usage: nc [-46DdFhklNnrStUuvz] [-I length] [-i interval]
[-O length]\n" "\t  [-P proxy_username] [-p source_port] [-s source]
[-T ToS]\n"
-           "\t  [-V rtable] [-w timeout] [-X proxy_protocol]\n"
+           "\t  [-V rtable] [-w timeout] [-q timeout] [-X
proxy_protocol]\n" "\t  [-x proxy_address[:port]] [destination]
[port]\n"); if (ret)
                exit(1);



-- 
http://gmerlin.de
OpenPGP: http://gmerlin.de/christopher.pub
1917 680A 723C BF3D 2CA3  0E44 7E24 D19F 34B8 2A2A

Attachment: signature.asc
Description: PGP signature

Reply via email to