2017-07-17 15:26:12 +02:00
|
|
|
From: Aron Xu <aron@debian.org>
|
|
|
|
Date: Mon, 13 Feb 2012 15:38:15 +0800
|
|
|
|
Subject: verbose numeric port
|
|
|
|
|
|
|
|
---
|
2018-11-14 14:18:05 +01:00
|
|
|
netcat.c | 25 ++++++++++++++++++++-----
|
|
|
|
1 file changed, 20 insertions(+), 5 deletions(-)
|
2017-07-17 15:26:12 +02:00
|
|
|
|
|
|
|
--- a/netcat.c
|
|
|
|
+++ b/netcat.c
|
|
|
|
@@ -43,6 +43,7 @@
|
2013-09-02 21:53:10 +02:00
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <arpa/telnet.h>
|
|
|
|
+#include <arpa/inet.h>
|
2017-07-17 15:26:12 +02:00
|
|
|
#ifdef __linux__
|
|
|
|
# include <linux/in6.h>
|
|
|
|
#endif
|
2018-11-14 14:18:05 +01:00
|
|
|
@@ -689,6 +690,21 @@ main(int argc, char *argv[])
|
|
|
|
}
|
2017-07-17 15:26:12 +02:00
|
|
|
if (s < 0)
|
|
|
|
err(1, NULL);
|
|
|
|
+
|
2018-11-14 14:18:05 +01:00
|
|
|
+ if (vflag && (family != AF_UNIX)) {
|
|
|
|
+ char* local;
|
|
|
|
+ if (family == AF_INET)
|
|
|
|
+ local = "0.0.0.0";
|
|
|
|
+ else if (family == AF_INET6)
|
|
|
|
+ local = "::";
|
|
|
|
+ else
|
|
|
|
+ local = "unknown";
|
|
|
|
+ fprintf(stderr, "Listening on [%s] (family %d, port %d)\n",
|
|
|
|
+ host ?: local,
|
|
|
|
+ family,
|
|
|
|
+ *uport);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
if (uflag && kflag) {
|
|
|
|
/*
|
|
|
|
* For UDP and -k, don't connect the socket,
|
|
|
|
@@ -708,20 +724,19 @@ main(int argc, char *argv[])
|
|
|
|
*/
|
|
|
|
int rv;
|
|
|
|
char buf[2048];
|
|
|
|
- struct sockaddr_storage z;
|
2013-09-02 21:53:10 +02:00
|
|
|
|
|
|
|
- len = sizeof(z);
|
|
|
|
+ len = sizeof(cliaddr);
|
2018-11-14 14:18:05 +01:00
|
|
|
rv = recvfrom(s, buf, sizeof(buf), MSG_PEEK,
|
2013-09-02 21:53:10 +02:00
|
|
|
- (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");
|
|
|
|
|
2018-11-14 14:18:05 +01:00
|
|
|
if (vflag)
|
|
|
|
- report_connect((struct sockaddr *)&z, len, NULL);
|
|
|
|
+ report_connect((struct sockaddr *)&cliaddr, len, NULL);
|
|
|
|
|
|
|
|
# if defined(TLS)
|
|
|
|
readwrite(s, NULL);
|