|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
Re: [PATCH] verbose msg on -l, verbose to stderr on nc(1)
From: Fabio Olive Leite (fabio.olive
gmail.com)
Date: Sat Apr 02 2005 - 00:52:38 CST
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
The patch below adds a verbose message to the listen mode on nc(1) and
also puts the existing verbose "Connect" message to stderr. As nc(1)
will use read/write directly on fd 1 after printf'ing the "Connect"
message, when the user pipes its output away from a line-buffered
terminal the stdio buffer will never be flushed and you'll never get
the connect message.
If you don't like informative messages on stderr, at least add
fflush(stdout) calls after the printf's.
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 2 Apr 2005 06:46:00 -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);
+ }
+ fprintf(stderr, "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);
+ }
+ fprintf(stderr, "Connection from %s [%u/%s]!\n",
+ hostname,
+ ntohs(((struct sockaddr_in6 *)&sockst)->sin6_port),
+ uflag ? "udp" : "tcp");
+ }
+ }
+ }
readwrite(connfd);
close(connfd);

-364,7 +395,7 
uflag ? "udp" : "tcp");
}
- printf("Connection to %s %s port [%s/%s] succeeded!\n",
+ fprintf(stderr, "Connection to %s %s port [%s/%s] succeeded!\n",
host, portlist[i], uflag ? "udp" : "tcp",
sv ? sv->s_name : "*");
}
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 ]