提交 faffe269 编写于 作者: D Doug Goldstein 提交者: Peter Krempa

Fix test failure when no IPv6 is avail

When the system doesn't have IPv6 available (e.g. not built into the
kernel or the module isn't loaded), you can not create an IPv6 socket.
The test determines earlier on that IPv6 isn't available then goes and
creates a socket. This makes socket creation conditional on IPv6
availability.
上级 f9ce7dad
...@@ -90,11 +90,13 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, ...@@ -90,11 +90,13 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6,
if ((s4 = socket(AF_INET, SOCK_STREAM, 0)) < 0) if ((s4 = socket(AF_INET, SOCK_STREAM, 0)) < 0)
goto cleanup; goto cleanup;
if ((s6 = socket(AF_INET6, SOCK_STREAM, 0)) < 0) if (*hasIPv6) {
goto cleanup; if ((s6 = socket(AF_INET6, SOCK_STREAM, 0)) < 0)
goto cleanup;
if (setsockopt(s6, IPPROTO_IPV6, IPV6_V6ONLY, &only, sizeof(only)) < 0) if (setsockopt(s6, IPPROTO_IPV6, IPV6_V6ONLY, &only, sizeof(only)) < 0)
goto cleanup; goto cleanup;
}
memset(&in4, 0, sizeof(in4)); memset(&in4, 0, sizeof(in4));
memset(&in6, 0, sizeof(in6)); memset(&in6, 0, sizeof(in6));
...@@ -114,13 +116,16 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, ...@@ -114,13 +116,16 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6,
} }
goto cleanup; goto cleanup;
} }
if (bind(s6, (struct sockaddr *)&in6, sizeof(in6)) < 0) {
if (errno == EADDRINUSE) { if (*hasIPv6) {
VIR_FORCE_CLOSE(s4); if (bind(s6, (struct sockaddr *)&in6, sizeof(in6)) < 0) {
VIR_FORCE_CLOSE(s6); if (errno == EADDRINUSE) {
continue; VIR_FORCE_CLOSE(s4);
VIR_FORCE_CLOSE(s6);
continue;
}
goto cleanup;
} }
goto cleanup;
} }
*freePort = BASE_PORT + i; *freePort = BASE_PORT + i;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册