mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
tests: Don't assume IPv4 connectivity is available
If the host doesn't have a single IPv4 address assigned to any of its interfaces, not even the loopback one, then virnetsockettest will fail with Cannot identify IPv4/6 availability because, while the IPv6 bind attempt is conditional, the IPv4 one is not, and in this case it will always fail. This commit is better viewed with 'git show -w'. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
2b23d194d2
commit
efe6429910
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user