Module: wine Branch: stable Commit: 661acebaf9792982e9dad19470a32ef211d45b9e URL: https://source.winehq.org/git/wine.git/?a=commit;h=661acebaf9792982e9dad1947...
Author: Dagfinn Reiakvam dagfinn@reiakvam.no Date: Tue Mar 20 18:27:04 2018 +0100
iphlpapi: Add support for ConvertLengthToIpv4Mask().
Signed-off-by: Dagfinn Reiakvam dagfinn@reiakvam.no Signed-off-by: Huw Davies huw@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org (cherry picked from commit 1d82495ba154b0f0fd5e2fe493d15290d22d2637) Signed-off-by: Michael Stefaniuc mstefani@winehq.org
---
dlls/iphlpapi/iphlpapi.spec | 2 +- dlls/iphlpapi/iphlpapi_main.c | 19 +++++++++++++++++++ dlls/iphlpapi/tests/iphlpapi.c | 36 ++++++++++++++++++++++++++++++++++++ include/netioapi.h | 1 + 4 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/dlls/iphlpapi/iphlpapi.spec b/dlls/iphlpapi/iphlpapi.spec index b6c9aef..bbd1ed8 100644 --- a/dlls/iphlpapi/iphlpapi.spec +++ b/dlls/iphlpapi/iphlpapi.spec @@ -23,7 +23,7 @@ @ stdcall ConvertInterfaceNameToLuidW( wstr ptr ) #@ stub ConvertInterfacePhysicalAddressToLuid #@ stub ConvertIpv4MaskToLength -#@ stub ConvertLengthToIpv4Mask +@ stdcall ConvertLengthToIpv4Mask( long ptr ) #@ stub ConvertRemoteInterfaceAliasToLuid #@ stub ConvertRemoteInterfaceGuidToLuid #@ stub ConvertRemoteInterfaceIndexToLuid diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 48a8387..266f44c 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -3223,6 +3223,25 @@ DWORD WINAPI ConvertInterfaceNameToLuidW(const WCHAR *name, NET_LUID *luid) }
/****************************************************************** + * ConvertLengthToIpv4Mask (IPHLPAPI.@) + */ +DWORD WINAPI ConvertLengthToIpv4Mask(ULONG mask_len, ULONG *mask) +{ + if (mask_len > 32) + { + *mask = INADDR_NONE; + return ERROR_INVALID_PARAMETER; + } + + if (mask_len == 0) + *mask = 0; + else + *mask = htonl(~0u << (32 - mask_len)); + + return NO_ERROR; +} + +/****************************************************************** * if_nametoindex (IPHLPAPI.@) */ IF_INDEX WINAPI IPHLP_if_nametoindex(const char *name) diff --git a/dlls/iphlpapi/tests/iphlpapi.c b/dlls/iphlpapi/tests/iphlpapi.c index 6397742..2a50d8e 100644 --- a/dlls/iphlpapi/tests/iphlpapi.c +++ b/dlls/iphlpapi/tests/iphlpapi.c @@ -96,6 +96,7 @@ static DWORD (WINAPI *pConvertInterfaceLuidToNameW)(const NET_LUID*,WCHAR*,SIZE_ 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 DWORD (WINAPI *pConvertLengthToIpv4Mask)(ULONG,ULONG*);
static PCHAR (WINAPI *pif_indextoname)(NET_IFINDEX,PCHAR); static NET_IFINDEX (WINAPI *pif_nametoindex)(const char*); @@ -149,6 +150,7 @@ static void loadIPHlpApi(void) pConvertInterfaceLuidToNameW = (void *)GetProcAddress(hLibrary, "ConvertInterfaceLuidToNameW"); pConvertInterfaceNameToLuidA = (void *)GetProcAddress(hLibrary, "ConvertInterfaceNameToLuidA"); pConvertInterfaceNameToLuidW = (void *)GetProcAddress(hLibrary, "ConvertInterfaceNameToLuidW"); + pConvertLengthToIpv4Mask = (void *)GetProcAddress(hLibrary, "ConvertLengthToIpv4Mask"); pif_indextoname = (void *)GetProcAddress(hLibrary, "if_indextoname"); pif_nametoindex = (void *)GetProcAddress(hLibrary, "if_nametoindex"); } @@ -2223,6 +2225,39 @@ static void test_GetUnicastIpAddressTable(void) pFreeMibTable(table); }
+static void test_ConvertLengthToIpv4Mask(void) +{ + DWORD ret; + DWORD n; + ULONG mask; + ULONG expected; + + if (!pConvertLengthToIpv4Mask) + { + win_skip( "ConvertLengthToIpv4Mask not available\n" ); + return; + } + + for (n = 0; n <= 32; n++) + { + mask = 0xdeadbeef; + if (n > 0) + expected = htonl( ~0u << (32 - n) ); + else + expected = 0; + + ret = pConvertLengthToIpv4Mask( n, &mask ); + ok( ret == NO_ERROR, "ConvertLengthToIpv4Mask returned 0x%08x, expected 0x%08x\n", ret, NO_ERROR ); + ok( mask == expected, "ConvertLengthToIpv4Mask mask value 0x%08x, expected 0x%08x\n", mask, expected ); + } + + /* Testing for out of range. In this case both mask and return are changed to indicate error. */ + mask = 0xdeadbeef; + ret = pConvertLengthToIpv4Mask( 33, &mask ); + ok( ret == ERROR_INVALID_PARAMETER, "ConvertLengthToIpv4Mask returned 0x%08x, expected 0x%08x\n", ret, ERROR_INVALID_PARAMETER ); + ok( mask == INADDR_NONE, "ConvertLengthToIpv4Mask mask value 0x%08x, expected 0x%08x\n", mask, INADDR_NONE ); +} + START_TEST(iphlpapi) {
@@ -2250,6 +2285,7 @@ START_TEST(iphlpapi) test_GetIfTable2Ex(); test_GetUnicastIpAddressEntry(); test_GetUnicastIpAddressTable(); + test_ConvertLengthToIpv4Mask(); freeIPHlpApi(); } } diff --git a/include/netioapi.h b/include/netioapi.h index 1095888..4bd64e8 100644 --- a/include/netioapi.h +++ b/include/netioapi.h @@ -170,6 +170,7 @@ DWORD WINAPI ConvertInterfaceLuidToNameA(const NET_LUID*,char*,SIZE_T); DWORD WINAPI ConvertInterfaceLuidToNameW(const NET_LUID*,WCHAR*,SIZE_T); DWORD WINAPI ConvertInterfaceNameToLuidA(const char*,NET_LUID*); DWORD WINAPI ConvertInterfaceNameToLuidW(const WCHAR*,NET_LUID*); +DWORD WINAPI ConvertLengthToIpv4Mask(ULONG,ULONG*); void WINAPI FreeMibTable(void*); DWORD WINAPI GetIfEntry2(MIB_IF_ROW2*); DWORD WINAPI GetIfTable2(MIB_IF_TABLE2**);