|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
[PATCH] adding -v to nc -l
From: Fabio Olive Leite (fabio.olive
gmail.com)
Date: Fri Apr 01 2005 - 12:46:07 CST
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
The patch below, motivated by my april 1st joke on misc
, adds an
actual -v "connect" message when nc is in listen mode (-l). Its lines
are long, my type casts look bad, and I had never used inet_ntop
before, so beware. I hope it will be "purified" by a proper developer
if it gets accepted. It does work, anyway.
Index: netcat.c
===================================================================
RCS file: /cvs/src/usr.bin/nc/netcat.c,v
retrieving revision 1.77
diff -u -r1.77 netcat.c
--- netcat.c 8 Feb 2005 15:26:23 -0000 1.77
+++ netcat.c 1 Apr 2005 18:42:10 -0000

-305,6 +305,37 
connfd = accept(s, (struct sockaddr *)&cliaddr,
&len);
}
+ if (vflag) {
+ struct sockaddr_storage sockst;
+ int rv;
+ char hostname[64];
+
+ len = sizeof(sockst);
+ rv = getpeername(connfd, (struct sockaddr *)&sockst, &len);
+ if (rv < 0) {
+ err(1, "getpeername");
+ } else {
+ if (sockst.ss_family == AF_INET) {
+ if (inet_ntop(sockst.ss_family, &((struct sockaddr_in *)&sockst)->sin_addr, hostname, 64) == NULL) {
+ err(1, "inet_ntop");
+ strlcpy(hostname, "?", 1);
+ }
+ printf("Connection from %s [%u/%s]!\n",
+ hostname,
+ ntohs(((struct sockaddr_in *)&sockst)->sin_port),
+ uflag ? "udp" : "tcp");
+ } else if (sockst.ss_family == AF_INET6) {
+ if (inet_ntop(sockst.ss_family, &((struct sockaddr_in6 *)&sockst)->sin6_addr, hostname, 64) == NULL) {
+ err(1, "inet_ntop");
+ strlcpy(hostname, "?", 1);
+ }
+ printf("Connection from %s [%u/%s]!\n",
+ hostname,
+ ntohs(((struct sockaddr_in6 *)&sockst)->sin6_port),
+ uflag ? "udp" : "tcp");
+ }
+ }
+ }
readwrite(connfd);
close(connfd);
Regards,
fabio.olive
--
I drowned in the universal pool of entropy
Eris has saved me, and she has set me free
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]