[PATCH] IPHLPAPI.DLL: Implement functions ConvertLengthToIpv4Mask and ConvertIpv4MaskToLength

Roger Zoellner zoellner.roger at gmail.com
Mon Mar 19 05:55:38 CDT 2018


---
 dlls/iphlpapi/iphlpapi.spec   |  4 ++--
 dlls/iphlpapi/iphlpapi_main.c | 48 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/dlls/iphlpapi/iphlpapi.spec b/dlls/iphlpapi/iphlpapi.spec
index b6c9aef2f8..167c646de4 100644
--- a/dlls/iphlpapi/iphlpapi.spec
+++ b/dlls/iphlpapi/iphlpapi.spec
@@ -22,8 +22,8 @@
 @ stdcall ConvertInterfaceNameToLuidA( str ptr )
 @ stdcall ConvertInterfaceNameToLuidW( wstr ptr )
 #@ stub ConvertInterfacePhysicalAddressToLuid
-#@ stub ConvertIpv4MaskToLength
-#@ stub ConvertLengthToIpv4Mask
+@ stdcall ConvertIpv4MaskToLength ( long ptr )
+@ 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 97284edbe6..87f35dd170 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -429,6 +429,54 @@ DWORD WINAPI CreateSortedAddressPairs( const PSOCKADDR_IN6 src_list, DWORD src_c
 }
 
 
+/******************************************************************
+ *    ConvertLengthToIpv4Mask (IPHLPAPI.@)
+ */
+DWORD WINAPI ConvertLengthToIpv4Mask(ULONG mask_length, ULONG *mask)
+{
+    if (mask_length > 32)
+    {
+        *mask = INADDR_NONE;
+        return ERROR_INVALID_PARAMETER;
+    }
+
+    if (mask_length == 0)
+    {
+        *mask = 0;
+        return NO_ERROR;
+    }
+
+    *mask = htonl(0xFFFFFFFF << (32 - mask_length));
+    return NO_ERROR;
+}
+
+
+/******************************************************************
+ *    ConvertIpv4MaskToLength (IPHLPAPI.@)
+ */
+DWORD WINAPI ConvertIpv4MaskToLength(DWORD mask, UINT8 *mask_length)
+{
+    int i;
+    mask = ntohl(mask);
+
+    for (i = 0; i < 32; i++)
+    {
+        if (!((mask << i) & 0x80000000))
+        {
+            if (!((mask << i) & 0xFFFFFFFF))
+            {
+                break;
+            }
+
+            return ERROR_INVALID_PARAMETER;
+        }
+    }
+
+    *mask_length = i;
+    return NO_ERROR;
+}
+
+
 /******************************************************************
  *    DeleteIPAddress (IPHLPAPI.@)
  *
-- 
2.16.2




More information about the wine-devel mailing list