From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Cc: Takashi Yano <takashi.yano@nifty.ne.jp>
Subject: [PATCH] Cygwin: net: Make if_nametoindex, etc. consistent with if_nameindex.
Date: Sat, 3 Feb 2024 18:59:06 +0900 [thread overview]
Message-ID: <20240203095919.1483-1-takashi.yano@nifty.ne.jp> (raw)
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:
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
---
winsup/cygwin/autoload.cc | 2 --
winsup/cygwin/net.cc | 31 +++++++++++++++++++++++++++++--
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index c1a124c1d..7e610bdd0 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 8840d5ead..08c584fe5 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 *
--
2.43.0
reply other threads:[~2024-02-03 9:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240203095919.1483-1-takashi.yano@nifty.ne.jp \
--to=takashi.yano@nifty.ne.jp \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).