From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id C48423857C7D; Sat, 3 Feb 2024 14:51:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C48423857C7D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1706971866; bh=nUZDNsEXAKKrOQD5ERJG5i10QyR6438LFPMjCfPwjuw=; h=From:To:Subject:Date:From; b=l0KwGaecWdn8KeKZNqiWhxFe7Yaw8Om2Ud0Lhv9UhLc3l28TH6dGgHuEejCBs4IUY dygdeB//WDF7MH4lhWwo2iKKChcV+v6MGU0O2uwStEE1JadE+iiSkGwo2zm0KEG+Pr kMvLfXADZmZR12v87R0Kruq5FWqLaYGfs8LJl0Y8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_5-branch] Cygwin: net: Make if_nametoindex, etc. consistent with if_nameindex. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_5-branch X-Git-Oldrev: aa22a43ec0408e6989ae539976f620c26a333a83 X-Git-Newrev: aa392df06bb3eb42e07dd68bda2443614ba6a051 Message-Id: <20240203145106.C48423857C7D@sourceware.org> Date: Sat, 3 Feb 2024 14:51:06 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Daa392df06bb= 3eb42e07dd68bda2443614ba6a051 commit aa392df06bb3eb42e07dd68bda2443614ba6a051 Author: Takashi Yano Date: Sat Feb 3 12:45:29 2024 +0900 Cygwin: net: Make if_nametoindex, etc. consistent with if_nameindex. =20 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. =20 Fixes: c356901f0d69 ("Rename if_indextoname to cygwin_if_indextoname (a= nalag for if_nametoindex)") Reviewed-by: Corinna Vinschen Signed-off-by: Takashi Yano Diff: --- winsup/cygwin/autoload.cc | 2 -- winsup/cygwin/net.cc | 31 +++++++++++++++++++++++++++++-- winsup/cygwin/release/3.5.1 | 3 +++ 3 files changed, 32 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) =20 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 =3D NULL, pap; + if (get_adapters_addresses (&pa0, AF_UNSPEC)) + for (pap =3D pa0; pap; pap =3D pap->Next) + if (strcmp (name, pap->AdapterName) =3D=3D 0) + { + free (pa0); + return pap->IfIndex; + } + if (pa0) + free (pa0); + return 0; } =20 extern "C" char * cygwin_if_indextoname (unsigned ifindex, char *ifname) { - return ::if_indextoname (ifindex, ifname); + if (ifindex =3D=3D 0 || ifname =3D=3D NULL) + { + set_errno (ENXIO); + return NULL; + } + PIP_ADAPTER_ADDRESSES pa0 =3D NULL, pap; + if (get_adapters_addresses (&pa0, AF_UNSPEC)) + for (pap =3D pa0; pap; pap =3D pap->Next) + if (ifindex =3D=3D pap->IfIndex) + { + strcpy (ifname, pap->AdapterName); + free (pa0); + return ifname; + } + if (pa0) + free (pa0); + set_errno (ENXIO); + return NULL; } =20 extern "C" struct if_nameindex * diff --git a/winsup/cygwin/release/3.5.1 b/winsup/cygwin/release/3.5.1 index 054988b90..7776d120f 100644 --- a/winsup/cygwin/release/3.5.1 +++ b/winsup/cygwin/release/3.5.1 @@ -3,3 +3,6 @@ Bug Fixes =20 - 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().