aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2024-02-03 12:45:29 +0900
committerTakashi Yano <takashi.yano@nifty.ne.jp>2024-02-03 23:47:44 +0900
commitb91d38db37d8088901e47d73a65dadac51e227fb (patch)
tree32c774286e4aa618b09356241a64d32c4d9821b4 /winsup/cygwin
parentad75a40cd80bf266dfa5201497c53b7060f7b86d (diff)
downloadnewlib-b91d38db37d8088901e47d73a65dadac51e227fb.zip
newlib-b91d38db37d8088901e47d73a65dadac51e227fb.tar.gz
newlib-b91d38db37d8088901e47d73a65dadac51e227fb.tar.bz2
Cygwin: net: Make if_nametoindex, etc. consistent with if_nameindex.
Currently, if_nametoindex() and if_indextoname() handle interface names such as "ethernet_32777", while if_nameindex() returns the names such as "{5AF7ACD0-D52E-4DFC-A4D0-54D3E6D6B2AC}". This patch unifies the interface names to the latter. Fixes: c356901f0d69 ("Rename if_indextoname to cygwin_if_indextoname (analag for if_nametoindex)") Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/autoload.cc2
-rw-r--r--winsup/cygwin/net.cc31
-rw-r--r--winsup/cygwin/release/3.5.13
3 files changed, 32 insertions, 4 deletions
diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index c1a124c..7e610bd 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -462,8 +462,6 @@ LoadDLLfunc (GetNetworkParams, iphlpapi)
LoadDLLfunc (GetTcpTable, iphlpapi)
LoadDLLfunc (GetTcp6Table, iphlpapi)
LoadDLLfunc (GetUdpTable, iphlpapi)
-LoadDLLfunc (if_indextoname, iphlpapi)
-LoadDLLfunc (if_nametoindex, iphlpapi)
LoadDLLfuncEx2 (DiscardVirtualMemory, kernel32, 1, 127)
LoadDLLfuncEx (ClosePseudoConsole, kernel32, 1)
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 8840d5e..08c584f 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -2001,13 +2001,40 @@ get_ifconf (struct ifconf *ifc, int what)
extern "C" unsigned
cygwin_if_nametoindex (const char *name)
{
- return (unsigned) ::if_nametoindex (name);
+ PIP_ADAPTER_ADDRESSES pa0 = NULL, pap;
+ if (get_adapters_addresses (&pa0, AF_UNSPEC))
+ for (pap = pa0; pap; pap = pap->Next)
+ if (strcmp (name, pap->AdapterName) == 0)
+ {
+ free (pa0);
+ return pap->IfIndex;
+ }
+ if (pa0)
+ free (pa0);
+ return 0;
}
extern "C" char *
cygwin_if_indextoname (unsigned ifindex, char *ifname)
{
- return ::if_indextoname (ifindex, ifname);
+ if (ifindex == 0 || ifname == NULL)
+ {
+ set_errno (ENXIO);
+ return NULL;
+ }
+ PIP_ADAPTER_ADDRESSES pa0 = NULL, pap;
+ if (get_adapters_addresses (&pa0, AF_UNSPEC))
+ for (pap = pa0; pap; pap = pap->Next)
+ if (ifindex == pap->IfIndex)
+ {
+ strcpy (ifname, pap->AdapterName);
+ free (pa0);
+ return ifname;
+ }
+ if (pa0)
+ free (pa0);
+ set_errno (ENXIO);
+ return NULL;
}
extern "C" struct if_nameindex *
diff --git a/winsup/cygwin/release/3.5.1 b/winsup/cygwin/release/3.5.1
index 054988b..7776d12 100644
--- a/winsup/cygwin/release/3.5.1
+++ b/winsup/cygwin/release/3.5.1
@@ -3,3 +3,6 @@ Bug Fixes
- Fix exit code for non-cygwin process running in console. The bug
was introduced in 3.5.0.
+
+- Make the interface names handled by if_nametoindex() and if_indextoname()
+ consistent with that of if_nameindex().