On 9/28/22 08:12, David Gibson wrote:
@@ -253,9 +253,27 @@ static void net_stream_accept(void *opaque) s->fd = fd; s->nc.link_down = false; net_stream_connect(s); - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "connection from %s:%d", - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); + switch (saddr.ss_family) { + case AF_INET: { + struct sockaddr_in *saddr_in = (struct sockaddr_in *)&saddr; + + snprintf(s->nc.info_str, sizeof(s->nc.info_str), + "connection from %s:%d", + inet_ntoa(saddr_in->sin_addr), ntohs(saddr_in->sin_port));So, here you print the address from which the connection has come - the remote address.+ break; + } + case AF_UNIX: { + struct sockaddr_un saddr_un; + + len = sizeof(saddr_un); + getsockname(s->listen_fd, (struct sockaddr *)&saddr_un, &len); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), + "connect from %s", saddr_un.sun_path);Here you print the bound address - the local address. Does that make sense? I mean, in almost every occasion the remote Unix socket will be anonymous, so it probably doesn't make sense to display that, but is the bound address actually a useful substitute? Maybe it should just be "connect from Unix socket".
I agree the needed information is "connected" and type "unix". But I think more information we can put here can be useful for a debugging purpose. Thanks, Laurent
