--- 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.@) *
On Mon, Mar 19, 2018 at 11:55:38AM +0100, Roger Zoellner wrote:
dlls/iphlpapi/iphlpapi.spec | 4 ++-- dlls/iphlpapi/iphlpapi_main.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-)
Hi Roger,
Thank you for your contribution. We actually have another implementation of ConvertLengthIpv4Mask() that's almost viable (see wine-devel for the details), so I suggest you concerntrate on something else. Your ConvertIpv4MaskToLength implementation would be a good choice to work on, so I'd resubmit just the bits that touch that.
You will need to include the following:
A Signed-off-by: line. Some tests. Add the prototype of ConvertIpv4MaskToLength in include/netioapi.h
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)
Also, watch out for inconsistent white-space.
Huw.