netcat-openbsd/verbose-numeric-port.patch

55 lines
1.4 KiB
Diff

Index: netcat-openbsd-1.89/netcat.c
===================================================================
--- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:34.000000000 -0500
+++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:44.000000000 -0500
@@ -41,6 +41,7 @@
#include <netinet/tcp.h>
#include <netinet/ip.h>
#include <arpa/telnet.h>
+#include <arpa/inet.h>
#include <err.h>
#include <errno.h>
@@ -317,16 +318,15 @@
if (uflag) {
int rv, plen;
char buf[8192];
- struct sockaddr_storage z;
- len = sizeof(z);
+ len = sizeof(cliaddr);
plen = jflag ? 8192 : 1024;
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");
@@ -337,6 +337,21 @@
&len);
}
+ if(vflag) {
+ /* Don't look up port if -n. */
+ if (nflag)
+ sv = NULL;
+ else
+ sv = getservbyport(ntohs(atoi(uport)),
+ uflag ? "udp" : "tcp");
+
+ fprintf(stderr, "Connection from %s port %s [%s/%s] accepted\n",
+ inet_ntoa(((struct sockaddr_in *)(&cliaddr))->sin_addr),
+ uport,
+ uflag ? "udp" : "tcp",
+ sv ? sv->s_name : "*");
+ }
+
readwrite(connfd);
close(connfd);
if (family != AF_UNIX)