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

Last change on this file since 2154c77 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
RevLine 
[c5c522c]1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 15:29:37 +0800
3Subject: udp scan timeout
4
5---
6 netcat.c |   25 ++++++++++++++++---------
7 1 file changed, 16 insertions(+), 9 deletions(-)
8
9diff --git a/netcat.c b/netcat.c
10index 29ecf1a..baab909 100644
11--- a/netcat.c
12+++ b/netcat.c
13@@ -111,6 +111,8 @@
14 #define CONNECTION_FAILED 1
15 #define CONNECTION_TIMEOUT 2
16 
17+#define UDP_SCAN_TIMEOUT 3                     /* Seconds */
18+
19 /* Command Line Options */
20 int     Cflag = 0;                              /* CRLF line-ending */
21 int    dflag;                                  /* detached, no stdin */
22@@ -497,7 +499,7 @@ main(int argc, char *argv[])
23                                continue;
24 
25                        ret = 0;
26-                       if (vflag || zflag) {
27+                       if (vflag) {
28                                /* For UDP, make sure we are connected. */
29                                if (uflag) {
30                                        if (udptest(s) == -1) {
31@@ -1057,15 +1059,20 @@ build_ports(char *p)
32 int
33 udptest(int s)
34 {
35-       int i, ret;
36-
37-       for (i = 0; i <= 3; i++) {
38-               if (write(s, "X", 1) == 1)
39-                       ret = 1;
40-               else
41-                       ret = -1;
42+       int i, t;
43+
44+       if ((write(s, "X", 1) != 1) ||
45+           ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED)))
46+               return -1;
47+
48+       /* Give the remote host some time to reply. */
49+       for (i = 0, t = (timeout == -1) ? UDP_SCAN_TIMEOUT : (timeout / 1000);
50+            i < t; i++) {
51+               sleep(1);
52+               if ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED))
53+                       return -1;
54        }
55-       return (ret);
56+       return 1;
57 }
58 
59 void
60--
Note: See TracBrowser for help on using the repository browser.