diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 78fb9cbffd..f56e623cb3 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -56,8 +56,10 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, for (i = 0; i < 50; i++) { int only = 1; - if ((s4 = socket(AF_INET, SOCK_STREAM, 0)) < 0) - goto cleanup; + if (*hasIPv4) { + if ((s4 = socket(AF_INET, SOCK_STREAM, 0)) < 0) + goto cleanup; + } if (*hasIPv6) { if ((s6 = socket(AF_INET6, SOCK_STREAM, 0)) < 0) @@ -77,13 +79,15 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, in6.sin6_port = htons(BASE_PORT + i); in6.sin6_addr = in6addr_loopback; - if (bind(s4, (struct sockaddr *)&in4, sizeof(in4)) < 0) { - if (errno == EADDRINUSE) { - VIR_FORCE_CLOSE(s4); - VIR_FORCE_CLOSE(s6); - continue; + if (*hasIPv4) { + if (bind(s4, (struct sockaddr *)&in4, sizeof(in4)) < 0) { + if (errno == EADDRINUSE) { + VIR_FORCE_CLOSE(s4); + VIR_FORCE_CLOSE(s6); + continue; + } + goto cleanup; } - goto cleanup; } if (*hasIPv6) {