diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2008-06-10 18:15:57 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2008-06-10 18:15:57 +0000 |
commit | bbfcc68ad284e0ae779559e8836f513ad78b4204 (patch) | |
tree | dd1f85f4c4d32a074e7c03e91a7372b9d24b4ecc /winsup/cygwin/net.cc | |
parent | 7a2c0a0d6bec344172130ecdcfb3b40bbcca4873 (diff) | |
download | newlib-bbfcc68ad284e0ae779559e8836f513ad78b4204.zip newlib-bbfcc68ad284e0ae779559e8836f513ad78b4204.tar.gz newlib-bbfcc68ad284e0ae779559e8836f513ad78b4204.tar.bz2 |
* 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.
Diffstat (limited to 'winsup/cygwin/net.cc')
-rw-r--r-- | winsup/cygwin/net.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index d8d426b..c18a775 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: ; |