2004-08-05 18:17:37 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2006-05-10 17:47:44 +00:00
|
|
|
* PROJECT: ReactOS Runtime Library
|
2004-08-05 18:17:37 +00:00
|
|
|
* PURPOSE: Network Address Translation implementation
|
2006-05-10 17:47:44 +00:00
|
|
|
* PROGRAMMER: Alex Ionescu (alexi@tinykrnl.org)
|
2004-08-05 18:17:37 +00:00
|
|
|
*/
|
|
|
|
|
2005-09-08 00:09:32 +00:00
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2005-07-26 08:39:07 +00:00
|
|
|
#include <rtl.h>
|
2004-08-05 18:17:37 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2005-09-08 00:09:32 +00:00
|
|
|
|
2011-12-23 20:40:02 +00:00
|
|
|
/* 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))
|
|
|
|
|
2005-09-08 00:09:32 +00:00
|
|
|
/* FUNCTIONS ***************************************************************/
|
2004-08-05 18:17:37 +00:00
|
|
|
|
|
|
|
/*
|
2006-05-10 17:47:44 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
2004-09-13 20:25:26 +00:00
|
|
|
LPSTR
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv4AddressToStringA(IN struct in_addr *Addr,
|
|
|
|
OUT PCHAR S)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2011-10-12 11:58:46 +00:00
|
|
|
INT Length;
|
2012-02-20 06:37:13 +00:00
|
|
|
|
|
|
|
if (!S) return (LPSTR)~0;
|
2011-12-23 20:40:02 +00:00
|
|
|
|
2012-02-20 01:13:31 +00:00
|
|
|
Length = sprintf(S, "%u.%u.%u.%u", Addr->S_un.S_un_b.s_b1,
|
2011-10-12 11:58:46 +00:00
|
|
|
Addr->S_un.S_un_b.s_b2,
|
|
|
|
Addr->S_un.S_un_b.s_b3,
|
|
|
|
Addr->S_un.S_un_b.s_b4);
|
2011-12-23 20:40:02 +00:00
|
|
|
|
2011-10-12 11:58:46 +00:00
|
|
|
return S + Length;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-12-23 20:40:02 +00:00
|
|
|
* @implemented
|
2006-05-10 17:47:44 +00:00
|
|
|
*/
|
2004-08-05 18:17:37 +00:00
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv4AddressToStringExA(IN struct in_addr *Address,
|
|
|
|
IN USHORT Port,
|
|
|
|
OUT PCHAR AddressString,
|
|
|
|
IN OUT PULONG AddressStringLength)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2011-12-23 20:40:02 +00:00
|
|
|
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;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-05-10 17:47:44 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
2004-09-13 20:25:26 +00:00
|
|
|
LPWSTR
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv4AddressToStringW(IN struct in_addr *Addr,
|
|
|
|
OUT PWCHAR S)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2011-12-23 20:40:02 +00:00
|
|
|
INT Length;
|
|
|
|
|
2012-02-20 06:37:13 +00:00
|
|
|
if (!S) return (LPWSTR)~0;
|
|
|
|
|
2012-02-20 01:13:31 +00:00
|
|
|
Length = 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);
|
2011-12-23 20:40:02 +00:00
|
|
|
return S + Length;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-12-23 20:40:02 +00:00
|
|
|
* @implemented
|
2006-05-10 17:47:44 +00:00
|
|
|
*/
|
2004-08-05 18:17:37 +00:00
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv4AddressToStringExW(IN struct in_addr *Address,
|
|
|
|
IN USHORT Port,
|
|
|
|
OUT PWCHAR AddressString,
|
|
|
|
IN OUT PULONG AddressStringLength)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2011-12-23 20:40:02 +00:00
|
|
|
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;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-05-10 17:47:44 +00:00
|
|
|
* @unimplemented
|
|
|
|
*/
|
2004-08-05 18:17:37 +00:00
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv4StringToAddressA(IN PCHAR String,
|
|
|
|
IN BOOLEAN Strict,
|
|
|
|
OUT PCHAR *Terminator,
|
|
|
|
OUT struct in_addr *Addr)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2006-05-10 17:47:44 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv4StringToAddressExA(IN PCHAR AddressString,
|
|
|
|
IN BOOLEAN Strict,
|
|
|
|
OUT struct in_addr *Address,
|
|
|
|
IN PUSHORT Port)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2006-05-10 17:47:44 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2010-06-08 20:24:15 +00:00
|
|
|
RtlIpv4StringToAddressW(IN PCWSTR String,
|
|
|
|
IN BOOLEAN Strict,
|
|
|
|
OUT LPWSTR *Terminator,
|
2006-05-10 17:47:44 +00:00
|
|
|
OUT struct in_addr *Addr)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2006-05-10 17:47:44 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv4StringToAddressExW(IN PWCHAR AddressString,
|
|
|
|
IN BOOLEAN Strict,
|
|
|
|
OUT struct in_addr *Address,
|
|
|
|
OUT PUSHORT Port)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2006-05-10 17:47:44 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv6AddressToStringA(IN struct in6_addr *Addr,
|
|
|
|
OUT PCHAR S)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2006-05-10 17:47:44 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv6AddressToStringExA(IN struct in6_addr *Address,
|
|
|
|
IN ULONG ScopeId,
|
|
|
|
IN ULONG Port,
|
|
|
|
OUT PCHAR AddressString,
|
|
|
|
IN OUT PULONG AddressStringLength)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2006-05-10 17:47:44 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv6AddressToStringW(IN struct in6_addr *Addr,
|
|
|
|
OUT PWCHAR S)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2006-05-10 17:47:44 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv6AddressToStringExW(IN struct in6_addr *Address,
|
|
|
|
IN ULONG ScopeId,
|
|
|
|
IN USHORT Port,
|
|
|
|
IN OUT PWCHAR AddressString,
|
|
|
|
IN OUT PULONG AddressStringLength)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2006-05-10 17:47:44 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv6StringToAddressA(IN PCHAR Name,
|
|
|
|
OUT PCHAR *Terminator,
|
|
|
|
OUT struct in6_addr *Addr)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2005-12-04 03:24:11 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv6StringToAddressExA(IN PCHAR AddressString,
|
|
|
|
OUT struct in6_addr *Address,
|
|
|
|
OUT PULONG ScopeId,
|
|
|
|
OUT PUSHORT Port)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2005-12-04 03:24:11 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv6StringToAddressW(IN PWCHAR Name,
|
|
|
|
OUT PCHAR *Terminator,
|
|
|
|
OUT struct in6_addr *Addr)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2005-12-04 03:24:11 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2006-05-10 17:47:44 +00:00
|
|
|
RtlIpv6StringToAddressExW(IN PWCHAR AddressName,
|
|
|
|
OUT struct in6_addr *Address,
|
|
|
|
OUT PULONG ScopeId,
|
|
|
|
OUT PUSHORT Port)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2005-12-04 03:24:11 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|