Rename if_indextoname to cygwin_if_indextoname (analag for if_nametoindex)

Just call OS functions
This commit is contained in:
Corinna Vinschen 2015-12-15 15:50:13 +01:00
parent bd4339e2a2
commit c356901f0d
3 changed files with 8 additions and 68 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 *