Author: fireball
Date: Fri Dec 23 20:40:02 2011
New Revision: 54742
URL:
http://svn.reactos.org/svn/reactos?rev=54742&view=rev
Log:
[RTL]
- Samuel Serapion: Implement RtlIpv4AddressToStringEx A/W and minor enhancements
RtlIpv4AddressToStringA/W. Fixes some ntdll:rtl winetests.
See issue #6779 for more details.
Modified:
trunk/reactos/lib/rtl/network.c
Modified: trunk/reactos/lib/rtl/network.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/network.c?rev=5474…
==============================================================================
--- trunk/reactos/lib/rtl/network.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/network.c [iso-8859-1] Fri Dec 23 20:40:02 2011
@@ -12,6 +12,15 @@
#define NDEBUG
#include <debug.h>
+/* maximum length of an ipv4 address expressed as a string */
+#define IPV4_ADDR_STRING_MAX_LEN 16
+
+/* maximum length of an ipv4 port expressed as a string */
+#define IPV4_PORT_STRING_MAX_LEN 7 /* with the leading ':' */
+
+/* network to host order conversion for little endian machines */
+#define WN2H(w) (((w & 0xFF00) >> 8) | ((w & 0x00FF) << 8))
+
/* FUNCTIONS ***************************************************************/
/*
@@ -22,19 +31,23 @@
RtlIpv4AddressToStringA(IN struct in_addr *Addr,
OUT PCHAR S)
{
- CHAR Buffer[sizeof("255.255.255.255")];
+ CHAR Buffer[IPV4_ADDR_STRING_MAX_LEN];
INT Length;
+
+ if(!S)
+ return NULL;
+
Length = sprintf(Buffer, "%u.%u.%u.%u", Addr->S_un.S_un_b.s_b1,
Addr->S_un.S_un_b.s_b2,
Addr->S_un.S_un_b.s_b3,
Addr->S_un.S_un_b.s_b4);
- if (S)
- strcpy(S, Buffer);
+
+ strcpy(S, Buffer);
return S + Length;
}
/*
- * @unimplemented
+ * @implemented
*/
NTSTATUS
NTAPI
@@ -43,8 +56,28 @@
OUT PCHAR AddressString,
IN OUT PULONG AddressStringLength)
{
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
+ CHAR Buffer[IPV4_ADDR_STRING_MAX_LEN+IPV4_PORT_STRING_MAX_LEN];
+ ULONG Length;
+
+ if (!Address || !AddressString || !AddressStringLength)
+ return STATUS_INVALID_PARAMETER;
+
+ Length = sprintf(Buffer, "%u.%u.%u.%u", Address->S_un.S_un_b.s_b1,
+ Address->S_un.S_un_b.s_b2,
+ Address->S_un.S_un_b.s_b3,
+ Address->S_un.S_un_b.s_b4);
+
+ if (Port) Length += sprintf(Buffer + Length, ":%u", WN2H(Port));
+
+ if (*AddressStringLength > Length)
+ {
+ *AddressStringLength = Length + 1;
+ strcpy(AddressString, Buffer);
+ return STATUS_SUCCESS;
+ }
+
+ *AddressStringLength = Length + 1;
+ return STATUS_INVALID_PARAMETER;
}
/*
@@ -55,14 +88,24 @@
RtlIpv4AddressToStringW(IN struct in_addr *Addr,
OUT PWCHAR S)
{
- return S + swprintf(S, L"%u.%u.%u.%u", Addr->S_un.S_un_b.s_b1,
- Addr->S_un.S_un_b.s_b2,
- Addr->S_un.S_un_b.s_b3,
- Addr->S_un.S_un_b.s_b4);
-}
-
-/*
- * @unimplemented
+ WCHAR Buffer[IPV4_ADDR_STRING_MAX_LEN];
+ INT Length;
+
+ if (!S)
+ return NULL;
+
+ Length = swprintf(Buffer, L"%u.%u.%u.%u", Addr->S_un.S_un_b.s_b1,
+ Addr->S_un.S_un_b.s_b2,
+ Addr->S_un.S_un_b.s_b3,
+ Addr->S_un.S_un_b.s_b4);
+
+ wcscpy(S, Buffer);
+
+ return S + Length;
+}
+
+/*
+ * @implemented
*/
NTSTATUS
NTAPI
@@ -71,8 +114,28 @@
OUT PWCHAR AddressString,
IN OUT PULONG AddressStringLength)
{
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
+ WCHAR Buffer[IPV4_ADDR_STRING_MAX_LEN+IPV4_PORT_STRING_MAX_LEN];
+ ULONG Length;
+
+ if (!Address || !AddressString || !AddressStringLength)
+ return STATUS_INVALID_PARAMETER;
+
+ Length = swprintf(Buffer, L"%u.%u.%u.%u", Address->S_un.S_un_b.s_b1,
+ Address->S_un.S_un_b.s_b2,
+ Address->S_un.S_un_b.s_b3,
+ Address->S_un.S_un_b.s_b4);
+
+ if (Port) Length += swprintf(Buffer + Length, L":%u", WN2H(Port));
+
+ if (*AddressStringLength > Length)
+ {
+ *AddressStringLength = Length + 1;
+ wcscpy(AddressString, Buffer);
+ return STATUS_SUCCESS;
+ }
+
+ *AddressStringLength = Length + 1;
+ return STATUS_INVALID_PARAMETER;
}
/*