17#define IPV4_ADDR_STRING_MAX_LEN 16
20#define IPV4_PORT_STRING_MAX_LEN 7
23#define RTLIPV6A2S_MAX_LEN 46
26#define RTLIPV6A2SEX_MAX_LEN 65
29#define WN2H(w) (((w & 0xFF00) >> 8) | ((w & 0x00FF) << 8))
51 else if (Digit >=
L'a' && Digit <=
L'f' &&
Base >= 16)
105 if (Strict &&
Base != 10)
170 Addr->S_un.S_un_b.s_b1,
171 Addr->S_un.S_un_b.s_b2,
172 Addr->S_un.S_un_b.s_b3,
173 Addr->S_un.S_un_b.s_b4);
197 if (!
Address || !AddressString || !AddressStringLength)
205 Port ?
"%u.%u.%u.%u:%u"
217 if (*AddressStringLength >
Length)
220 *AddressStringLength,
223 *AddressStringLength =
Length + 1;
227 *AddressStringLength =
Length + 1;
252 Addr->S_un.S_un_b.s_b1,
253 Addr->S_un.S_un_b.s_b2,
254 Addr->S_un.S_un_b.s_b3,
255 Addr->S_un.S_un_b.s_b4);
279 if (!
Address || !AddressString || !AddressStringLength)
287 Port ?
L"%u.%u.%u.%u:%u"
298 Length = End - AddressString;
299 if (*AddressStringLength >
Length)
302 *AddressStringLength,
305 *AddressStringLength =
Length + 1;
309 *AddressStringLength =
Length + 1;
402 if (Strict && Parts < 4)
409 Result = Values[Parts - 1];
410 for (
i = 0;
i < Parts - 1;
i++)
414 if (Values[
i] > 0xFF || (
Result & (0xFF <<
Shift)) != 0)
456 if (*CurrentChar !=
L':')
467 if (*CurrentChar || !ConvertedPort || ConvertedPort > 0xffff)
520 if (!
Address || !AddressString || !AddressStringLength)
554 if (!Addr->s6_words[0] && !Addr->s6_words[1] && !Addr->s6_words[2] && !Addr->s6_words[3] && Addr->s6_words[6])
557 if (Addr->s6_words[4] == 0xffff && !Addr->s6_words[5])
559 else if (!Addr->s6_words[4] && Addr->s6_words[5] == 0xffff)
561 else if (!Addr->s6_words[4] && !Addr->s6_words[5])
584 if (!(Addr->s6_words[4] & 0xfffd) && Addr->s6_words[5] == 0xfe5e)
587 for (
n = 0;
n < Parts; ++
n)
589 if (SkipOnce && ((
n + 1) < Parts) && !Addr->s6_words[
n] && !Addr->s6_words[
n + 1])
592 while (!Addr->s6_words[
n + 1] && (
n + 1) < Parts)
596 if ((
n + 1) >= Parts)
615 WN2H(Addr->s6_words[
n]));
662 if (!
Address || !AddressString || !AddressStringLength)
708 if (*AddressStringLength >
Length)
712 *AddressStringLength =
Length + 1;
716 *AddressStringLength =
Length + 1;
795 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
796 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
797 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
798 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
799 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
800 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
801 -1, 10, 11, 12, 13, 14, 15
808 ULONG cur_value, prev_value = 0;
817 if ((*
str)[0] ==
'0')
819 if ((*
str)[1] ==
'x' || (*
str)[1] ==
'X')
825 else if ((*
str)[1] >=
'0' && (*
str)[1] <=
'9')
833 for (cur_value = 0; **
str; *
str += 1)
838 if (
d == -1 ||
d >=
base)
break;
839 cur_value = cur_value *
base +
d;
841 if (cur_value < prev_value)
return FALSE;
842 prev_value = cur_value;
854 if (*terminator ==
'0') terminator++;
855 else if (terminator == *
str)
return FALSE;
864 int n_bytes = 0, n_ipv4_bytes = 0, gap = -1;
865 ULONG ip_component, scope_component = 0, port_component = 0;
866 const WCHAR *prev_str;
871 expecting_port =
TRUE;
884 if (!n_ipv4_bytes && *
str ==
':')
887 if (gap != -1)
goto error;
899 if (!n_ipv4_bytes && n_bytes <= (gap != -1 ? 10 : 12))
910 if (
str - prev_str > 3 || ip_component > 255)
916 if (*
str !=
'.' && (n_ipv4_bytes < 4 || (n_bytes < 15 && gap == -1)))
goto error;
917 address->u.Byte[n_bytes] = ip_component;
920 if (n_ipv4_bytes == 4 || *
str !=
'.')
break;
927 if (prev_str[0] ==
'0' && (prev_str[1] ==
'x' || prev_str[1] ==
'X'))
930 if (terminator) *terminator = prev_str + 1;
937 if (*
str !=
':' && n_bytes < 14 && gap == -1)
goto error;
938 if (
str - prev_str > 4)
943 if (*
str !=
':' || (gap != -1 &&
str[1] ==
':'))
break;
945 if (n_bytes == (gap != -1 ? 14 : 16))
break;
950 if (terminator) *terminator =
str;
956 if (n_bytes < 16)
goto error;
966 if (has_0x)
goto error;
982 if (!port_component || port_component > 0xFFFF || *
str)
goto error;
990 if (scope) *scope = scope_component;
996 if (terminator) *terminator =
str;
1010 if (!
String || !Terminator || !Addr)
1027 if (!AddressString || !
Address || !ScopeId || !
Port)
ACPI_SIZE strlen(const char *String)
#define NT_SUCCESS(StatCode)
#define RtlUlongByteSwap(_x)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI NTSTATUS WINAPI RtlInitAnsiStringEx(PANSI_STRING, PCSZ)
static const WCHAR StringW[]
#define memmove(s1, s2, n)
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteN(_Out_ PCHAR MbString, _In_ ULONG MbSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
#define _Out_writes_to_(s, c)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
NTSTRSAFEAPI RtlStringCchCopyW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
NTSTRSAFEAPI RtlStringCchCopyA(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCSTR pszSrc)
NTSTRSAFEVAPI RtlStringCchPrintfExA(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cchDest, _Outptr_opt_result_buffer_(*pcchRemaining) NTSTRSAFE_PSTR *ppszDestEnd, _Out_opt_ size_t *pcchRemaining, _In_ STRSAFE_DWORD dwFlags, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
NTSTRSAFEVAPI RtlStringCchPrintfExW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _Outptr_opt_result_buffer_(*pcchRemaining) NTSTRSAFE_PWSTR *ppszDestEnd, _Out_opt_ size_t *pcchRemaining, _In_ STRSAFE_DWORD dwFlags, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
PWSTR NTAPI RtlIpv6AddressToStringW(_In_ const struct in6_addr *Addr, _Out_writes_(RTLIPV6A2S_MAX_LEN) PWSTR S)
NTSTATUS NTAPI RtlIpv4StringToAddressExA(_In_ PCSTR AddressString, _In_ BOOLEAN Strict, _Out_ struct in_addr *Address, _Out_ PUSHORT Port)
#define RTLIPV6A2S_MAX_LEN
#define IPV4_PORT_STRING_MAX_LEN
PSTR NTAPI RtlIpv4AddressToStringA(_In_ const struct in_addr *Addr, _Out_writes_(IPV4_ADDR_STRING_MAX_LEN) PCHAR S)
PWSTR NTAPI RtlIpv4AddressToStringW(_In_ const struct in_addr *Addr, _Out_writes_(IPV4_ADDR_STRING_MAX_LEN) PWCHAR S)
NTSTATUS NTAPI RtlIpv4AddressToStringExA(_In_ const struct in_addr *Address, _In_ USHORT Port, _Out_writes_to_(*AddressStringLength, *AddressStringLength) PCHAR AddressString, _Inout_ PULONG AddressStringLength)
NTSTATUS NTAPI RtlIpv6StringToAddressExW(_In_ PCWSTR AddressString, _Out_ struct in6_addr *Address, _Out_ PULONG ScopeId, _Out_ PUSHORT Port)
static NTSTATUS RtlpStringToUlongBase(_In_ PCWSTR String, _In_ ULONG Base, _Out_ PCWSTR *Terminator, _Out_ PULONG Out)
NTSTATUS NTAPI RtlIpv4AddressToStringExW(_In_ const struct in_addr *Address, _In_ USHORT Port, _Out_writes_to_(*AddressStringLength, *AddressStringLength) PWCHAR AddressString, _Inout_ PULONG AddressStringLength)
static NTSTATUS ipv6_string_to_address(const WCHAR *str, BOOL ex, const WCHAR **terminator, IN6_ADDR *address, ULONG *scope, USHORT *port)
static NTSTATUS RtlpStringToUlong(_In_ PCWSTR String, _In_ BOOLEAN Strict, _Out_ PCWSTR *Terminator, _Out_ PULONG Out)
NTSTATUS NTAPI RtlIpv4StringToAddressW(_In_ PCWSTR String, _In_ BOOLEAN Strict, _Out_ PCWSTR *Terminator, _Out_ struct in_addr *Addr)
static const int hex_table[]
#define IPV4_ADDR_STRING_MAX_LEN
NTSTATUS NTAPI RtlIpv6AddressToStringExA(_In_ const struct in6_addr *Address, _In_ ULONG ScopeId, _In_ USHORT Port, _Out_writes_to_(*AddressStringLength, *AddressStringLength) PSTR AddressString, _Inout_ PULONG AddressStringLength)
static BOOL parse_ipv4_component(const WCHAR **str, BOOL strict, ULONG *value)
static BOOL parse_ipv6_component(const WCHAR **str, int base, ULONG *value)
#define RTLIPV6A2SEX_MAX_LEN
NTSTATUS NTAPI RtlIpv6StringToAddressExA(_In_ PCSTR AddressString, _Out_ struct in6_addr *Address, _Out_ PULONG ScopeId, _Out_ PUSHORT Port)
NTSTATUS NTAPI RtlIpv6AddressToStringExW(_In_ const struct in6_addr *Address, _In_ ULONG ScopeId, _In_ USHORT Port, _Out_writes_to_(*AddressStringLength, *AddressStringLength) PWCHAR AddressString, _Inout_ PULONG AddressStringLength)
NTSTATUS NTAPI RtlIpv4StringToAddressA(_In_ PCSTR String, _In_ BOOLEAN Strict, _Out_ PCSTR *Terminator, _Out_ struct in_addr *Addr)
NTSTATUS NTAPI RtlIpv6StringToAddressW(_In_ PCWSTR String, _Out_ PCWSTR *Terminator, _Out_ struct in6_addr *Addr)
PSTR NTAPI RtlIpv6AddressToStringA(_In_ const struct in6_addr *Addr, _Out_writes_(RTLIPV6A2S_MAX_LEN) PSTR S)
NTSTATUS NTAPI RtlIpv6StringToAddressA(_In_ PCSTR String, _Out_ PCSTR *Terminator, _Out_ struct in6_addr *Addr)
NTSTATUS NTAPI RtlpIpv4StringToAddressParserW(_In_ PCWSTR String, _In_ BOOLEAN Strict, _Out_ PCWSTR *Terminator, _Out_writes_(4) ULONG *Values, _Out_ INT *Parts)
NTSTATUS NTAPI RtlIpv4StringToAddressExW(_In_ PCWSTR AddressString, _In_ BOOLEAN Strict, _Out_ struct in_addr *Address, _Out_ PUSHORT Port)
#define STATUS_INVALID_PARAMETER
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
#define success(from, fromstr, to, tostr)
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
#define RtlUshortByteSwap(_x)
_In_ __drv_aliasesMem PSTRING Prefix