From a1026df4031292eeb8b33b2c0ca970560dc8b038 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20D=C3=B6singer?= Date: Wed, 24 May 2017 19:09:53 +0200 Subject: [PATCH] iphlpapi: Implement if_nametoindex. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Dösinger Signed-off-by: Bruno Jesus Signed-off-by: Alexandre Julliard --- dlls/iphlpapi/iphlpapi.spec | 2 +- dlls/iphlpapi/iphlpapi_main.c | 14 ++++++++++++++ dlls/iphlpapi/tests/iphlpapi.c | 23 ++++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/dlls/iphlpapi/iphlpapi.spec b/dlls/iphlpapi/iphlpapi.spec index 4e019266177..4e5970c2772 100644 --- a/dlls/iphlpapi/iphlpapi.spec +++ b/dlls/iphlpapi/iphlpapi.spec @@ -160,7 +160,7 @@ @ stdcall IcmpSendEcho2(ptr ptr ptr ptr long ptr long ptr ptr long long) @ stdcall IcmpSendEcho(ptr long ptr long ptr ptr long long) #@ stub if_indextoname -#@ stub if_nametoindex +@ stdcall if_nametoindex(str) IPHLP_if_nametoindex #@ stub InitializeIpForwardEntry #@ stub InitializeIpInterfaceEntry #@ stub InitializeUnicastIpAddressEntry diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 796950e0f96..c592a902ef6 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -3208,3 +3208,17 @@ DWORD WINAPI ConvertInterfaceNameToLuidW(const WCHAR *name, NET_LUID *luid) luid->Info.IfType = row.dwType; return NO_ERROR; } + +/****************************************************************** + * if_nametoindex (IPHLPAPI.@) + */ +IF_INDEX WINAPI IPHLP_if_nametoindex(const char *name) +{ + IF_INDEX idx; + + TRACE("(%s)\n", name); + if (getInterfaceIndexByName(name, &idx) == NO_ERROR) + return idx; + + return 0; +} diff --git a/dlls/iphlpapi/tests/iphlpapi.c b/dlls/iphlpapi/tests/iphlpapi.c index 5fb23fbc164..3369f78f55a 100644 --- a/dlls/iphlpapi/tests/iphlpapi.c +++ b/dlls/iphlpapi/tests/iphlpapi.c @@ -96,6 +96,8 @@ static DWORD (WINAPI *pConvertInterfaceLuidToNameA)(const NET_LUID*,char*,SIZE_T static DWORD (WINAPI *pConvertInterfaceNameToLuidA)(const char*,NET_LUID*); static DWORD (WINAPI *pConvertInterfaceNameToLuidW)(const WCHAR*,NET_LUID*); +static NET_IFINDEX (WINAPI *pif_nametoindex)(const char*); + static void loadIPHlpApi(void) { hLibrary = LoadLibraryA("iphlpapi.dll"); @@ -144,6 +146,7 @@ static void loadIPHlpApi(void) pConvertInterfaceLuidToNameW = (void *)GetProcAddress(hLibrary, "ConvertInterfaceLuidToNameW"); pConvertInterfaceNameToLuidA = (void *)GetProcAddress(hLibrary, "ConvertInterfaceNameToLuidA"); pConvertInterfaceNameToLuidW = (void *)GetProcAddress(hLibrary, "ConvertInterfaceNameToLuidW"); + pif_nametoindex = (void *)GetProcAddress(hLibrary, "if_nametoindex"); } } @@ -1792,7 +1795,7 @@ static void test_interface_identifier_conversion(void) SIZE_T len; WCHAR nameW[IF_MAX_STRING_SIZE + 1]; char nameA[IF_MAX_STRING_SIZE + 1]; - NET_IFINDEX index; + NET_IFINDEX index, index2; if (!pConvertInterfaceIndexToLuid) { @@ -1951,6 +1954,24 @@ static void test_interface_identifier_conversion(void) ok( !luid.Info.Reserved, "got %x\n", luid.Info.Reserved ); ok( luid.Info.NetLuidIndex != 0xdead, "index not set\n" ); ok( luid.Info.IfType == IF_TYPE_ETHERNET_CSMACD, "got %u\n", luid.Info.IfType ); + + /* if_nametoindex */ + if (pif_nametoindex) + { + index2 = pif_nametoindex( NULL ); + ok( !index2, "Got unexpected index %u\n", index2 ); + index2 = pif_nametoindex( nameA ); + ok( index2 == index, "Got index %u for %s, expected %u\n", index2, nameA, index ); + /* Wargaming.net Game Center passes a GUID-like string. */ + index2 = pif_nametoindex( "{00000001-0000-0000-0000-000000000000}" ); + ok( !index2, "Got unexpected index %u\n", index2 ); + index2 = pif_nametoindex( wine_dbgstr_guid( &guid ) ); + ok( !index2, "Got unexpected index %u for input %s\n", index2, wine_dbgstr_guid( &guid ) ); + } + else + { + skip("if_nametoindex not supported\n"); + } } static void test_GetIfEntry2(void) -- 2.11.4.GIT