Module: wine Branch: stable Commit: 45697383c8e7543d24b77f11820e005883b0cf0c URL: http://source.winehq.org/git/wine.git/?a=commit;h=45697383c8e7543d24b77f1182...
Author: Stefan Dösinger stefan@codeweavers.com Date: Wed May 24 19:09:53 2017 +0200
iphlpapi: Implement if_nametoindex.
Signed-off-by: Stefan Dösinger stefan@codeweavers.com Signed-off-by: Bruno Jesus bjesus@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org (cherry picked from commit a1026df4031292eeb8b33b2c0ca970560dc8b038) Signed-off-by: Michael Stefaniuc mstefani@winehq.org
---
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 314ca17..7e16895 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 b5b1f7b..951e11e 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -3104,3 +3104,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 6991a39..5467d3f 100644 --- a/dlls/iphlpapi/tests/iphlpapi.c +++ b/dlls/iphlpapi/tests/iphlpapi.c @@ -94,6 +94,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"); @@ -140,6 +142,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"); } }
@@ -1742,7 +1745,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) { @@ -1901,6 +1904,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)