[PATCH] esx: Allow connecting to IPv6 server

Michal Privoznik via Devel posted 1 patch 1 week, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/5f81f97ca153fa345335454c3de7632f91ace155.1768900347.git.mprivozn@redhat.com
src/esx/esx_util.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] esx: Allow connecting to IPv6 server
Posted by Michal Privoznik via Devel 1 week, 5 days ago
From: Michal Privoznik <mprivozn@redhat.com>

When connecting to a VMWare server, the hostname from URI is
resolved using esxUtil_ResolveHostname() which in turn calls
getaddrinfo(). But in the hints argument, we restrict the return
address to be IPv4 (AF_INET) which obviously fails if the address
to resolve is an IPv6 address. Set the hint to AF_UNSPEC which
allows both IPv4 and IPv6. While at it, also allow IPv4 addresses
mapped in IPv6 by setting AI_V4MAPPED flag.

Resolves: https://issues.redhat.com/browse/RHEL-138300
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/esx/esx_util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index 88b3dc893f..a6275babd5 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -275,8 +275,8 @@ esxUtil_ResolveHostname(const char *hostname, char **ipAddress)
     int errcode;
     g_autofree char *address = NULL;
 
-    hints.ai_flags = AI_ADDRCONFIG;
-    hints.ai_family = AF_INET;
+    hints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED;
+    hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
     hints.ai_protocol = 0;
 
-- 
2.52.0
Re: [PATCH] esx: Allow connecting to IPv6 server
Posted by Richard W.M. Jones via Devel 1 week, 5 days ago
On Tue, Jan 20, 2026 at 10:12:27AM +0100, Michal Privoznik via Devel wrote:
> From: Michal Privoznik <mprivozn@redhat.com>
> 
> When connecting to a VMWare server, the hostname from URI is
> resolved using esxUtil_ResolveHostname() which in turn calls
> getaddrinfo(). But in the hints argument, we restrict the return
> address to be IPv4 (AF_INET) which obviously fails if the address
> to resolve is an IPv6 address. Set the hint to AF_UNSPEC which
> allows both IPv4 and IPv6. While at it, also allow IPv4 addresses
> mapped in IPv6 by setting AI_V4MAPPED flag.
> 
> Resolves: https://issues.redhat.com/browse/RHEL-138300
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/esx/esx_util.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
> index 88b3dc893f..a6275babd5 100644
> --- a/src/esx/esx_util.c
> +++ b/src/esx/esx_util.c
> @@ -275,8 +275,8 @@ esxUtil_ResolveHostname(const char *hostname, char **ipAddress)
>      int errcode;
>      g_autofree char *address = NULL;
>  
> -    hints.ai_flags = AI_ADDRCONFIG;
> -    hints.ai_family = AF_INET;
> +    hints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED;
> +    hints.ai_family = AF_UNSPEC;
>      hints.ai_socktype = SOCK_STREAM;
>      hints.ai_protocol = 0;

Thanks for looking at this, Michal.

Reviewed-by: Richard W.M. Jones <rjones@redhat.com>

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
Re: [PATCH] esx: Allow connecting to IPv6 server
Posted by Daniel P. Berrangé via Devel 1 week, 5 days ago
On Tue, Jan 20, 2026 at 10:12:27AM +0100, Michal Privoznik via Devel wrote:
> From: Michal Privoznik <mprivozn@redhat.com>
> 
> When connecting to a VMWare server, the hostname from URI is
> resolved using esxUtil_ResolveHostname() which in turn calls
> getaddrinfo(). But in the hints argument, we restrict the return
> address to be IPv4 (AF_INET) which obviously fails if the address
> to resolve is an IPv6 address. Set the hint to AF_UNSPEC which
> allows both IPv4 and IPv6. While at it, also allow IPv4 addresses
> mapped in IPv6 by setting AI_V4MAPPED flag.
> 
> Resolves: https://issues.redhat.com/browse/RHEL-138300
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/esx/esx_util.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

> 
> diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
> index 88b3dc893f..a6275babd5 100644
> --- a/src/esx/esx_util.c
> +++ b/src/esx/esx_util.c
> @@ -275,8 +275,8 @@ esxUtil_ResolveHostname(const char *hostname, char **ipAddress)
>      int errcode;
>      g_autofree char *address = NULL;
>  
> -    hints.ai_flags = AI_ADDRCONFIG;
> -    hints.ai_family = AF_INET;
> +    hints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED;
> +    hints.ai_family = AF_UNSPEC;
>      hints.ai_socktype = SOCK_STREAM;
>      hints.ai_protocol = 0;
>  
> -- 
> 2.52.0
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|