https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c356901f0d69b83107740bc0965960154b35e251

commit c356901f0d69b83107740bc0965960154b35e251
Author: Corinna Vinschen <[email protected]>
Date:   Tue Dec 15 15:50:13 2015 +0100

    Rename if_indextoname to cygwin_if_indextoname (analag for if_nametoindex)
    
    Just call OS functions

Diff:
---
 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 d8e6e79..d9bf96b 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 2ae3c81..d8df00e 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 97885b1..7834aae 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 *

Reply via email to