Re: nc(1): Report incoming connections on nc -v -l
Still waiting for another ok. On Thu, Jun 28, 2012 at 11:36:27PM -0300, Christiano F. Haesbaert wrote: > This looks good to me, can I get another ok ? > > > On Sun, Jun 24, 2012 at 07:07:29AM -0400, Ricky Zhou wrote: > > On 2012-06-16 02:37:27 PM, Christiano F. Haesbaert wrote: > > > I guess so, I don't use nc too often but it sounds reasonable to me, > > > your code has a few notes though, please check inline. > > (Sorry for the slow response, was travelling last week) > > > > Thanks for looking at the patch - here's a new one with your fixes > > included. > > > > Thanks, > > Ricky > > > > > > Index: netcat.c > > === > > RCS file: /cvs/src/usr.bin/nc/netcat.c,v > > retrieving revision 1.107 > > diff -u netcat.c > > --- netcat.c1 Apr 2012 02:58:57 - 1.107 > > +++ netcat.c24 Jun 2012 09:51:19 - > > @@ -106,6 +106,7 @@ > > intunix_listen(char *); > > void set_common_sockopts(int); > > intmap_tos(char *, int *); > > +void report_connect(const struct sockaddr *, socklen_t); > > void usage(int); > > > > int > > @@ -364,6 +365,9 @@ > > if (rv < 0) > > err(1, "connect"); > > > > + if (vflag) > > + report_connect((struct sockaddr *)&z, > > len); > > + > > readwrite(s); > > } else { > > len = sizeof(cliaddr); > > @@ -371,6 +375,10 @@ > > &len); > > if (connfd == -1) > > err(1, "accept"); > > + > > + if (vflag) > > + report_connect((struct sockaddr > > *)&cliaddr, len); > > + > > readwrite(connfd); > > close(connfd); > > } > > @@ -957,6 +965,32 @@ > > } > > > > return (0); > > +} > > + > > +void > > +report_connect(const struct sockaddr *sa, socklen_t salen) > > +{ > > + char remote_host[NI_MAXHOST]; > > + char remote_port[NI_MAXSERV]; > > + int herr; > > + int flags = NI_NUMERICSERV; > > + > > + if (nflag) > > + flags |= NI_NUMERICHOST; > > + > > + if ((herr = getnameinfo(sa, salen, > > + remote_host, sizeof(remote_host), > > + remote_port, sizeof(remote_port), > > + flags)) != 0) { > > + if (herr == EAI_SYSTEM) > > + err(1, "getnameinfo"); > > + else > > + errx(1, "getnameinfo: %s", gai_strerror(herr)); > > + } > > + > > + fprintf(stderr, > > + "Connection from %s %s " > > + "received!\n", remote_host, remote_port); > > } > > > > void
Re: nc(1): Report incoming connections on nc -v -l
This looks good to me, can I get another ok ? On Sun, Jun 24, 2012 at 07:07:29AM -0400, Ricky Zhou wrote: > On 2012-06-16 02:37:27 PM, Christiano F. Haesbaert wrote: > > I guess so, I don't use nc too often but it sounds reasonable to me, > > your code has a few notes though, please check inline. > (Sorry for the slow response, was travelling last week) > > Thanks for looking at the patch - here's a new one with your fixes > included. > > Thanks, > Ricky > > > Index: netcat.c > === > RCS file: /cvs/src/usr.bin/nc/netcat.c,v > retrieving revision 1.107 > diff -u netcat.c > --- netcat.c 1 Apr 2012 02:58:57 - 1.107 > +++ netcat.c 24 Jun 2012 09:51:19 - > @@ -106,6 +106,7 @@ > int unix_listen(char *); > void set_common_sockopts(int); > int map_tos(char *, int *); > +void report_connect(const struct sockaddr *, socklen_t); > void usage(int); > > int > @@ -364,6 +365,9 @@ > if (rv < 0) > err(1, "connect"); > > + if (vflag) > + report_connect((struct sockaddr *)&z, > len); > + > readwrite(s); > } else { > len = sizeof(cliaddr); > @@ -371,6 +375,10 @@ > &len); > if (connfd == -1) > err(1, "accept"); > + > + if (vflag) > + report_connect((struct sockaddr > *)&cliaddr, len); > + > readwrite(connfd); > close(connfd); > } > @@ -957,6 +965,32 @@ > } > > return (0); > +} > + > +void > +report_connect(const struct sockaddr *sa, socklen_t salen) > +{ > + char remote_host[NI_MAXHOST]; > + char remote_port[NI_MAXSERV]; > + int herr; > + int flags = NI_NUMERICSERV; > + > + if (nflag) > + flags |= NI_NUMERICHOST; > + > + if ((herr = getnameinfo(sa, salen, > + remote_host, sizeof(remote_host), > + remote_port, sizeof(remote_port), > + flags)) != 0) { > + if (herr == EAI_SYSTEM) > + err(1, "getnameinfo"); > + else > + errx(1, "getnameinfo: %s", gai_strerror(herr)); > + } > + > + fprintf(stderr, > + "Connection from %s %s " > + "received!\n", remote_host, remote_port); > } > > void
Re: nc(1): Report incoming connections on nc -v -l
On 2012-06-16 02:37:27 PM, Christiano F. Haesbaert wrote: > I guess so, I don't use nc too often but it sounds reasonable to me, > your code has a few notes though, please check inline. (Sorry for the slow response, was travelling last week) Thanks for looking at the patch - here's a new one with your fixes included. Thanks, Ricky Index: netcat.c === RCS file: /cvs/src/usr.bin/nc/netcat.c,v retrieving revision 1.107 diff -u netcat.c --- netcat.c1 Apr 2012 02:58:57 - 1.107 +++ netcat.c24 Jun 2012 09:51:19 - @@ -106,6 +106,7 @@ intunix_listen(char *); void set_common_sockopts(int); intmap_tos(char *, int *); +void report_connect(const struct sockaddr *, socklen_t); void usage(int); int @@ -364,6 +365,9 @@ if (rv < 0) err(1, "connect"); + if (vflag) + report_connect((struct sockaddr *)&z, len); + readwrite(s); } else { len = sizeof(cliaddr); @@ -371,6 +375,10 @@ &len); if (connfd == -1) err(1, "accept"); + + if (vflag) + report_connect((struct sockaddr *)&cliaddr, len); + readwrite(connfd); close(connfd); } @@ -957,6 +965,32 @@ } return (0); +} + +void +report_connect(const struct sockaddr *sa, socklen_t salen) +{ + char remote_host[NI_MAXHOST]; + char remote_port[NI_MAXSERV]; + int herr; + int flags = NI_NUMERICSERV; + + if (nflag) + flags |= NI_NUMERICHOST; + + if ((herr = getnameinfo(sa, salen, + remote_host, sizeof(remote_host), + remote_port, sizeof(remote_port), + flags)) != 0) { + if (herr == EAI_SYSTEM) + err(1, "getnameinfo"); + else + errx(1, "getnameinfo: %s", gai_strerror(herr)); + } + + fprintf(stderr, + "Connection from %s %s " + "received!\n", remote_host, remote_port); } void
Re: nc(1): Report incoming connections on nc -v -l
On Fri, Jun 15, 2012 at 10:43:13AM -0400, Ricky Zhou wrote: > This patch adds a message on incoming connections when netcat is run > with -l and -v. Does this look like a reasonable addition? I guess so, I don't use nc too often but it sounds reasonable to me, your code has a few notes though, please check inline. > > One thought is that report_connect might not need to err() when > getnameinfo fails thoughts? > > Thanks, > Ricky > > Index: netcat.c > === > RCS file: /cvs/src/usr.bin/nc/netcat.c,v > retrieving revision 1.107 > diff -u netcat.c > --- netcat.c 1 Apr 2012 02:58:57 - 1.107 > +++ netcat.c 15 Jun 2012 12:39:49 - > @@ -106,6 +106,7 @@ > int unix_listen(char *); > void set_common_sockopts(int); > int map_tos(char *, int *); > +void report_connect(const struct sockaddr *, socklen_t); > void usage(int); > > int > @@ -364,6 +365,9 @@ > if (rv < 0) > err(1, "connect"); > > + if (vflag) > + report_connect((struct sockaddr *)&z, > len); > + > readwrite(s); > } else { > len = sizeof(cliaddr); > @@ -371,6 +375,10 @@ > &len); > if (connfd == -1) > err(1, "accept"); > + > + if (vflag) > + report_connect((struct sockaddr > *)&cliaddr, len); > + > readwrite(connfd); > close(connfd); > } > @@ -957,6 +965,27 @@ > } > > return (0); > +} > + > +void > +report_connect(const struct sockaddr *sa, socklen_t salen) > +{ > + char remote_host[NI_MAXHOST]; > + char remote_port[NI_MAXSERV]; > + int flags = NI_NUMERICSERV; > + > + if (nflag) > + flags |= NI_NUMERICHOST; > + > + if (getnameinfo(sa, salen, > + remote_host, sizeof(remote_host), > + remote_port, sizeof(remote_port), > + flags) != 0) > + err(1, "getnameinfo"); Your getnameinfo() call is not correct, you want something like this: if ((herr = getnameinfo(addr, alen, hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), NI_NUMERICHOST|NI_NUMERICSERV)) != 0) { if (herr == EAI_SYSTEM) err(1, "getnameinfo"); else errx(1, "getnameinfo: %s", gai_strerror(herr)); You can only trust errno if getnameinfo returned EAI_SYSTEM. > + > + fprintf(stderr, > + "Connection from %s %s " > + "receieved!\n", remote_host, remote_port); Typo here: receieved. > } > > void
nc(1): Report incoming connections on nc -v -l
This patch adds a message on incoming connections when netcat is run with -l and -v. Does this look like a reasonable addition? One thought is that report_connect might not need to err() when getnameinfo fails thoughts? Thanks, Ricky Index: netcat.c === RCS file: /cvs/src/usr.bin/nc/netcat.c,v retrieving revision 1.107 diff -u netcat.c --- netcat.c1 Apr 2012 02:58:57 - 1.107 +++ netcat.c15 Jun 2012 12:39:49 - @@ -106,6 +106,7 @@ intunix_listen(char *); void set_common_sockopts(int); intmap_tos(char *, int *); +void report_connect(const struct sockaddr *, socklen_t); void usage(int); int @@ -364,6 +365,9 @@ if (rv < 0) err(1, "connect"); + if (vflag) + report_connect((struct sockaddr *)&z, len); + readwrite(s); } else { len = sizeof(cliaddr); @@ -371,6 +375,10 @@ &len); if (connfd == -1) err(1, "accept"); + + if (vflag) + report_connect((struct sockaddr *)&cliaddr, len); + readwrite(connfd); close(connfd); } @@ -957,6 +965,27 @@ } return (0); +} + +void +report_connect(const struct sockaddr *sa, socklen_t salen) +{ + char remote_host[NI_MAXHOST]; + char remote_port[NI_MAXSERV]; + int flags = NI_NUMERICSERV; + + if (nflag) + flags |= NI_NUMERICHOST; + + if (getnameinfo(sa, salen, + remote_host, sizeof(remote_host), + remote_port, sizeof(remote_port), + flags) != 0) + err(1, "getnameinfo"); + + fprintf(stderr, + "Connection from %s %s " + "receieved!\n", remote_host, remote_port); } void