OSDN Git Service

* net.cc (if_nametoindex): Fix typo in call to get_adapters_addresses.
authorcorinna <corinna>
Tue, 10 Jun 2008 18:15:56 +0000 (18:15 +0000)
committercorinna <corinna>
Tue, 10 Jun 2008 18:15:56 +0000 (18:15 +0000)
(if_indextoname): Prefer IPv6 loopback device name over IPv4 loopback
device name on pre-Vista systems.
(if_nameindex): Ditto.

winsup/cygwin/ChangeLog
winsup/cygwin/net.cc

index 7050171..775c710 100644 (file)
@@ -1,5 +1,12 @@
 2008-06-10  Corinna Vinschen  <corinna@vinschen.de>
 
+       * net.cc (if_nametoindex): Fix typo in call to get_adapters_addresses.
+       (if_indextoname): Prefer IPv6 loopback device name over IPv4 loopback
+       device name on pre-Vista systems.
+       (if_nameindex): Ditto.
+
+2008-06-10  Corinna Vinschen  <corinna@vinschen.de>
+
        * fhandler_procnet.cc (format_procnet_ifinet6): Use sprintf rather than
        __small_sprintf.
        * net.cc (if_nametoindex): Prefer IPv6IfIndex over IfIndex for
index d8d426b..c18a775 100644 (file)
@@ -2037,7 +2037,7 @@ if_nametoindex (const char *name)
     return 0;
 
   if (wincap.has_gaa_prefixes ()
-      && get_adapters_addresses (&pap, AF_UNSPEC))
+      && get_adapters_addresses (&pa0, AF_UNSPEC))
     {
       char lname[IF_NAMESIZE], *c;
 
@@ -2072,6 +2072,19 @@ if_indextoname (unsigned ifindex, char *ifname)
       for (pap = pa0; pap; pap = pap->Next)
        if (ifindex == (pap->Ipv6IfIndex ?: pap->IfIndex))
          {
+           /* Unfortunately the pre-Vista IPv6 stack has a distinct loopback
+              device with the same Ipv6IfIndex as the IfIndex of the IPv4
+              loopback device, but with a different adapter name.
+              For consistency with /proc/net/if_inet6, try to find the
+              IPv6 loopback device and use that adapter name instead.
+              We identify the loopback device by its IfIndex of 1. */
+           if (pap->IfIndex == 1 && pap->Ipv6IfIndex == 0)
+             for (PIP_ADAPTER_ADDRESSES pap2 = pa0; pap2; pap2 = pap2->Next)
+               if (pap2->Ipv6IfIndex == 1)
+                 {
+                   pap = pap2;
+                   break;
+                 }
            name = strcpy (ifname, pap->AdapterName);
            break;
          }
@@ -2114,6 +2127,14 @@ if_nameindex (void)
                  goto outer_loop;
              iflist[cnt].if_index = pap->Ipv6IfIndex ?: pap->IfIndex;
              strcpy (iflist[cnt].if_name = ifnamelist[cnt], pap->AdapterName);
+             /* See comment in if_indextoname. */
+             if (pap->IfIndex == 1 && pap->Ipv6IfIndex == 0)
+               for (PIP_ADAPTER_ADDRESSES pap2 = pa0; pap2; pap2 = pap2->Next)
+                 if (pap2->Ipv6IfIndex == 1)
+                   {
+                     strcpy (ifnamelist[cnt], pap2->AdapterName);
+                     break;
+                   }
              ++cnt;
            outer_loop:
              ;