unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob b2ddd1e73d9b2786ad13853ffb4ae248d97f6898 3442 bytes (raw)
name: gnu/packages/patches/netcat-openbsd-0008-verbose-numeric-port.patch 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
 
This patch is based on db2b1d9a8d4644ef892f47d84606ee96598d23fb
of http://anonscm.debian.org/cgit/collab-maint/netcat-openbsd.git

From: Aron Xu <aron@debian.org>
Date: Mon, 13 Feb 2012 15:38:15 +0800
Subject: verbose numeric port

---
 netcat.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 55 insertions(+), 4 deletions(-)

diff --git a/netcat.c b/netcat.c
index baab909..eb3453e 100644
--- a/netcat.c
+++ b/netcat.c
@@ -41,6 +41,7 @@
 #include <netinet/tcp.h>
 #include <netinet/ip.h>
 #include <arpa/telnet.h>
+#include <arpa/inet.h>

 #ifndef IPTOS_LOWDELAY
 # define IPTOS_LOWDELAY 0x10
@@ -424,6 +425,18 @@ main(int argc, char *argv[])
 				s = local_listen(host, uport, hints);
 			if (s < 0)
 				err(1, NULL);
+
+			char* local;
+			if (family == AF_INET6
+				local = "0.0.0.0";
+			else if (family == AF_INET)
+				local = ":::";
+			else
+				local = "unknown"
+			fprintf(stderr, "Listening on [%s] (family %d, port %d)\n",
+				host ?: local,
+				family,
+				*uport);
 			/*
 			 * For UDP, we will use recvfrom() initially
 			 * to wait for a caller, then use the regular
@@ -432,16 +445,15 @@ main(int argc, char *argv[])
 			if (uflag) {
 				int rv, plen;
 				char buf[16384];
-				struct sockaddr_storage z;

-				len = sizeof(z);
+				len = sizeof(cliaddr);
 				plen = jflag ? 16384 : 2048;
 				rv = recvfrom(s, buf, plen, MSG_PEEK,
-				    (struct sockaddr *)&z, &len);
+				    (struct sockaddr *)&cliaddr, &len);
 				if (rv < 0)
 					err(1, "recvfrom");

-				rv = connect(s, (struct sockaddr *)&z, len);
+				rv = connect(s, (struct sockaddr *)&cliaddr, len);
 				if (rv < 0)
 					err(1, "connect");

@@ -450,6 +462,45 @@ main(int argc, char *argv[])
 				len = sizeof(cliaddr);
 				connfd = accept(s, (struct sockaddr *)&cliaddr,
 				    &len);
+				if(vflag) {
+				/* Don't look up port if -n. */
+					if (nflag)
+						sv = NULL;
+					else
+						sv = getservbyport(ntohs(atoi(uport)),
+							uflag ? "udp" : "tcp");
+
+					if (((struct sockaddr *)&cliaddr)->sa_family == AF_INET) {
+						char dst[INET_ADDRSTRLEN];
+						inet_ntop(((struct sockaddr *)&cliaddr)->sa_family,&(((struct sockaddr_in *)&cliaddr)->sin_addr),dst,INET_ADDRSTRLEN);
+						fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n",
+							dst,
+							uport,
+							uflag ? "udp" : "tcp",
+							sv ? sv->s_name : "*",
+							((struct sockaddr *)(&cliaddr))->sa_family,
+							ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
+					}
+					else if(((struct sockaddr *)&cliaddr)->sa_family == AF_INET6) {
+						char dst[INET6_ADDRSTRLEN];
+						inet_ntop(((struct sockaddr *)&cliaddr)->sa_family,&(((struct sockaddr_in6 *)&cliaddr)->sin6_addr),dst,INET6_ADDRSTRLEN);
+						fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n",
+							dst,
+							uport,
+							uflag ? "udp" : "tcp",
+							sv ? sv->s_name : "*",
+							((struct sockaddr *)&cliaddr)->sa_family,
+							ntohs(((struct sockaddr_in6 *)&cliaddr)->sin6_port));
+					}
+					else {
+						fprintf(stderr, "Connection from unknown port %s [%s/%s] accepted (family %d, sport %d)\n",
+							uport,
+							uflag ? "udp" : "tcp",
+							sv ? sv->s_name : "*",
+							((struct sockaddr *)(&cliaddr))->sa_family,
+							ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
+					}
+				}
 				readwrite(connfd);
 				close(connfd);
 			}
--

debug log:

solving b2ddd1e ...
found b2ddd1e in https://yhetil.org/guix-devel/20160622110046.GA12755@shadowwalker/

applying [1/1] https://yhetil.org/guix-devel/20160622110046.GA12755@shadowwalker/
diff --git a/gnu/packages/patches/netcat-openbsd-0008-verbose-numeric-port.patch b/gnu/packages/patches/netcat-openbsd-0008-verbose-numeric-port.patch
new file mode 100644
index 0000000..b2ddd1e

1:31: space before tab in indent.
 				s = local_listen(host, uport, hints);
1:32: space before tab in indent.
 			if (s < 0)
1:33: space before tab in indent.
 				err(1, NULL);
1:46: space before tab in indent.
 			/*
1:47: space before tab in indent.
 			 * For UDP, we will use recvfrom() initially
Checking patch gnu/packages/patches/netcat-openbsd-0008-verbose-numeric-port.patch...
Applied patch gnu/packages/patches/netcat-openbsd-0008-verbose-numeric-port.patch cleanly.
warning: squelched 16 whitespace errors
warning: 21 lines add whitespace errors.

skipping https://yhetil.org/guix-devel/20160622110046.GA12755@shadowwalker/ for b2ddd1e
index at:
100644 b2ddd1e73d9b2786ad13853ffb4ae248d97f6898	gnu/packages/patches/netcat-openbsd-0008-verbose-numeric-port.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).