For tcp sockets we read back what is the socket/address.  So we know
what is the port that we are listening into.

Looked all callers of the function, and they just create the addr, use
it, and drop it, so no problem that we always update the port in the
address.

Signed-off-by: Juan Quintela <quint...@redhat.com>
CC: Daniel P. Berrange <berra...@redhat.com>
---
 util/qemu-sockets.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index b47fb45885..b099c88dd1 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -322,13 +322,16 @@ listen_failed:
 
 listen_ok:
     if (update_addr) {
+        SocketAddress *addr;
+
+        addr = socket_local_address(slisten, errp);
         g_free(saddr->host);
-        saddr->host = g_strdup(uaddr);
+        saddr->host = g_strdup(addr->u.inet.host);
         g_free(saddr->port);
-        saddr->port = g_strdup_printf("%d",
-                                      inet_getport(e) - port_offset);
+        saddr->port = g_strdup(addr->u.inet.port);
         saddr->has_ipv6 = saddr->ipv6 = e->ai_family == PF_INET6;
         saddr->has_ipv4 = saddr->ipv4 = e->ai_family != PF_INET6;
+        qapi_free_SocketAddress(addr);
     }
     freeaddrinfo(res);
     return slisten;
@@ -1047,7 +1050,7 @@ int socket_listen(SocketAddress *addr, Error **errp)
 
     switch (addr->type) {
     case SOCKET_ADDRESS_TYPE_INET:
-        fd = inet_listen_saddr(&addr->u.inet, 0, false, errp);
+        fd = inet_listen_saddr(&addr->u.inet, 0, true, errp);
         break;
 
     case SOCKET_ADDRESS_TYPE_UNIX:
-- 
2.13.6


Reply via email to