diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 70501713d..775c710a1 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2008-06-10 Corinna Vinschen + + * 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 * fhandler_procnet.cc (format_procnet_ifinet6): Use sprintf rather than diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index d8d426b98..c18a775de 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -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: ;