mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-09-03 12:23:25 +00:00
[RTL]
- Samuel Serapion: Implement RtlIpv4AddressToStringEx A/W and minor enhancements RtlIpv4AddressToStringA/W. Fixes some ntdll:rtl winetests. See issue #6779 for more details. svn path=/trunk/; revision=54742
This commit is contained in:
+76
-13
@@ -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 @@ NTAPI
|
||||
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 @@ RtlIpv4AddressToStringExA(IN struct in_addr *Address,
|
||||
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 @@ NTAPI
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
* @implemented
|
||||
*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
@@ -71,8 +114,28 @@ RtlIpv4AddressToStringExW(IN struct in_addr *Address,
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user