[virt-tools-list] [PATCH virt-viewer] Fix check for IPv6 any address
Christophe Fergeau
cfergeau at redhat.com
Tue Oct 9 17:10:20 UTC 2012
On Tue, Oct 09, 2012 at 05:53:53PM +0100, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at redhat.com>
>
> 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 at redhat.com>
> ---
> src/virt-viewer.c | 25 ++++++++++++++++++++++---
> 1 file changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/src/virt-viewer.c b/src/virt-viewer.c
> index 0a4cea7..5b6a479 100644
> --- a/src/virt-viewer.c
> +++ b/src/virt-viewer.c
> @@ -282,6 +282,27 @@ virt_viewer_extract_xpath_string(const gchar *xmldesc,
> 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 hotsname */
nit: hostname
ACK
Christophe
> + 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(VirtViewer *self,
> * 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);
> --
> 1.7.11.2
>
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20121009/db82b66f/attachment.sig>
More information about the virt-tools-list
mailing list