source: npl/overig/netcat_openbsd/patches/0006-quit-timer.patch @ a9c55d3

perl-5.22
Last change on this file since a9c55d3 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
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  
    4040.Op Fl O Ar length
    4141.Op Fl P Ar proxy_username
    4242.Op Fl p Ar source_port
     43.Op Fl q Ar seconds
    4344.Op Fl s Ar source
    4445.Op Fl T Ar toskeyword
    4546.Op Fl V Ar rtable
    Proxy authentication is only supported for HTTP CONNECT proxies at present. 
    148149Specifies the source port
    149150.Nm
    150151should use, subject to privilege restrictions and availability.
     152.It Fl q Ar seconds
     153after EOF on stdin, wait the specified number of seconds and then quit. If
     154.Ar seconds
     155is negative, wait forever.
    151156.It Fl r
    152157Specifies that source and/or destination ports should be chosen randomly
    153158instead 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  
    8686#include <errno.h>
    8787#include <netdb.h>
    8888#include <poll.h>
     89#include <signal.h>
    8990#include <stdarg.h>
    9091#include <stdio.h>
    9192#include <stdlib.h>
    int lflag; /* Bind to local port */ 
    120121int     nflag;                                  /* Don't do name look up */
    121122char   *Pflag;                                  /* Proxy username */
    122123char   *pflag;                                  /* Localport flag */
     124int     qflag = 0;                             /* Quit after some secs */
    123125int     rflag;                                  /* Random ports flag */
    124126char   *sflag;                                  /* Source Address */
    125127int     tflag;                                  /* Telnet Emulation */
    void usage(int); 
    158160
    159161static int connect_with_timeout(int fd, const struct sockaddr *sa,
    160162        socklen_t salen, int ctimeout);
     163static void quit();
    161164
    162165int
    163166main(int argc, char *argv[])
    main(int argc, char *argv[]) 
    181184        sv = NULL;
    182185
    183186        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) {
    185188                switch (ch) {
    186189                case '4':
    187190                        family = AF_INET;
    main(int argc, char *argv[]) 
    235238                case 'p':
    236239                        pflag = optarg;
    237240                        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;
    238246                case 'r':
    239247                        rflag = 1;
    240248                        break;
    readwrite(int nfd) 
    924932                        }
    925933                        else if (pfd[1].revents & POLLHUP) {
    926934                        shutdown_wr:
     935                        /* if the user asked to exit on EOF, do it */
     936                        if (qflag == 0) {
    927937                                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;
    930947                        }
    931948                }
    932949        }
    help(void) 
    11641181        \t-O length     TCP send buffer length\n\
    11651182        \t-P proxyuser\tUsername for proxy authentication\n\
    11661183        \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\
    11671185        \t-r            Randomize remote ports\n\
    11681186        \t-S            Enable the TCP MD5 signature option\n\
    11691187        \t-s addr\t     Local source address\n\
    usage(int ret) 
    11861204{
    11871205        fprintf(stderr,
    11881206            "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"
    11911209            "\t  [-x proxy_address[:port]] [destination] [port]\n");
    11921210        if (ret)
    11931211                exit(1);
    11941212}
     1213
     1214/*
     1215 * quit()
     1216 * handler for a "-q" timeout (exit 0 instead of 1)
     1217 */
     1218static void quit()
     1219{
     1220        /* XXX: should explicitly close fds here */
     1221        exit(0);
     1222}
Note: See TracBrowser for help on using the repository browser.