[PATCH v4] iphlpapi: Add support for ConvertLengthToIpv4Mask()
Huw Davies
huw at codeweavers.com
Tue Mar 20 04:09:33 CDT 2018
On Tue, Mar 20, 2018 at 12:23:51AM +0100, Dagfinn Reiakvam wrote:
> This patch fixes bug:
> https://bugs.winehq.org/show_bug.cgi?id=44742
>
> Signed-off-by: Dagfinn Reiakvam <dagfinn at reiakvam.no>
> ---
> 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 97284ed..604470a 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)
This looks good.
> diff --git a/dlls/iphlpapi/tests/iphlpapi.c b/dlls/iphlpapi/tests/iphlpapi.c
> index 873612d..518366b 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");
> }
> @@ -2174,6 +2176,39 @@ static void test_GetUnicastIpAddressTable(void)
> pFreeMibTable(table);
> }
>
> +static void test_ConvertLengthToIpv4Mask(void)
> +{
I meant to mention this last time, but please indent
this function with 4 spaces per level.
> + DWORD apiReturn;
Let's just call this variable 'ret'. We don't like camelCase in general.
> + DWORD n;
> + ULONG mask;
> + ULONG expected;
> +
> + if (!pConvertLengthToIpv4Mask)
> + {
> + win_skip( "ConvertLengthToIpv4Mask not available\n" );
> + return;
> + }
> +
> + for (n=0; n <= 32; n++)
Space on either side of '=' to match the spaces around '<='. Consistency.
> + {
> + mask = 0xdeadbeef;
> + if (n>0)
Spaces around '>'. Consistency, again.
> + expected = htonl( ~0u << (32 - n) );
> + else
> + expected = 0;
> +
> + apiReturn = pConvertLengthToIpv4Mask( n, &mask );
> + ok( apiReturn == NO_ERROR, "ConvertLengthToIpv4Mask returned 0x%08x, expected 0x%08x\n", apiReturn, 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;
> + apiReturn = pConvertLengthToIpv4Mask( 33, &mask );
> + ok( apiReturn == ERROR_INVALID_PARAMETER, "ConvertLengthToIpv4Mask returned 0x%08x, expected 0x%08x\n", apiReturn, ERROR_INVALID_PARAMETER );
^
Remove one of the double spaces.
> + ok( mask == INADDR_NONE, "ConvertLengthToIpv4Mask mask value 0x%.8x, expected 0x%08x\n", mask, INADDR_NONE );
First format here wants to be 0x%08x to be consistent with the others.
Huw.
More information about the wine-devel
mailing list