[libvirt] [PATCH] tests: Improve IPv6 detection for virNetSocket tests

getifaddrs can return an IPv6 address, but getaddrinfo can fail for an IPv6 address. Cover this combination. --- This is only tested on my system with broken IPv6. Could someone test this on an IPv6 capable system and ensure that the IPv6 tests aren't skipped now by running cd tests make virnetsockettest PATH=`pwd`:$PATH LIBVIRT_DEBUG=1 ./virnetsockettest This should print something like this 17:35:09.810: 4102: debug : checkProtocols:83 : Protocols: v4 1 v6 1 on an IPv6 capable system. tests/virnetsockettest.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index f686a15..f6c7274 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -45,12 +45,16 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, int *freePort) { struct ifaddrs *ifaddr = NULL, *ifa; + struct addrinfo hints; + struct addrinfo *ai = NULL; struct sockaddr_in in4; struct sockaddr_in6 in6; int s4 = -1, s6 = -1; int i; int ret = -1; + memset(&hints, 0, sizeof hints); + *hasIPv4 = *hasIPv6 = false; *freePort = 0; @@ -67,6 +71,15 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, *hasIPv6 = true; } + hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; + hints.ai_family = AF_INET6; + hints.ai_socktype = SOCK_STREAM; + + if (getaddrinfo("::1", "5672", &hints, &ai) != 0) + *hasIPv6 = false; + + freeaddrinfo(ai); + VIR_DEBUG("Protocols: v4 %d v6 %d\n", *hasIPv4, *hasIPv6); freeifaddrs(ifaddr); -- 1.7.0.4

On 06/24/2011 09:39 AM, Matthias Bolte wrote:
getifaddrs can return an IPv6 address, but getaddrinfo can fail for an IPv6 address. Cover this combination. ---
This is only tested on my system with broken IPv6. Could someone test this on an IPv6 capable system and ensure that the IPv6 tests aren't skipped now by running
cd tests make virnetsockettest PATH=`pwd`:$PATH LIBVIRT_DEBUG=1 ./virnetsockettest
This should print something like this
17:35:09.810: 4102: debug : checkProtocols:83 : Protocols: v4 1 v6 1
on an IPv6 capable system.
Done, and worked for me. ACK to the patch. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

2011/6/24 Eric Blake <eblake@redhat.com>:
On 06/24/2011 09:39 AM, Matthias Bolte wrote:
getifaddrs can return an IPv6 address, but getaddrinfo can fail for an IPv6 address. Cover this combination. ---
This is only tested on my system with broken IPv6. Could someone test this on an IPv6 capable system and ensure that the IPv6 tests aren't skipped now by running
cd tests make virnetsockettest PATH=`pwd`:$PATH LIBVIRT_DEBUG=1 ./virnetsockettest
This should print something like this
17:35:09.810: 4102: debug : checkProtocols:83 : Protocols: v4 1 v6 1
on an IPv6 capable system.
Done, and worked for me.
ACK to the patch.
Thanks, pushed. -- Matthias Bolte http://photron.blogspot.com
participants (2)
-
Eric Blake
-
Matthias Bolte