mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-07-11 12:25:52 +00:00
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 commit is contained in:
parent
0b501bd4e1
commit
d772167f6d
@ -45,12 +45,16 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6,
|
|||||||
int *freePort)
|
int *freePort)
|
||||||
{
|
{
|
||||||
struct ifaddrs *ifaddr = NULL, *ifa;
|
struct ifaddrs *ifaddr = NULL, *ifa;
|
||||||
|
struct addrinfo hints;
|
||||||
|
struct addrinfo *ai = NULL;
|
||||||
struct sockaddr_in in4;
|
struct sockaddr_in in4;
|
||||||
struct sockaddr_in6 in6;
|
struct sockaddr_in6 in6;
|
||||||
int s4 = -1, s6 = -1;
|
int s4 = -1, s6 = -1;
|
||||||
int i;
|
int i;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
memset(&hints, 0, sizeof hints);
|
||||||
|
|
||||||
*hasIPv4 = *hasIPv6 = false;
|
*hasIPv4 = *hasIPv6 = false;
|
||||||
*freePort = 0;
|
*freePort = 0;
|
||||||
|
|
||||||
@ -67,6 +71,15 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6,
|
|||||||
*hasIPv6 = true;
|
*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);
|
VIR_DEBUG("Protocols: v4 %d v6 %d\n", *hasIPv4, *hasIPv6);
|
||||||
|
|
||||||
freeifaddrs(ifaddr);
|
freeifaddrs(ifaddr);
|
||||||
|
Loading…
Reference in New Issue
Block a user