From c356901f0d69b83107740bc0965960154b35e251 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 15 Dec 2015 15:50:13 +0100 Subject: [PATCH] Rename if_indextoname to cygwin_if_indextoname (analag for if_nametoindex) Just call OS functions --- winsup/cygwin/autoload.cc | 2 ++ winsup/cygwin/common.din | 4 +-- winsup/cygwin/net.cc | 70 +++------------------------------------ 3 files changed, 8 insertions(+), 68 deletions(-) diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index d8e6e794c..d9bf96b7d 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -574,6 +574,8 @@ LoadDLLfunc (GetIpAddrTable, 12, iphlpapi) LoadDLLfunc (GetIpForwardTable, 12, iphlpapi) LoadDLLfunc (GetNetworkParams, 8, iphlpapi) LoadDLLfunc (GetUdpTable, 12, iphlpapi) +LoadDLLfunc (if_indextoname, 8, iphlpapi) +LoadDLLfunc (if_nametoindex, 4, iphlpapi) LoadDLLfuncEx (CancelSynchronousIo, 4, kernel32, 1) LoadDLLfunc (CreateSymbolicLinkW, 12, kernel32) diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din index 2ae3c81d3..d8df00e3d 100644 --- a/winsup/cygwin/common.din +++ b/winsup/cygwin/common.din @@ -692,9 +692,9 @@ hypot NOSIGFE hypotf NOSIGFE hypotl NOSIGFE if_freenameindex SIGFE -if_indextoname SIGFE +if_indextoname = cygwin_if_indextoname SIGFE if_nameindex SIGFE -if_nametoindex SIGFE +if_nametoindex = cygwin_if_nametoindex SIGFE ilogb NOSIGFE ilogbf NOSIGFE ilogbl NOSIGFE diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 97885b13c..7834aae9d 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -2380,77 +2380,15 @@ get_ifconf (struct ifconf *ifc, int what) } extern "C" unsigned -if_nametoindex (const char *name) +cygwin_if_nametoindex (const char *name) { - PIP_ADAPTER_ADDRESSES pa0 = NULL, pap; - unsigned index = 0; - - __try - { - if (get_adapters_addresses (&pa0, AF_UNSPEC)) - { - char lname[IF_NAMESIZE], *c; - - lname[0] = '\0'; - strncat (lname, name, IF_NAMESIZE - 1); - if (lname[0] == '{' && (c = strchr (lname, ':'))) - *c = '\0'; - for (pap = pa0; pap; pap = pap->Next) - if (strcasematch (lname, pap->AdapterName)) - { - index = pap->Ipv6IfIndex ?: pap->IfIndex; - break; - } - free (pa0); - } - } - __except (EFAULT) - { - index = 0; - } - __endtry - return index; + return (unsigned) ::if_nametoindex (name); } extern "C" char * -if_indextoname (unsigned ifindex, char *ifname) +cygwin_if_indextoname (unsigned ifindex, char *ifname) { - PIP_ADAPTER_ADDRESSES pa0 = NULL, pap; - char *name = NULL; - - __try - { - if (get_adapters_addresses (&pa0, AF_UNSPEC)) - { - 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; - } - free (pa0); - } - else - set_errno (ENXIO); - } - __except (EFAULT) {} - __endtry - return name; + return ::if_indextoname (ifindex, ifname); } extern "C" struct if_nameindex *