source: npl/overig/netcat_openbsd/patches/0007-udp-scan-timeout.patch @ ffaaf60

Last change on this file since ffaaf60 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: 1.3 KB
  • netcat.c

    From: Aron Xu <aron@debian.org>
    Date: Mon, 13 Feb 2012 15:29:37 +0800
    Subject: udp scan timeout
    
    ---
     netcat.c |   25 ++++++++++++++++---------
     1 file changed, 16 insertions(+), 9 deletions(-)
    
    diff --git a/netcat.c b/netcat.c
    index 29ecf1a..baab909 100644
    a b  
    111111#define CONNECTION_FAILED 1
    112112#define CONNECTION_TIMEOUT 2
    113113
     114#define UDP_SCAN_TIMEOUT 3                      /* Seconds */
     115
    114116/* Command Line Options */
    115117int     Cflag = 0;                              /* CRLF line-ending */
    116118int     dflag;                                  /* detached, no stdin */
    main(int argc, char *argv[]) 
    497499                                continue;
    498500
    499501                        ret = 0;
    500                         if (vflag || zflag) {
     502                        if (vflag) {
    501503                                /* For UDP, make sure we are connected. */
    502504                                if (uflag) {
    503505                                        if (udptest(s) == -1) {
    build_ports(char *p) 
    10571059int
    10581060udptest(int s)
    10591061{
    1060         int i, ret;
    1061 
    1062         for (i = 0; i <= 3; i++) {
    1063                 if (write(s, "X", 1) == 1)
    1064                         ret = 1;
    1065                 else
    1066                         ret = -1;
     1062        int i, t;
     1063
     1064        if ((write(s, "X", 1) != 1) ||
     1065            ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED)))
     1066                return -1;
     1067
     1068        /* Give the remote host some time to reply. */
     1069        for (i = 0, t = (timeout == -1) ? UDP_SCAN_TIMEOUT : (timeout / 1000);
     1070             i < t; i++) {
     1071                sleep(1);
     1072                if ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED))
     1073                        return -1;
    10671074        }
    1068         return (ret);
     1075        return 1;
    10691076}
    10701077
    10711078void
Note: See TracBrowser for help on using the repository browser.