[glib] gio/tests/network-address: fix for systems with large ifindexes



commit ed2bb953301b47bf34ff9c76b5931285d8434654
Author: Dan Winship <danw gnome org>
Date:   Sat Feb 1 13:37:07 2014 +0100

    gio/tests/network-address: fix for systems with large ifindexes
    
    In some virtualization setups, ifindexes can end up becoming very
    large, and so the existing code that assumes that *some* interface
    must have an index less than 255 fails.
    
    Fix this by explicitly looking for "lo" first. And then if that fails
    (on Windows, or other systems where the loopback interface is not
    called "lo"), try indexes up to 1024 rather than 255.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723048

 gio/tests/network-address.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/gio/tests/network-address.c b/gio/tests/network-address.c
index 05d2866..cfcbd0c 100644
--- a/gio/tests/network-address.c
+++ b/gio/tests/network-address.c
@@ -116,7 +116,7 @@ test_parse_host (gconstpointer d)
 #define SCOPE_ID_TEST_ADDR "fe80::42"
 #define SCOPE_ID_TEST_PORT 99
 
-#ifdef HAVE_IF_INDEXTONAME
+#if defined (HAVE_IF_INDEXTONAME) && defined (HAVE_IF_NAMETOINDEX)
 static char SCOPE_ID_TEST_IFNAME[IF_NAMESIZE];
 static int SCOPE_ID_TEST_INDEX;
 #else
@@ -130,8 +130,15 @@ find_ifname_and_index (void)
   if (SCOPE_ID_TEST_INDEX != 0)
     return;
 
-#ifdef HAVE_IF_INDEXTONAME
-  for (SCOPE_ID_TEST_INDEX = 1; SCOPE_ID_TEST_INDEX < 255; SCOPE_ID_TEST_INDEX++) {
+#if defined (HAVE_IF_INDEXTONAME) && defined (HAVE_IF_NAMETOINDEX)
+  SCOPE_ID_TEST_INDEX = if_nametoindex ("lo");
+  if (SCOPE_ID_TEST_INDEX != 0)
+    {
+      g_strlcpy (SCOPE_ID_TEST_IFNAME, "lo", sizeof (SCOPE_ID_TEST_IFNAME));
+      return;
+    }
+
+  for (SCOPE_ID_TEST_INDEX = 1; SCOPE_ID_TEST_INDEX < 1024; SCOPE_ID_TEST_INDEX++) {
     if (if_indextoname (SCOPE_ID_TEST_INDEX, SCOPE_ID_TEST_IFNAME))
       break;
   }


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