File virtview-git-ipv6-check.patch of Package virt-viewer

Subject: Fix check for IPv6 any address
From: Daniel P. Berrange berrange@redhat.com Tue Oct 9 17:52:23 2012 +0100
Date: Wed Oct 10 16:28:38 2012 +0100:
Git: c4bfbe104f507236e2f98d6d4aa5966b0b6857bc

The string '::' is just one of many possible ways to express
the IPv6 "any" address. Others include  '::0', '0:0:0:0:0:0:0:0',
'0::0' and more. Instead of trying to do strcmp, actually try
parsing the address with GInetAddress and then simply use an
accessor to check what type it is

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>

Index: virt-viewer-0.5.4/src/virt-viewer.c
===================================================================
--- virt-viewer-0.5.4.orig/src/virt-viewer.c
+++ virt-viewer-0.5.4/src/virt-viewer.c
@@ -282,6 +282,27 @@ virt_viewer_extract_xpath_string(const g
     return port;
 }
 
+
+static gboolean
+virt_viewer_replace_host(const gchar *host)
+{
+    GInetAddress *addr;
+    gboolean ret;
+
+    if (!host)
+        return TRUE;
+
+    addr = g_inet_address_new_from_string(host);
+
+    if (!addr) /* Parsing error means it was probably a hostname */
+        return FALSE;
+
+    ret = g_inet_address_get_is_any(addr);
+    g_object_unref(addr);
+
+    return ret;
+}
+
 static gboolean
 virt_viewer_extract_connect_info(VirtViewer *self,
                                  virDomainPtr dom)
@@ -351,9 +372,7 @@ virt_viewer_extract_connect_info(VirtVie
      * from a remote host. Instead we fallback to the hostname used in
      * the libvirt URI. This isn't perfect but it is better than nothing
      */
-    if (!ghost ||
-        (strcmp(ghost, "0.0.0.0") == 0 ||
-         strcmp(ghost, "::") == 0)) {
+    if (virt_viewer_replace_host(ghost)) {
         DEBUG_LOG("Guest graphics listen '%s' is NULL or a wildcard, replacing with '%s'",
                   ghost ? ghost : "", host);
         g_free(ghost);
openSUSE Build Service is sponsored by