[PATCH 1/2] ntdll: Implement RtlIpv4AddressToString / RtlIpv4AddressToStringEx [try 4]
Detlef Riekenberg
wine.dev at web.de
Wed Aug 18 13:28:24 CDT 2010
try 4: Removed an unused variable
try 3: Don't use the WS_* field names
try 2: using inaddr.h instead of winsock2.h
--
By By ... Detlef
---
dlls/ntdll/ntdll.spec | 8 +-
dlls/ntdll/rtl.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 152 insertions(+), 8 deletions(-)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 8441b41..574b4c3 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -690,10 +690,10 @@
@ stdcall RtlInterlockedPushEntrySList(ptr ptr)
@ stdcall RtlInterlockedPushListSList(ptr ptr ptr long)
# @ stub RtlInvertRangeList
-# @ stub RtlIpv4AddressToStringA
-# @ stub RtlIpv4AddressToStringExA
-@ stdcall RtlIpv4AddressToStringExW(ptr ptr ptr ptr)
-# @ stub RtlIpv4AddressToStringW
+@ stdcall RtlIpv4AddressToStringA(ptr ptr)
+@ stdcall RtlIpv4AddressToStringExA(ptr long ptr ptr)
+@ stdcall RtlIpv4AddressToStringExW(ptr long ptr ptr)
+@ stdcall RtlIpv4AddressToStringW(ptr ptr)
# @ stub RtlIpv4StringToAddressA
# @ stub RtlIpv4StringToAddressExA
@ stdcall RtlIpv4StringToAddressExW(ptr ptr wstr ptr)
diff --git a/dlls/ntdll/rtl.c b/dlls/ntdll/rtl.c
index 301b30c..47236a1 100644
--- a/dlls/ntdll/rtl.c
+++ b/dlls/ntdll/rtl.c
@@ -37,8 +37,15 @@
#include "winternl.h"
#include "wine/debug.h"
#include "wine/exception.h"
+#include "wine/unicode.h"
#include "ntdll_misc.h"
+#ifdef HAVE_NETINET_IN_H
+#include "netinet/in.h"
+#endif
+#define USE_WS_PREFIX
+#include "inaddr.h"
+
WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
static RTL_CRITICAL_SECTION peb_lock;
@@ -904,14 +911,151 @@ NTSTATUS WINAPI RtlIpv4StringToAddressExW(PULONG IP, PULONG Port,
return STATUS_SUCCESS;
}
-NTSTATUS WINAPI RtlIpv4AddressToStringExW (PULONG IP, PULONG Port,
- LPWSTR Buffer, PULONG MaxSize)
+/***********************************************************************
+ * RtlIpv4AddressToStringExW [NTDLL.@]
+ *
+ * Convert the given ipv4 address and optional the port to a string
+ *
+ * PARAMS
+ * pin [I] PTR to the ip address to convert (network byte order)
+ * port [I] optional port to convert (network byte order)
+ * buffer [O] destination buffer for the result
+ * psize [IO] PTR to available/used size of the destination buffer
+ *
+ * RETURNS
+ * Success: STATUS_SUCCESS
+ * Failure: STATUS_INVALID_PARAMETER
+ *
+ */
+NTSTATUS WINAPI RtlIpv4AddressToStringExW(const IN_ADDR *pin, USHORT port, LPWSTR buffer, PULONG psize)
{
- FIXME("(%p,%p,%p,%p): stub\n", IP, Port, Buffer, MaxSize);
+ WCHAR tmp_ip[16];
+ WCHAR tmp_port[16];
+ static WCHAR fmt_ip[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
+ static WCHAR fmt_port[] = {':','%','u',0};
+ ULONG needed;
- return STATUS_SUCCESS;
+ TRACE("(%p:0x%x, %d, %p, %p:%d)\n", pin, pin ? (*pin).S_un.S_addr : 0,
+ port, buffer, psize, psize ? *psize : 0);
+
+ if (!pin || !buffer || !psize)
+ return STATUS_INVALID_PARAMETER;
+
+ sprintfW(tmp_ip, fmt_ip, (*pin).S_un.S_un_b.s_b1, (*pin).S_un.S_un_b.s_b2,
+ (*pin).S_un.S_un_b.s_b3, (*pin).S_un.S_un_b.s_b4);
+
+ needed = strlenW(tmp_ip);
+
+ if (port) {
+ sprintfW(tmp_port, fmt_port, ntohs(port));
+ needed += strlenW(tmp_port);
+ }
+ else
+ *tmp_port = 0;
+
+ if (*psize > needed) {
+ *psize = needed + 1;
+ strcpyW(buffer, tmp_ip);
+ strcatW(buffer, tmp_port);
+ return STATUS_SUCCESS;
+ }
+
+ *psize = needed + 1;
+ return STATUS_INVALID_PARAMETER;
}
+/***********************************************************************
+ * RtlIpv4AddressToStringExA [NTDLL.@]
+ *
+ * Convert the given ipv4 address and optional the port to a string
+ *
+ * See RtlIpv4AddressToStringExW
+ */
+NTSTATUS WINAPI RtlIpv4AddressToStringExA(const IN_ADDR *pin, USHORT port, LPSTR buffer, PULONG psize)
+{
+ CHAR tmp_ip[16];
+ CHAR tmp_port[16];
+ ULONG needed;
+
+ TRACE("(%p:0x%x, %d, %p, %p:%d)\n", pin, (ULONG) pin ? (*pin).S_un.S_addr : 0,
+ port, buffer, psize, psize ? *psize : 0);
+
+ if (!pin || !buffer || !psize)
+ return STATUS_INVALID_PARAMETER;
+
+ sprintf(tmp_ip, "%u.%u.%u.%u", (*pin).S_un.S_un_b.s_b1, (*pin).S_un.S_un_b.s_b2,
+ (*pin).S_un.S_un_b.s_b3, (*pin).S_un.S_un_b.s_b4);
+
+ needed = strlen(tmp_ip);
+
+ if (port) {
+ sprintf(tmp_port, ":%u", ntohs(port));
+ needed += strlen(tmp_port);
+ }
+ else
+ *tmp_port = 0;
+
+ if (*psize > needed) {
+ *psize = needed + 1;
+ strcpy(buffer, tmp_ip);
+ strcat(buffer, tmp_port);
+ return STATUS_SUCCESS;
+ }
+
+ *psize = needed + 1;
+ return STATUS_INVALID_PARAMETER;
+}
+
+/***********************************************************************
+ * RtlIpv4AddressToStringW [NTDLL.@]
+ *
+ * Convert the given ipv4 address to a string
+ *
+ * PARAMS
+ * pin [I] PTR to the ip address to convert (network byte order)
+ * buffer [O] destination buffer for the result (at least 16 character)
+ *
+ * RETURNS
+ * Success: PTR to the 0 character at the end of the converted string
+ * Failure: ~0
+ *
+ */
+WCHAR * WINAPI RtlIpv4AddressToStringW(const IN_ADDR *pin, LPWSTR buffer)
+{
+ ULONG size = 16;
+ NTSTATUS res;
+
+ TRACE("(%p:0x%x, %p)\n", pin, pin ? (*pin).S_un.S_addr : 0, buffer);
+ res = RtlIpv4AddressToStringExW(pin, 0, buffer, &size);
+ if (!res) {
+ return buffer + size - 1;
+ }
+ return (WCHAR *) ~0;
+}
+
+/***********************************************************************
+ * RtlIpv4AddressToStringA [NTDLL.@]
+ *
+ * Convert the given ipv4 address to a string
+ *
+ * See RtlIpv4AddressToStringW
+ */
+CHAR * WINAPI RtlIpv4AddressToStringA(const IN_ADDR *pin, LPSTR buffer)
+{
+ ULONG size = 16;
+ NTSTATUS res;
+
+ TRACE("(%p:0x%x, %p)\n", pin, pin ? (*pin).S_un.S_addr : 0, buffer);
+ res = RtlIpv4AddressToStringExA(pin, 0, buffer, &size);
+ if (!res) {
+ return buffer + size - 1;
+ }
+ return (CHAR *) ~0;
+}
+
+/***********************************************************************
+ * get_pointer_obfuscator (internal)
+ */
static DWORD_PTR get_pointer_obfuscator( void )
{
static DWORD_PTR pointer_obfuscator;
--
1.7.0.4
More information about the wine-patches
mailing list