[PATCH 4/4] iphlpapi: Implement ParseNetworkString for IPv4 addresses and services

Alex Henrie alexhenrie24 at gmail.com
Thu Sep 5 00:14:15 CDT 2019


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45560
Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
 dlls/iphlpapi/iphlpapi.spec   |  2 +-
 dlls/iphlpapi/iphlpapi_main.c | 61 +++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/dlls/iphlpapi/iphlpapi.spec b/dlls/iphlpapi/iphlpapi.spec
index abc7152b6b..c5857f2831 100644
--- a/dlls/iphlpapi/iphlpapi.spec
+++ b/dlls/iphlpapi/iphlpapi.spec
@@ -243,7 +243,7 @@
 @ stdcall NotifyUnicastIpAddressChange(long ptr ptr long ptr)
 #@ stub NTPTimeToNTFileTime
 #@ stub NTTimeToNTPTime
-#@ stub ParseNetworkString
+@ stdcall ParseNetworkString(wstr long ptr ptr ptr)
 @ stub _PfAddFiltersToInterface at 24
 @ stub _PfAddGlobalFilterToInterface at 8
 @ stdcall _PfBindInterfaceToIPAddress at 12(long long ptr) PfBindInterfaceToIPAddress
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index f1aa0d1e04..1f823b401d 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -46,6 +46,7 @@
 #include "winsock2.h"
 #include "winternl.h"
 #include "ws2ipdef.h"
+#include "windns.h"
 #include "iphlpapi.h"
 #include "ifenum.h"
 #include "ipstats.h"
@@ -54,6 +55,7 @@
 #include "ifdef.h"
 #include "netioapi.h"
 #include "tcpestats.h"
+#include "ip2string.h"
 
 #include "wine/debug.h"
 #include "wine/unicode.h"
@@ -3333,3 +3335,62 @@ DWORD WINAPI GetBestRoute2(NET_LUID *luid, NET_IFINDEX index,
 
     return ERROR_NOT_SUPPORTED;
 }
+
+/******************************************************************
+ *    ParseNetworkString (IPHLPAPI.@)
+ */
+DWORD WINAPI ParseNetworkString(const WCHAR *str, DWORD type,
+                                NET_ADDRESS_INFO *info, USHORT *port, BYTE *prefix_len)
+{
+    IN_ADDR temp_addr4;
+    USHORT temp_port = 0;
+    NTSTATUS status;
+
+    TRACE("(%s, %d, %p, %p, %p)\n", debugstr_w(str), type, info, port, prefix_len);
+
+    if (!str)
+        return ERROR_INVALID_PARAMETER;
+
+    if (type & NET_STRING_IPV4_ADDRESS)
+    {
+        status = RtlIpv4StringToAddressExW(str, TRUE, &temp_addr4, &temp_port);
+        if (SUCCEEDED(status) && !temp_port)
+        {
+            if (info)
+            {
+                info->Format = NET_ADDRESS_IPV4;
+                info->u.Ipv4Address.sin_addr = temp_addr4;
+                info->u.Ipv4Address.sin_port = 0;
+            }
+            if (port) *port = 0;
+            if (prefix_len) *prefix_len = 255;
+            return ERROR_SUCCESS;
+        }
+    }
+    if (type & NET_STRING_IPV4_SERVICE)
+    {
+        status = RtlIpv4StringToAddressExW(str, TRUE, &temp_addr4, &temp_port);
+        if (SUCCEEDED(status) && temp_port)
+        {
+            if (info)
+            {
+                info->Format = NET_ADDRESS_IPV4;
+                info->u.Ipv4Address.sin_addr = temp_addr4;
+                info->u.Ipv4Address.sin_port = temp_port;
+            }
+            if (port) *port = ntohs(temp_port);
+            if (prefix_len) *prefix_len = 255;
+            return ERROR_SUCCESS;
+        }
+    }
+
+    if (info) info->Format = NET_ADDRESS_FORMAT_UNSPECIFIED;
+
+    if (type & ~(NET_STRING_IPV4_ADDRESS|NET_STRING_IPV4_SERVICE))
+    {
+        FIXME("Unimplemented type 0x%x\n", type);
+        return ERROR_NOT_SUPPORTED;
+    }
+
+    return ERROR_INVALID_PARAMETER;
+}
-- 
2.23.0




More information about the wine-devel mailing list