slackbuilds_ponce/network/netcat-openbsd/patches/0007-udp-scan-timeout.patch
Matteo Bernardini b49d0a636b network/netcat-openbsd: Updated for version 1.105 (from Debian).
Apply the patches locally and added a note
about this package being incompatible with nc from Slackware

Signed-off-by: Matteo Bernardini <ponce@slackbuilds.org>
2013-11-06 00:57:03 -06:00

60 lines
1.3 KiB
Diff

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/netcat.c
+++ b/netcat.c
@@ -111,6 +111,8 @@
#define CONNECTION_FAILED 1
#define CONNECTION_TIMEOUT 2
+#define UDP_SCAN_TIMEOUT 3 /* Seconds */
+
/* Command Line Options */
int Cflag = 0; /* CRLF line-ending */
int dflag; /* detached, no stdin */
@@ -497,7 +499,7 @@ main(int argc, char *argv[])
continue;
ret = 0;
- if (vflag || zflag) {
+ if (vflag) {
/* For UDP, make sure we are connected. */
if (uflag) {
if (udptest(s) == -1) {
@@ -1057,15 +1059,20 @@ build_ports(char *p)
int
udptest(int s)
{
- int i, ret;
-
- for (i = 0; i <= 3; i++) {
- if (write(s, "X", 1) == 1)
- ret = 1;
- else
- ret = -1;
+ int i, t;
+
+ 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;
}
- return (ret);
+ return 1;
}
void
--