Bob Beck <[email protected]> writes:

>> Hi tech@,
>> 
>> I just ran into this while fiddling with some netcat-based plumbing.
>> When I connect to the specified socket from another shell, the
>> listening nc dies if it is AF_UNIX:
>> 
>>     $ tail -10f /var/log/messages | nc -vkU -l ~/.xlog_socket
>>     nc: getnameinfo: Invalid argument
>> 
>> The attached patch fixes the issue:
>> 
>>     $ tail -10f /var/log/messages | \
>>         /usr/obj/usr.bin/nc/nc -vkU -l ~/.xlog_socket
>>     Connection on /home/attila/.xlog_socket received!
>> 
>> Feedback, comments most welcome.
>> 
>> Pax, -A
>
> How's this instead for you.. (Inspired by your diff.. thanks)
>

Preferable to my patch.  Thanks for looking at it!

Also: I noticed there are no regression tests for netcat, so I'm
writing one at least to test this case.  Any requests or thoughts on
others?  I have a couple obvious ideas, input most welcome.

> Index: netcat.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/nc/netcat.c,v
> retrieving revision 1.150
> diff -u -p -u -p -r1.150 netcat.c
> --- netcat.c  4 Jan 2016 02:18:31 -0000       1.150
> +++ netcat.c  28 May 2016 17:32:01 -0000
> @@ -133,7 +133,7 @@ int       unix_listen(char *);
>  void set_common_sockopts(int, int);
>  int  map_tos(char *, int *);
>  int  map_tls(char *, int *);
> -void report_connect(const struct sockaddr *, socklen_t);
> +void report_connect(const struct sockaddr *, socklen_t, char *);
>  void report_tls(struct tls *tls_ctx, char * host, char *tls_expectname);
>  void usage(int);
>  ssize_t drainbuf(int, unsigned char *, size_t *, struct tls *);
> @@ -516,7 +516,7 @@ main(int argc, char *argv[])
>                                       err(1, "connect");
>  
>                               if (vflag)
> -                                     report_connect((struct sockaddr *)&z, 
> len);
> +                                     report_connect((struct sockaddr *)&z, 
> len, NULL);
>  
>                               readwrite(s, NULL);
>                       } else {
> @@ -528,7 +528,8 @@ main(int argc, char *argv[])
>                                       err(1, "accept");
>                               }
>                               if (vflag)
> -                                     report_connect((struct sockaddr 
> *)&cliaddr, len);
> +                                     report_connect((struct sockaddr 
> *)&cliaddr, len,
> +                                         family == AF_UNIX ? host : NULL);
>                               if ((usetls) &&
>                                   (tls_cctx = tls_setup_server(tls_ctx, 
> connfd, host)))
>                                       readwrite(connfd, tls_cctx);
> @@ -1487,12 +1488,17 @@ report_tls(struct tls * tls_ctx, char * 
>  }
>  
>  void
> -report_connect(const struct sockaddr *sa, socklen_t salen)
> +report_connect(const struct sockaddr *sa, socklen_t salen, char *path)
>  {
>       char remote_host[NI_MAXHOST];
>       char remote_port[NI_MAXSERV];
>       int herr;
>       int flags = NI_NUMERICSERV;
> +
> +     if (path != NULL) {
> +             fprintf(stderr, "Connection on %s received!\n", path);
> +             return;
> +     }
>  
>       if (nflag)
>               flags |= NI_NUMERICHOST;

Pax, -A
--
http://haqistan.net/~attila | [email protected] | 0x62A729CF

Reply via email to