Use virSocketAddrIsWildcard instead of STREQ to check for the ANY
address and put brackets around the address if it contains ':'.
---
 tools/virsh-domain.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index fa012d1..42c9920 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9043,6 +9043,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
     int flags = 0;
     bool params = false;
     const char *xpath_fmt = "string(/domain/devices/graphics[@type='%s']/@%s)";
+    virSocketAddr addr;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return false;
@@ -9126,8 +9127,12 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
             virBufferAsprintf(&buf, ":%s@", passwd);
 
         /* Then host name or IP */
-        if (!listen_addr || STREQ((const char *)listen_addr, "0.0.0.0"))
+        if (!listen_addr ||
+            (virSocketAddrParse(&addr, listen_addr, AF_UNSPEC) > 0 &&
+             virSocketAddrIsWildcard(&addr)))
             virBufferAddLit(&buf, "localhost");
+        else if (strchr(listen_addr, ':'))
+            virBufferAsprintf(&buf, "[%s]", listen_addr);
         else
             virBufferAsprintf(&buf, "%s", listen_addr);
 
-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to