[libvirt PATCH 1/2] tests: Don't assume IPv4 connectivity is available

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 tests/virnetsockettest.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

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) {
-- 
2.25.4




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux