If only IPv6 is configured and nscd is started, getaddrinfo
function reture value is -9. So hints.ai_flags should include
the AI_V4MAPPED flag.

The following is the partial implementation of getaddrinfo(glibc):

    if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
        at->family = AF_INET;
    else if (req->ai_family == AF_INET6 && (req->ai_flags & AI_V4MAPPED))
    {
        at->addr[3] = at->addr[0];
        at->addr[2] = htonl (0xffff);
        at->addr[1] = 0;
        at->addr[0] = 0;
        at->family = AF_INET6;
    }
    else
    {
         result = -EAI_ADDRFAMILY;
         goto free_and_return;
    }

Signed-off-by: Zhimin Feng <fengzhim...@huawei.com>
---
 src/rpc/virnetsocket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index a217404fa6..c547acefc0 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -575,7 +575,7 @@ int virNetSocketNewConnectTCP(const char *nodename,
 
     memset(&hints, 0, sizeof(hints));
     hints.ai_family = family;
-    hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+    hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_V4MAPPED;
     hints.ai_socktype = SOCK_STREAM;
 
     int e = getaddrinfo(nodename, service, &hints, &ai);
-- 
2.19.1



Reply via email to