Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
---
net/stream.c | 108 +++++++++++++++++++++++++++++++++++++++++++++---
qapi/net.json | 2 +-
qemu-options.hx | 1 +
3 files changed, 105 insertions(+), 6 deletions(-)
diff --git a/net/stream.c b/net/stream.c
index e8afbaca50b6..0f91ff20df61 100644
--- a/net/stream.c
+++ b/net/stream.c
@@ -235,7 +235,7 @@ static NetStreamState
*net_stream_fd_init_stream(NetClientState *peer,
static void net_stream_accept(void *opaque)
{
NetStreamState *s = opaque;
- struct sockaddr_in saddr;
+ struct sockaddr_storage saddr;
socklen_t len;
int fd;
@@ -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));
+ break;
+ }
+ case AF_UNIX: {
+ struct sockaddr_un saddr_un;
+
+ len = sizeof(saddr_un);
+ getsockname(s->listen_fd, (struct sockaddr *)&saddr_un, &len);