[PATCH] Log actual address spice-server binds to

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It's not always obvious what address spice-server will bind to,
in particular when the 'addr' parameter is omitted on QEMU
commandline. The decision of what address to bind to is made
in reds_init_socket with a call to getaddrinfo. Surprisingly,
that function had a call to getnameinfo() already, but it does
not seem to be using the result of that call in any way.
This commit moves this call after the socket is successfully bound
and add a log message to indicate which address it's bound to.
---
 server/reds.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index f6a1ce9..ae02e09 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2994,8 +2994,6 @@ static int reds_init_socket(const char *addr, int portnr, int family)
     static const int on=1, off=0;
     struct addrinfo ai,*res,*e;
     char port[33];
-    char uaddr[INET6_ADDRSTRLEN+1];
-    char uport[33];
     int slisten,rc;
 
     memset(&ai,0, sizeof(ai));
@@ -3012,9 +3010,6 @@ static int reds_init_socket(const char *addr, int portnr, int family)
     }
 
     for (e = res; e != NULL; e = e->ai_next) {
-        getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
-                    uaddr,INET6_ADDRSTRLEN, uport,32,
-                    NI_NUMERICHOST | NI_NUMERICSERV);
         slisten = socket(e->ai_family, e->ai_socktype, e->ai_protocol);
         if (slisten < 0) {
             continue;
@@ -3029,6 +3024,16 @@ static int reds_init_socket(const char *addr, int portnr, int family)
         }
 #endif
         if (bind(slisten, e->ai_addr, e->ai_addrlen) == 0) {
+            char uaddr[INET6_ADDRSTRLEN+1];
+            char uport[33];
+            rc = getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
+                             uaddr,INET6_ADDRSTRLEN, uport,32,
+                             NI_NUMERICHOST | NI_NUMERICSERV);
+            if (rc == 0) {
+                spice_info("bound to %s:%s", uaddr, uport);
+            } else {
+                spice_info("cannot resolve address spice-server is bound to");
+            }
             goto listen;
         }
         close(slisten);
-- 
1.8.2.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]