[PATCH v4] iphlpapi: Add support for ConvertLengthToIpv4Mask()
Dagfinn Reiakvam
dagfinn at reiakvam.no
Mon Mar 19 18:23:51 CDT 2018
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)
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)
+{
+ DWORD apiReturn;
+ 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;
+
+ 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 );
+ ok( mask == INADDR_NONE, "ConvertLengthToIpv4Mask mask value 0x%.8x, expected 0x%08x\n", mask, INADDR_NONE );
+}
+
START_TEST(iphlpapi)
{
@@ -2201,6 +2236,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**);
--
2.7.4
More information about the wine-devel
mailing list