2017-07-17 15:26:12 +02:00
|
|
|
From: Aron Xu <aron@debian.org>
|
|
|
|
Date: Mon, 13 Feb 2012 15:29:37 +0800
|
|
|
|
Subject: udp scan timeout
|
|
|
|
|
|
|
|
---
|
|
|
|
netcat.c | 23 +++++++++++++++--------
|
|
|
|
1 file changed, 15 insertions(+), 8 deletions(-)
|
|
|
|
|
|
|
|
--- a/netcat.c
|
|
|
|
+++ b/netcat.c
|
|
|
|
@@ -129,6 +129,8 @@
|
2013-09-02 21:53:10 +02:00
|
|
|
#define CONNECTION_FAILED 1
|
|
|
|
#define CONNECTION_TIMEOUT 2
|
|
|
|
|
|
|
|
+#define UDP_SCAN_TIMEOUT 3 /* Seconds */
|
|
|
|
+
|
|
|
|
/* Command Line Options */
|
|
|
|
int dflag; /* detached, no stdin */
|
2017-07-17 15:26:12 +02:00
|
|
|
int Fflag; /* fdpass sock to stdout */
|
2018-11-14 14:18:05 +01:00
|
|
|
@@ -815,7 +817,7 @@ main(int argc, char *argv[])
|
2013-09-02 21:53:10 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = 0;
|
2017-07-17 15:26:12 +02:00
|
|
|
- if (vflag || zflag) {
|
|
|
|
+ if (vflag) {
|
2013-09-02 21:53:10 +02:00
|
|
|
/* For UDP, make sure we are connected. */
|
|
|
|
if (uflag) {
|
|
|
|
if (udptest(s) == -1) {
|
2018-11-14 14:18:05 +01:00
|
|
|
@@ -1743,15 +1745,20 @@ build_ports(char *p)
|
2013-09-02 21:53:10 +02:00
|
|
|
int
|
|
|
|
udptest(int s)
|
|
|
|
{
|
|
|
|
- int i, ret;
|
|
|
|
+ int i, t;
|
|
|
|
|
|
|
|
- for (i = 0; i <= 3; i++) {
|
|
|
|
- if (write(s, "X", 1) == 1)
|
|
|
|
- ret = 1;
|
|
|
|
- else
|
|
|
|
- ret = -1;
|
|
|
|
+ if ((write(s, "X", 1) != 1) ||
|
|
|
|
+ ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED)))
|
|
|
|
+ return -1;
|
|
|
|
+
|
|
|
|
+ /* Give the remote host some time to reply. */
|
|
|
|
+ for (i = 0, t = (timeout == -1) ? UDP_SCAN_TIMEOUT : (timeout / 1000);
|
|
|
|
+ i < t; i++) {
|
|
|
|
+ sleep(1);
|
|
|
|
+ if ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED))
|
|
|
|
+ return -1;
|
|
|
|
}
|
2018-11-14 14:18:05 +01:00
|
|
|
- return ret;
|
2013-09-02 21:53:10 +02:00
|
|
|
+ return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|