From d7dbf8e05ca7d49d5cba2ea3a6d1a9d1a902aed5 Mon Sep 17 00:00:00 2001
From: Thomas Faber <thfabba@gmx.de>
Date: Fri, 20 Jul 2012 15:42:04 +0200
Subject: ntdll: Implement RtlIpv4StringToAddressA.

---
 dlls/ntdll/ntdll.spec               |    2 +-
 dlls/ntdll/rtl.c                    |   33 +++++++++++++++++++++++++++++++++
 dlls/ntdll/tests/rtl.c              |    2 +-
 dlls/ntoskrnl.exe/ntoskrnl.exe.spec |    2 +-
 4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 7454414..511052d 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -696,7 +696,7 @@
 @ stdcall RtlIpv4AddressToStringExA(ptr long ptr ptr)
 @ stdcall RtlIpv4AddressToStringExW(ptr long ptr ptr)
 @ stdcall RtlIpv4AddressToStringW(ptr ptr)
-# @ stub RtlIpv4StringToAddressA
+@ stdcall RtlIpv4StringToAddressA(str long ptr ptr)
 # @ stub RtlIpv4StringToAddressExA
 @ stdcall RtlIpv4StringToAddressExW(ptr ptr wstr ptr)
 @ stdcall RtlIpv4StringToAddressW(wstr long ptr ptr)
diff --git a/dlls/ntdll/rtl.c b/dlls/ntdll/rtl.c
index 4b00778..333a114 100644
--- a/dlls/ntdll/rtl.c
+++ b/dlls/ntdll/rtl.c
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "wine/port.h"
 
+#include <assert.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -1073,6 +1074,38 @@ Done:
     return Status;
 }
 
+/***********************************************************************
+ * RtlIpv4StringToAddressA [NTDLL.@]
+ *
+ * Parse the given string into an ipv4 address
+ *
+ * See RtlIpv4StringToAddressW
+ */
+NTSTATUS WINAPI RtlIpv4StringToAddressA(PCSTR String, BOOLEAN Strict,
+                                        PCSTR *Terminator, IN_ADDR *Addr)
+{
+    NTSTATUS Status;
+    ANSI_STRING AddressA;
+    UNICODE_STRING AddressW;
+    PCWSTR TerminatorW = NULL;
+
+    RtlInitAnsiString(&AddressA, String);
+    Status = RtlAnsiStringToUnicodeString(&AddressW, &AddressA, TRUE);
+    if (!NT_SUCCESS(Status)) return Status;
+
+    Status = RtlIpv4StringToAddressW(AddressW.Buffer,
+                                     Strict,
+                                     &TerminatorW,
+                                     Addr);
+
+    assert(TerminatorW >= AddressW.Buffer);
+    *Terminator = String + (TerminatorW - AddressW.Buffer);
+
+    RtlFreeUnicodeString(&AddressW);
+
+    return Status;
+}
+
 NTSTATUS WINAPI RtlIpv4StringToAddressExW(PULONG IP, PULONG Port,
                                           LPCWSTR Buffer, PULONG MaxSize)
 {
diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c
index 38909a3..95aaa8c 100644
--- a/dlls/ntdll/tests/rtl.c
+++ b/dlls/ntdll/tests/rtl.c
@@ -1409,7 +1409,7 @@ static void test_RtlIpv4StringToAddress(void)
 
     if (!pRtlIpv4StringToAddressA)
     {
-        skip("RtlIpv4StringToAddress not available\n");
+        win_skip("RtlIpv4StringToAddress not available\n");
         return;
     }
 
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec
index be7c6e3..068a4b3 100644
--- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec
+++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec
@@ -1073,7 +1073,7 @@
 @ stdcall RtlIpv4AddressToStringExA(ptr long ptr ptr) ntdll.RtlIpv4AddressToStringExA
 @ stdcall RtlIpv4AddressToStringExW(ptr ptr ptr ptr) ntdll.RtlIpv4AddressToStringExW
 @ stdcall RtlIpv4AddressToStringW(ptr ptr) ntdll.RtlIpv4AddressToStringW
-@ stub RtlIpv4StringToAddressA
+@ stdcall RtlIpv4StringToAddressA(str long ptr ptr) ntdll.RtlIpv4StringToAddressA
 @ stub RtlIpv4StringToAddressExA
 @ stdcall RtlIpv4StringToAddressExW(ptr ptr wstr ptr) ntdll.RtlIpv4StringToAddressExW
 @ stdcall RtlIpv4StringToAddressW(wstr long ptr ptr) ntdll.RtlIpv4StringToAddressW
-- 
1.7.10.msysgit.1
