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

---
 netcat.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/netcat.c b/netcat.c
index 9ab507a..3240a08 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
@@ -436,6 +437,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 and -k, don't connect the socket, let it
 			 * receive datagrams from multiple socket pairs.
@@ -452,14 +465,14 @@ main(int argc, char *argv[])
 				char buf[16384];
 				struct sockaddr_storage z;
 
-				len = sizeof(z);
+				len = sizeof(cliaddr);
 				plen = 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");
 
-- 
