ReactOS 0.4.15-dev-8339-g4028de8
dnslib.h File Reference
#include <ws2atm.h>
Include dependency graph for dnslib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _DNS_IPV6_ADDRESS
 
struct  _DNS_ADDRESS
 
struct  _DNS_ARRAY
 
struct  _DNS_BLOB
 
struct  _DNS_FAMILY_INFO
 
struct  _FLATBUFF
 

Macros

#define IpV4Address   3
 

Typedefs

typedef enum _DNS_STRING_TYPE DNS_STRING_TYPE
 
typedef struct _DNS_IPV6_ADDRESS DNS_IPV6_ADDRESS
 
typedef struct _DNS_IPV6_ADDRESSPDNS_IPV6_ADDRESS
 
typedef struct _DNS_ADDRESS DNS_ADDRESS
 
typedef struct _DNS_ADDRESSPDNS_ADDRESS
 
typedef struct _DNS_ARRAY DNS_ARRAY
 
typedef struct _DNS_ARRAYPDNS_ARRAY
 
typedef struct _DNS_BLOB DNS_BLOB
 
typedef struct _DNS_BLOBPDNS_BLOB
 
typedef struct _DNS_FAMILY_INFO DNS_FAMILY_INFO
 
typedef struct _DNS_FAMILY_INFOPDNS_FAMILY_INFO
 
typedef struct _FLATBUFF FLATBUFF
 
typedef struct _FLATBUFFPFLATBUFF
 

Enumerations

enum  _DNS_STRING_TYPE { UnicodeString = 1 , Utf8String , AnsiString }
 

Functions

VOID WINAPI Dns_Free (IN PVOID Address)
 
PVOID WINAPI Dns_AllocZero (IN SIZE_T Size)
 
PDNS_FAMILY_INFO WINAPI FamilyInfo_GetForFamily (IN WORD AddressFamily)
 
VOID WINAPI DnsAddr_BuildFromIp4 (IN PDNS_ADDRESS DnsAddress, IN IN_ADDR Address, IN WORD Unknown)
 
VOID WINAPI DnsAddr_BuildFromIp6 (IN PDNS_ADDRESS DnsAddress, IN PIN6_ADDR Address, IN ULONG ScopeId, IN WORD Port)
 
PDNS_ARRAY WINAPI DnsAddrArray_Create (ULONG Count)
 
BOOL WINAPI DnsAddrArray_AddAddr (IN PDNS_ARRAY DnsAddrArray, IN PDNS_ADDRESS DnsAddress, IN WORD AddressFamily OPTIONAL, IN DWORD AddressType OPTIONAL)
 
VOID WINAPI DnsAddrArray_Free (IN PDNS_ARRAY DnsAddrArray)
 
BOOL WINAPI DnsAddrArray_AddIp4 (IN PDNS_ARRAY DnsAddrArray, IN IN_ADDR Address, IN DWORD AddressType)
 
BOOL WINAPI DnsAddrArray_ContainsAddr (IN PDNS_ARRAY DnsAddrArray, IN PDNS_ADDRESS DnsAddress, IN DWORD AddressType)
 
BOOLEAN WINAPI DnsAddr_BuildFromDnsRecord (IN PDNS_RECORD DnsRecord, OUT PDNS_ADDRESS DnsAddr)
 
PHOSTENT WINAPI Hostent_Init (IN PVOID *Buffer, IN WORD AddressFamily, IN ULONG AddressSize, IN ULONG AddressCount, IN ULONG AliasCount)
 
VOID WINAPI Hostent_ConvertToOffsets (IN PHOSTENT Hostent)
 
VOID WINAPI FlatBuf_Init (IN PFLATBUFF FlatBuffer, IN PVOID Buffer, IN SIZE_T Size)
 
PVOID WINAPI FlatBuf_Arg_CopyMemory (IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN PVOID Buffer, IN SIZE_T Size, IN ULONG Align)
 
PVOID WINAPI FlatBuf_Arg_Reserve (IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN SIZE_T Size, IN ULONG Align)
 
PVOID WINAPI FlatBuf_Arg_WriteString (IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN PVOID String, IN BOOLEAN IsUnicode)
 
PDNS_BLOB WINAPI SaBlob_Create (IN ULONG Count)
 
PDNS_BLOB WINAPI SaBlob_CreateFromIp4 (IN LPWSTR Name, IN ULONG Count, IN PIN_ADDR AddressArray)
 
VOID WINAPI SaBlob_Free (IN PDNS_BLOB Blob)
 
PHOSTENT WINAPI SaBlob_CreateHostent (IN OUT PULONG_PTR BufferPosition, IN OUT PSIZE_T RemainingBufferSpace, IN OUT PSIZE_T HostEntrySize, IN PDNS_BLOB Blob, IN DWORD StringType, IN BOOLEAN Relative, IN BOOLEAN BufferAllocated)
 
INT WINAPI SaBlob_WriteNameOrAlias (IN PDNS_BLOB Blob, IN LPWSTR String, IN BOOLEAN IsAlias)
 
PDNS_BLOB WINAPI SaBlob_Query (IN LPWSTR Name, IN WORD DnsType, IN ULONG Flags, IN PVOID *Reserved, IN DWORD AddressFamily)
 
ULONG WINAPI Dns_StringCopy (OUT PVOID Destination, IN OUT PULONG DestinationSize, IN PVOID String, IN ULONG StringSize OPTIONAL, IN DWORD InputType, IN DWORD OutputType)
 
LPWSTR WINAPI Dns_CreateStringCopy_W (IN LPWSTR Name)
 
ULONG WINAPI Dns_GetBufferLengthForStringCopy (IN PVOID String, IN ULONG Size OPTIONAL, IN DWORD InputType, IN DWORD OutputType)
 
BOOLEAN WINAPI Dns_StringToAddressW (OUT PVOID Address, IN OUT PULONG AddressSize, IN LPWSTR AddressName, IN OUT PDWORD AddressFamily)
 
LPWSTR WINAPI Dns_Ip4AddressToReverseName_W (OUT LPWSTR Name, IN IN_ADDR Address)
 
LPWSTR WINAPI Dns_Ip6AddressToReverseName_W (OUT LPWSTR Name, IN IN6_ADDR Address)
 
BOOLEAN WINAPI Dns_ReverseNameToDnsAddr_W (OUT PDNS_ADDRESS DnsAddr, IN LPWSTR Name)
 
BOOLEAN WINAPI Dns_Ip4ReverseNameToAddress_W (OUT PIN_ADDR Address, IN LPWSTR Name)
 

Macro Definition Documentation

◆ IpV4Address

#define IpV4Address   3

Definition at line 22 of file dnslib.h.

Typedef Documentation

◆ DNS_ADDRESS

◆ DNS_ARRAY

◆ DNS_BLOB

◆ DNS_FAMILY_INFO

◆ DNS_IPV6_ADDRESS

◆ DNS_STRING_TYPE

◆ FLATBUFF

◆ PDNS_ADDRESS

◆ PDNS_ARRAY

◆ PDNS_BLOB

◆ PDNS_FAMILY_INFO

◆ PDNS_IPV6_ADDRESS

◆ PFLATBUFF

Enumeration Type Documentation

◆ _DNS_STRING_TYPE

Enumerator
UnicodeString 
Utf8String 
AnsiString 

Definition at line 15 of file dnslib.h.

16{
17 UnicodeString = 1,
@ Utf8String
Definition: dnslib.h:18
@ AnsiString
Definition: dnslib.h:19
enum _DNS_STRING_TYPE DNS_STRING_TYPE

Function Documentation

◆ Dns_AllocZero()

PVOID WINAPI Dns_AllocZero ( IN SIZE_T  Size)

Definition at line 42 of file memory.c.

43{
45
46 /* Check if whoever imported us specified a special allocation function */
48 {
49 /* Use it to allocate the memory */
51 if (Buffer)
52 {
53 /* Zero it out */
55 }
56 }
57 else
58 {
59 /* Use our default */
61 }
62
63 /* Return the allocate pointer */
64 return Buffer;
65}
Definition: bufpool.h:45
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
PDNS_ALLOC_FUNCTION pDnsAllocFunction
Definition: memory.c:18
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define LMEM_ZEROINIT
Definition: winbase.h:375

Referenced by Dns_CreateStringCopy_W(), DnsAddrArray_Create(), SaBlob_Create(), and SaBlob_CreateHostent().

◆ Dns_CreateStringCopy_W()

LPWSTR WINAPI Dns_CreateStringCopy_W ( IN LPWSTR  Name)

Definition at line 141 of file string.c.

142{
143 SIZE_T StringLength;
144 LPWSTR NameCopy;
145
146 /* Make sure that we have a name */
147 if (!Name)
148 {
149 /* Fail */
151 return NULL;
152 }
153
154 /* Find out the size of the string */
155 StringLength = (wcslen(Name) + 1) * sizeof(WCHAR);
156
157 /* Allocate space for the copy */
158 NameCopy = Dns_AllocZero(StringLength);
159 if (NameCopy)
160 {
161 /* Copy it */
162 RtlCopyMemory(NameCopy, Name, StringLength);
163 }
164 else
165 {
166 /* Fail */
168 }
169
170 /* Return the copy */
171 return NameCopy;
172}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NULL
Definition: types.h:112
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
PVOID WINAPI Dns_AllocZero(IN SIZE_T Size)
Definition: memory.c:42
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by SaBlob_CreateFromIp4(), SaBlob_Query(), and SaBlob_WriteNameOrAlias().

◆ Dns_Free()

VOID WINAPI Dns_Free ( IN PVOID  Address)

Definition at line 25 of file memory.c.

26{
27 /* Check if whoever imported us specified a special free function */
29 {
30 /* Use it */
32 }
33 else
34 {
35 /* Use our own */
37 }
38}
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
static WCHAR Address[46]
Definition: ping.c:68
PDNS_FREE_FUNCTION pDnsFreeFunction
Definition: memory.c:19

Referenced by DnsAddrArray_Free(), and SaBlob_Free().

◆ Dns_GetBufferLengthForStringCopy()

ULONG WINAPI Dns_GetBufferLengthForStringCopy ( IN PVOID  String,
IN ULONG Size  OPTIONAL,
IN DWORD  InputType,
IN DWORD  OutputType 
)

Definition at line 176 of file string.c.

180{
181 ULONG OutputSize = 0;
182
183 /* Check what kind of string this is */
184 if (InputType == UnicodeString)
185 {
186 /* Check if we have a size */
187 if (!Size)
188 {
189 /* Get it ourselves */
191 }
192
193 /* Check the output type */
194 if (OutputType == UnicodeString)
195 {
196 /* Convert the size to bytes */
197 OutputSize = (Size + 1) * sizeof(WCHAR);
198 }
199 else if (OutputType == Utf8String)
200 {
201 /* FIXME */
202 OutputSize = 0;
203 }
204 else
205 {
206 /* Find out how much it will be in ANSI bytes */
207 OutputSize = WideCharToMultiByte(CP_ACP,
208 0,
209 String,
210 Size,
211 NULL,
212 0,
213 NULL,
214 NULL) + 1;
215 }
216 }
217 else if (InputType == AnsiString)
218 {
219 /* Check if we have a size */
220 if (!Size)
221 {
222 /* Get it ourselves */
224 }
225
226 /* Check the output type */
227 if (OutputType == AnsiString)
228 {
229 /* Just add a byte for the null char */
230 OutputSize = Size + 1;
231 }
232 else if (OutputType == UnicodeString)
233 {
234 /* Calculate the bytes for a Unicode string */
235 OutputSize = (MultiByteToWideChar(CP_ACP,
236 0,
237 String,
238 Size,
239 NULL,
240 0) + 1) * sizeof(WCHAR);
241 }
242 else if (OutputType == Utf8String)
243 {
244 /* FIXME */
245 OutputSize = 0;
246 }
247 }
248 else if (InputType == Utf8String)
249 {
250 /* FIXME */
251 OutputSize = 0;
252 }
253
254 /* Return the size required */
255 return OutputSize;
256}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by Dns_StringCopy(), and SaBlob_CreateHostent().

◆ Dns_Ip4AddressToReverseName_W()

LPWSTR WINAPI Dns_Ip4AddressToReverseName_W ( OUT LPWSTR  Name,
IN IN_ADDR  Address 
)

Definition at line 26 of file straddr.c.

28{
29 /* Simply append the ARPA string */
30 return Name + (wsprintfW(Name,
31 L"%u.%u.%u.%u.in-addr.arpa.",
32 Address.S_un.S_addr >> 24,
33 Address.S_un.S_addr >> 10,
34 Address.S_un.S_addr >> 8,
35 Address.S_un.S_addr) * sizeof(WCHAR));
36}
#define L(x)
Definition: ntvdm.h:50
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)

◆ Dns_Ip4ReverseNameToAddress_W()

BOOLEAN WINAPI Dns_Ip4ReverseNameToAddress_W ( OUT PIN_ADDR  Address,
IN LPWSTR  Name 
)

Definition at line 136 of file straddr.c.

138{
139 CHAR AnsiName[32];
140 ULONG Size = sizeof(AnsiName);
142
143 /* Make a copy of the name in ANSI */
144 ErrorCode = Dns_StringCopy(&AnsiName,
145 &Size,
146 Name,
147 0,
149 AnsiString);
150 if (ErrorCode)
151 {
152 /* Copy made sucesfully, now convert it */
154 }
155
156 /* Return either 0 bytes copied (failure == false) or conversion status */
157 return ErrorCode;
158}
ULONG WINAPI Dns_StringCopy(OUT PVOID Destination, IN OUT PULONG DestinationSize, IN PVOID String, IN ULONG StringSize OPTIONAL, IN DWORD InputType, IN DWORD OutputType)
Definition: string.c:17
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
BOOLEAN WINAPI Dns_Ip4ReverseNameToAddress_A(OUT PIN_ADDR Address, IN LPSTR Name)
Definition: straddr.c:40
int32_t INT
Definition: typedefs.h:58
char CHAR
Definition: xmlstorage.h:175

◆ Dns_Ip6AddressToReverseName_W()

LPWSTR WINAPI Dns_Ip6AddressToReverseName_W ( OUT LPWSTR  Name,
IN IN6_ADDR  Address 
)

Definition at line 17 of file straddr.c.

19{
20 /* FIXME */
21 return NULL;
22}

◆ Dns_ReverseNameToDnsAddr_W()

BOOLEAN WINAPI Dns_ReverseNameToDnsAddr_W ( OUT PDNS_ADDRESS  DnsAddr,
IN LPWSTR  Name 
)

Definition at line 452 of file straddr.c.

454{
455 /* Call the common API */
456 return Dns_StringToDnsAddrEx(DnsAddr,
457 Name,
458 AF_UNSPEC,
459 TRUE,
460 TRUE);
461}
#define TRUE
Definition: types.h:120
BOOLEAN WINAPI Dns_StringToDnsAddrEx(OUT PDNS_ADDRESS DnsAddr, IN PVOID AddressName, IN DWORD AddressFamily, IN BOOLEAN Unicode, IN BOOLEAN Reverse)
Definition: straddr.c:319
#define AF_UNSPEC
Definition: winsock.h:344

Referenced by SaBlob_CreateFromRecords().

◆ Dns_StringCopy()

ULONG WINAPI Dns_StringCopy ( OUT PVOID  Destination,
IN OUT PULONG  DestinationSize,
IN PVOID  String,
IN ULONG StringSize  OPTIONAL,
IN DWORD  InputType,
IN DWORD  OutputType 
)

Definition at line 17 of file string.c.

23{
24 ULONG DestSize;
25 ULONG OutputSize = 0;
26
27 /* Check if the caller already gave us the string size */
28 if (!StringSize)
29 {
30 /* He didn't, get the input type */
31 if (InputType == UnicodeString)
32 {
33 /* Unicode string, calculate the size */
34 StringSize = (ULONG)wcslen((LPWSTR)String);
35 }
36 else
37 {
38 /* ANSI or UTF-8 sting, get the size */
39 StringSize = (ULONG)strlen((LPSTR)String);
40 }
41 }
42
43 /* Check if we have a limit on the desination size */
44 if (DestinationSize)
45 {
46 /* Make sure that we can respect it */
48 StringSize,
49 InputType,
50 OutputType);
51 if (*DestinationSize < DestSize)
52 {
53 /* Fail due to missing buffer space */
55
56 /* Return how much data we actually need */
57 *DestinationSize = DestSize;
58 return 0;
59 }
60 else if (!DestSize)
61 {
62 /* Fail due to invalid data */
64 return 0;
65 }
66
67 /* Return how much data we actually need */
68 *DestinationSize = DestSize;
69 }
70
71 /* Now check if this is a Unicode String as input */
72 if (InputType == UnicodeString)
73 {
74 /* Check if the output is ANSI */
75 if (OutputType == AnsiString)
76 {
77 /* Convert and return the final desination size */
78 OutputSize = WideCharToMultiByte(CP_ACP,
79 0,
80 String,
81 StringSize,
83 -1,
84 NULL,
85 NULL) + 1;
86 }
87 else if (OutputType == UnicodeString)
88 {
89 /* Copy the string */
90 StringSize = StringSize * sizeof(WCHAR);
91 RtlMoveMemory(Destination, String, StringSize);
92
93 /* Return output length */
94 OutputSize = StringSize + 2;
95 }
96 else if (OutputType == Utf8String)
97 {
98 /* FIXME */
99 OutputSize = 0;
100 }
101 }
102 else if (InputType == AnsiString)
103 {
104 /* It's ANSI, is the output ansi too? */
105 if (OutputType == AnsiString)
106 {
107 /* Copy the string */
108 RtlMoveMemory(Destination, String, StringSize);
109
110 /* Return output length */
111 OutputSize = StringSize + 1;
112 }
113 else if (OutputType == UnicodeString)
114 {
115 /* Convert to Unicode and return size */
116 OutputSize = MultiByteToWideChar(CP_ACP,
117 0,
118 String,
119 StringSize,
121 -1) * sizeof(WCHAR) + 2;
122 }
123 else if (OutputType == Utf8String)
124 {
125 /* FIXME */
126 OutputSize = 0;
127 }
128 }
129 else if (InputType == Utf8String)
130 {
131 /* FIXME */
132 OutputSize = 0;
133 }
134
135 /* Return the output size */
136 return OutputSize;
137}
#define ERROR_MORE_DATA
Definition: dderror.h:13
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3016
ULONG WINAPI Dns_GetBufferLengthForStringCopy(IN PVOID String, IN ULONG Size OPTIONAL, IN DWORD InputType, IN DWORD OutputType)
Definition: string.c:176
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define ERROR_INVALID_DATA
Definition: winerror.h:116
char * LPSTR
Definition: xmlstorage.h:182

Referenced by Dns_Ip4ReverseNameToAddress_W(), Dns_Ip4StringToAddress_W(), Dns_StringToAddressEx(), Dns_StringToDnsAddrEx(), and SaBlob_CreateHostent().

◆ Dns_StringToAddressW()

BOOLEAN WINAPI Dns_StringToAddressW ( OUT PVOID  Address,
IN OUT PULONG  AddressSize,
IN LPWSTR  AddressName,
IN OUT PDWORD  AddressFamily 
)

Definition at line 303 of file straddr.c.

307{
308 /* Call the common API */
310 AddressSize,
311 AddressName,
313 TRUE,
314 FALSE);
315}
#define FALSE
Definition: types.h:117
IN PCO_ADDRESS_FAMILY AddressFamily
Definition: ndis.h:1906
BOOLEAN WINAPI Dns_StringToAddressEx(OUT PVOID Address, IN OUT PULONG AddressSize, IN PVOID AddressName, IN OUT PDWORD AddressFamily, IN BOOLEAN Unicode, IN BOOLEAN Reverse)
Definition: straddr.c:162

◆ DnsAddr_BuildFromDnsRecord()

BOOLEAN WINAPI DnsAddr_BuildFromDnsRecord ( IN PDNS_RECORD  DnsRecord,
OUT PDNS_ADDRESS  DnsAddr 
)

Definition at line 155 of file dnsaddr.c.

157{
158 /* Check what kind of record this is */
159 switch(DnsRecord->wType)
160 {
161 /* IPv4 */
162 case DNS_TYPE_A:
163 /* Create the DNS Address */
164 DnsAddr_BuildFromIp4(DnsAddr,
165 *(PIN_ADDR)&DnsRecord->Data.A.IpAddress,
166 0);
167 break;
168
169 /* IPv6 */
170 case DNS_TYPE_AAAA:
171 /* Create the DNS Address */
172 DnsAddr_BuildFromIp6(DnsAddr,
173 (PIN6_ADDR)&DnsRecord->Data.AAAA.Ip6Address,
174 DnsRecord->dwReserved,
175 0);
176 break;
177
178 /* ATM */
179 case DNS_TYPE_ATMA:
180 /* Create the DNS Address */
181 DnsAddr_BuildFromAtm(DnsAddr,
182 DnsRecord->Data.Atma.AddressType,
183 &DnsRecord->Data.Atma.Address);
184 break;
185 }
186
187 /* Done! */
188 return TRUE;
189}
VOID WINAPI DnsAddr_BuildFromIp4(IN PDNS_ADDRESS DnsAddress, IN IN_ADDR Address, IN WORD Port)
Definition: dnsaddr.c:100
VOID WINAPI DnsAddr_BuildFromAtm(IN PDNS_ADDRESS DnsAddress, IN DWORD AddressType, IN PVOID AddressData)
Definition: dnsaddr.c:134
VOID WINAPI DnsAddr_BuildFromIp6(IN PDNS_ADDRESS DnsAddress, IN PIN6_ADDR Address, IN ULONG ScopeId, IN WORD Port)
Definition: dnsaddr.c:116
Definition: tcpip.h:126
#define DNS_TYPE_ATMA
Definition: windns.h:74
#define DNS_TYPE_AAAA
Definition: windns.h:68
#define DNS_TYPE_A
Definition: windns.h:41

Referenced by SaBlob_WriteRecords().

◆ DnsAddr_BuildFromIp4()

VOID WINAPI DnsAddr_BuildFromIp4 ( IN PDNS_ADDRESS  DnsAddress,
IN IN_ADDR  Address,
IN WORD  Unknown 
)

Definition at line 100 of file dnsaddr.c.

103{
104 /* Clear the address */
105 RtlZeroMemory(DnsAddress, sizeof(DNS_ADDRESS));
106
107 /* Write data */
108 DnsAddress->Ip4Address.sin_family = AF_INET;
109 DnsAddress->Ip4Address.sin_port = Port;
110 DnsAddress->Ip4Address.sin_addr = Address;
111 DnsAddress->AddressLength = sizeof(SOCKADDR_IN);
112}
#define AF_INET
Definition: tcpip.h:117
CPPORT Port[4]
Definition: headless.c:35
struct sockaddr_in SOCKADDR_IN
Definition: winsock.h:487

Referenced by Dns_StringToDnsAddrEx(), DnsAddr_BuildFromDnsRecord(), and DnsAddrArray_AddIp4().

◆ DnsAddr_BuildFromIp6()

VOID WINAPI DnsAddr_BuildFromIp6 ( IN PDNS_ADDRESS  DnsAddress,
IN PIN6_ADDR  Address,
IN ULONG  ScopeId,
IN WORD  Port 
)

Definition at line 116 of file dnsaddr.c.

120{
121 /* Clear the address */
122 RtlZeroMemory(DnsAddress, sizeof(DNS_ADDRESS));
123
124 /* Write data */
125 DnsAddress->Ip6Address.sin6_family = AF_INET6;
126 DnsAddress->Ip6Address.sin6_port = Port;
127 DnsAddress->Ip6Address.sin6_addr = *Address;
128 DnsAddress->Ip6Address.sin6_scope_id = ScopeId;
129 DnsAddress->AddressLength = sizeof(SOCKADDR_IN6);
130}
#define AF_INET6
Definition: winsock.h:369
SOCKADDR_IN6_LH SOCKADDR_IN6
Definition: ws2ipdef.h:199

Referenced by Dns_StringToDnsAddrEx(), and DnsAddr_BuildFromDnsRecord().

◆ DnsAddrArray_AddAddr()

BOOL WINAPI DnsAddrArray_AddAddr ( IN PDNS_ARRAY  DnsAddrArray,
IN PDNS_ADDRESS  DnsAddress,
IN WORD AddressFamily  OPTIONAL,
IN DWORD AddressType  OPTIONAL 
)

Definition at line 57 of file dnsaddr.c.

61{
62 /* Make sure we have an array */
63 if (!DnsAddrArray) return FALSE;
64
65 /* Check if we should validate the Address Family */
66 if (AddressFamily)
67 {
68 /* Validate it */
69 if (AddressFamily != DnsAddress->AddressFamily) return TRUE;
70 }
71
72 /* Check if we should validate the Address Type */
73 if (AddressType)
74 {
75 /* Make sure that this array contains this type of addresses */
76 if (!DnsAddrArray_ContainsAddr(DnsAddrArray, DnsAddress, AddressType))
77 {
78 /* Won't be adding it */
79 return TRUE;
80 }
81 }
82
83 /* Make sure we have space in the array */
84 if (DnsAddrArray->AllocatedAddresses < DnsAddrArray->UsedAddresses)
85 {
86 return FALSE;
87 }
88
89 /* Now add the address */
90 RtlCopyMemory(&DnsAddrArray->Addresses[DnsAddrArray->UsedAddresses],
91 DnsAddress,
92 sizeof(DNS_ADDRESS));
93
94 /* Return success */
95 return TRUE;
96}
BOOL WINAPI DnsAddrArray_ContainsAddr(IN PDNS_ARRAY DnsAddrArray, IN PDNS_ADDRESS DnsAddress, IN DWORD AddressType)
Definition: dnsaddr.c:193

Referenced by DnsAddrArray_AddIp4(), and SaBlob_WriteAddress().

◆ DnsAddrArray_AddIp4()

BOOL WINAPI DnsAddrArray_AddIp4 ( IN PDNS_ARRAY  DnsAddrArray,
IN IN_ADDR  Address,
IN DWORD  AddressType 
)

Definition at line 42 of file dnsaddr.c.

45{
46 DNS_ADDRESS DnsAddress;
47
48 /* Build the DNS Address */
49 DnsAddr_BuildFromIp4(&DnsAddress, Address, 0);
50
51 /* Add it to the array */
52 return DnsAddrArray_AddAddr(DnsAddrArray, &DnsAddress, 0, AddressType);
53}
BOOL WINAPI DnsAddrArray_AddAddr(IN PDNS_ARRAY DnsAddrArray, IN PDNS_ADDRESS DnsAddress, IN WORD AddressFamily OPTIONAL, IN DWORD AddressType OPTIONAL)
Definition: dnsaddr.c:57

Referenced by SaBlob_CreateFromIp4().

◆ DnsAddrArray_ContainsAddr()

BOOL WINAPI DnsAddrArray_ContainsAddr ( IN PDNS_ARRAY  DnsAddrArray,
IN PDNS_ADDRESS  DnsAddress,
IN DWORD  AddressType 
)

Definition at line 193 of file dnsaddr.c.

196{
197 /* FIXME */
198 return TRUE;
199}

Referenced by DnsAddrArray_AddAddr().

◆ DnsAddrArray_Create()

PDNS_ARRAY WINAPI DnsAddrArray_Create ( ULONG  Count)

Definition at line 17 of file dnsaddr.c.

18{
19 PDNS_ARRAY DnsAddrArray;
20
21 /* Allocate space for the array and the addresses within it */
22 DnsAddrArray = Dns_AllocZero(sizeof(DNS_ARRAY) +
23 (Count * sizeof(DNS_ADDRESS)));
24
25 /* Write the allocated address count */
26 if (DnsAddrArray) DnsAddrArray->AllocatedAddresses = Count;
27
28 /* Return it */
29 return DnsAddrArray;
30}
int Count
Definition: noreturn.cpp:7
ULONG AllocatedAddresses
Definition: dnslib.h:57

Referenced by SaBlob_Create(), and SaBlob_WriteAddress().

◆ DnsAddrArray_Free()

VOID WINAPI DnsAddrArray_Free ( IN PDNS_ARRAY  DnsAddrArray)

Definition at line 34 of file dnsaddr.c.

35{
36 /* Just free the entire array */
37 Dns_Free(DnsAddrArray);
38}
VOID WINAPI Dns_Free(IN PVOID Address)
Definition: memory.c:25

Referenced by SaBlob_Free().

◆ FamilyInfo_GetForFamily()

PDNS_FAMILY_INFO WINAPI FamilyInfo_GetForFamily ( IN WORD  AddressFamily)

Definition at line 42 of file addr.c.

43{
44 /* Check which family this is */
45 switch (AddressFamily)
46 {
47 case AF_INET:
48 /* Return IPv4 Family Info */
49 return &AddrFamilyTable[0];
50
51 case AF_INET6:
52 /* Return IPv6 Family Info */
53 return &AddrFamilyTable[1];
54
55 case AF_ATM:
56 /* Return ATM Family Info */
57 return &AddrFamilyTable[2];
58
59 default:
60 /* Invalid family */
61 return NULL;
62 }
63
64}
DNS_FAMILY_INFO AddrFamilyTable[3]
Definition: addr.c:13
#define AF_ATM
Definition: winsock.h:368

Referenced by SaBlob_CreateHostent().

◆ FlatBuf_Arg_CopyMemory()

PVOID WINAPI FlatBuf_Arg_CopyMemory ( IN OUT PULONG_PTR  Position,
IN OUT PSIZE_T  FreeSize,
IN PVOID  Buffer,
IN SIZE_T  Size,
IN ULONG  Align 
)

Definition at line 60 of file flatbuf.c.

65{
67
68 /* First reserve the memory */
70 if (Destination)
71 {
72 /* We have space, do the copy */
74 }
75
76 /* Return the pointer to the data */
77 return Destination;
78}
int Align(int arg)
Definition: ehframes.cpp:89
PVOID WINAPI FlatBuf_Arg_Reserve(IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN SIZE_T Size, IN ULONG Align)
Definition: flatbuf.c:32
static COORD Position
Definition: mouse.c:34

◆ FlatBuf_Arg_Reserve()

PVOID WINAPI FlatBuf_Arg_Reserve ( IN OUT PULONG_PTR  Position,
IN OUT PSIZE_T  FreeSize,
IN SIZE_T  Size,
IN ULONG  Align 
)

Definition at line 32 of file flatbuf.c.

36{
37 ULONG_PTR NewPosition, OldPosition = *Position;
38 SIZE_T NewFreeSize = *FreeSize;
39
40 /* Start by aligning our position */
41 if (Align) OldPosition += (Align - 1) & ~Align;
42
43 /* Update it */
44 NewPosition = OldPosition + Size;
45
46 /* Update Free Size */
47 NewFreeSize += (OldPosition - NewPosition);
48
49 /* Save new values */
50 *Position = NewPosition;
51 *FreeSize = NewFreeSize;
52
53 /* Check if we're out of space or not */
54 if (NewFreeSize > 0) return (PVOID)OldPosition;
55 return NULL;
56}
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by FlatBuf_Arg_CopyMemory(), FlatBuf_Arg_ReserveAlignPointer(), and FlatBuf_Arg_WriteString().

◆ FlatBuf_Arg_WriteString()

PVOID WINAPI FlatBuf_Arg_WriteString ( IN OUT PULONG_PTR  Position,
IN OUT PSIZE_T  FreeSize,
IN PVOID  String,
IN BOOLEAN  IsUnicode 
)

Definition at line 82 of file flatbuf.c.

86{
88 SIZE_T StringLength;
90
91 /* Calculate the string length */
92 if (IsUnicode)
93 {
94 /* Get the length in bytes and use WCHAR alignment */
95 StringLength = (wcslen((LPWSTR)String) + 1) * sizeof(WCHAR);
96 Align = sizeof(WCHAR);
97 }
98 else
99 {
100 /* Get the length in bytes and use CHAR alignment */
101 StringLength = strlen((LPSTR)String) + 1;
102 Align = sizeof(CHAR);
103 }
104
105 /* Now reserve the memory */
106 Destination = FlatBuf_Arg_Reserve(Position, FreeSize, StringLength, Align);
107 if (Destination)
108 {
109 /* We have space, do the copy */
110 RtlCopyMemory(Destination, String, StringLength);
111 }
112
113 /* Return the pointer to the data */
114 return Destination;
115}
#define CHAR(Char)

◆ FlatBuf_Init()

VOID WINAPI FlatBuf_Init ( IN PFLATBUFF  FlatBuffer,
IN PVOID  Buffer,
IN SIZE_T  Size 
)

Definition at line 17 of file flatbuf.c.

20{
21 /* Set up the Flat Buffer start, current and ending position */
22 FlatBuffer->Buffer = Buffer;
23 FlatBuffer->BufferPos = (ULONG_PTR)Buffer;
24 FlatBuffer->BufferEnd = (PVOID)(FlatBuffer->BufferPos + Size);
25
26 /* Setup the current size and the available size */
27 FlatBuffer->BufferSize = FlatBuffer->BufferFreeSize = Size;
28}
#define ULONG_PTR
Definition: config.h:101
void * PVOID
Definition: typedefs.h:50

◆ Hostent_ConvertToOffsets()

VOID WINAPI Hostent_ConvertToOffsets ( IN PHOSTENT  Hostent)

Definition at line 71 of file hostent.c.

72{
73 /* Do we have a name? */
74 if (Hostent->h_name)
75 {
76 /* Update it */
77 Hostent->h_name -= (ULONG_PTR)Hostent;
78 }
79
80 /* Do we have aliases? */
81 if (Hostent->h_aliases)
82 {
83 /* Update the pointer */
84 Hostent->h_aliases -= (ULONG_PTR)Hostent;
85
86 /* Fix them up */
87 Dns_PtrArrayToOffsetArray(Hostent->h_aliases, (ULONG_PTR)Hostent);
88 }
89
90 /* Do we have addresses? */
91 if (Hostent->h_addr_list)
92 {
93 /* Fix them up */
94 Dns_PtrArrayToOffsetArray(Hostent->h_addr_list, (ULONG_PTR)Hostent);
95 }
96}
VOID WINAPI Dns_PtrArrayToOffsetArray(PCHAR *List, ULONG_PTR Base)
Definition: hostent.c:58

Referenced by SaBlob_CreateHostent().

◆ Hostent_Init()

PHOSTENT WINAPI Hostent_Init ( IN PVOID Buffer,
IN WORD  AddressFamily,
IN ULONG  AddressSize,
IN ULONG  AddressCount,
IN ULONG  AliasCount 
)

Definition at line 17 of file hostent.c.

22{
23 PHOSTENT Hostent;
24 ULONG_PTR BufferPosition = (ULONG_PTR)*Buffer;
25
26 /* Align the hostent on the buffer's 4 byte boundary */
27 BufferPosition += 3 & ~3;
28
29 /* Set up the basic data */
30 Hostent = (PHOSTENT)BufferPosition;
31 Hostent->h_length = (WORD)AddressSize;
32 Hostent->h_addrtype = AddressFamily;
33
34 /* Put aliases after Hostent */
35 Hostent->h_aliases = (PCHAR*)((ULONG_PTR)(Hostent + 1) & ~3);
36
37 /* Zero it out */
38 RtlZeroMemory(Hostent->h_aliases, AliasCount * sizeof(PCHAR));
39
40 /* Put addresses after aliases */
41 Hostent->h_addr_list = (PCHAR*)
42 ((ULONG_PTR)Hostent->h_aliases +
43 (AliasCount * sizeof(PCHAR)) + sizeof(PCHAR));
44
45 /* Update the location */
46 BufferPosition = (ULONG_PTR)Hostent->h_addr_list +
47 ((AddressCount * sizeof(PCHAR)) + sizeof(PCHAR));
48
49 /* Send it back */
50 *Buffer = (PVOID)BufferPosition;
51
52 /* Return the hostent */
53 return Hostent;
54}
unsigned short WORD
Definition: ntddk_ex.h:93
#define PCHAR
Definition: match.c:90
short h_length
Definition: winsock.h:137
char ** h_aliases
Definition: winsock.h:135
short h_addrtype
Definition: winsock.h:136
char ** h_addr_list
Definition: winsock.h:138
char * PCHAR
Definition: typedefs.h:51
struct hostent * PHOSTENT
Definition: winsock.h:497

Referenced by SaBlob_CreateHostent().

◆ SaBlob_Create()

PDNS_BLOB WINAPI SaBlob_Create ( IN ULONG  Count)

Definition at line 27 of file sablob.c.

28{
29 PDNS_BLOB Blob;
30 PDNS_ARRAY DnsAddrArray;
31
32 /* Allocate the blob */
33 Blob = Dns_AllocZero(sizeof(DNS_BLOB));
34 if (Blob)
35 {
36 /* Check if it'll hold any addresses */
37 if (Count)
38 {
39 /* Create the DNS Address Array */
40 DnsAddrArray = DnsAddrArray_Create(Count);
41 if (!DnsAddrArray)
42 {
43 /* Failure, free the blob */
44 SaBlob_Free(Blob);
46 }
47 else
48 {
49 /* Link it with the blob */
50 Blob->DnsAddrArray = DnsAddrArray;
51 }
52 }
53 }
54
55 /* Return the blob */
56 return Blob;
57}
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
PDNS_ARRAY WINAPI DnsAddrArray_Create(ULONG Count)
Definition: dnsaddr.c:17
VOID WINAPI SaBlob_Free(IN PDNS_BLOB Blob)
Definition: sablob.c:103
PDNS_ARRAY DnsAddrArray
Definition: dnslib.h:66

Referenced by SaBlob_CreateFromIp4(), and SaBlob_CreateFromRecords().

◆ SaBlob_CreateFromIp4()

PDNS_BLOB WINAPI SaBlob_CreateFromIp4 ( IN LPWSTR  Name,
IN ULONG  Count,
IN PIN_ADDR  AddressArray 
)

Definition at line 61 of file sablob.c.

64{
65 PDNS_BLOB Blob;
66 LPWSTR NameCopy;
67 ULONG i;
68
69 /* Create the blob */
70 Blob = SaBlob_Create(Count);
71 if (!Blob) goto Quickie;
72
73 /* If we have a name */
74 if (Name)
75 {
76 /* Create a copy of it */
77 NameCopy = Dns_CreateStringCopy_W(Name);
78 if (!NameCopy) goto Quickie;
79
80 /* Save the pointer to the name */
81 Blob->Name = NameCopy;
82 }
83
84 /* Loop all the addresses */
85 for (i = 0; i < Count; i++)
86 {
87 /* Add an entry for this address */
88 DnsAddrArray_AddIp4(Blob->DnsAddrArray, AddressArray[i], IpV4Address);
89 }
90
91 /* Return the blob */
92 return Blob;
93
94Quickie:
95 /* Free the blob, set error and fail */
96 SaBlob_Free(Blob);
98 return NULL;
99}
BOOL WINAPI DnsAddrArray_AddIp4(IN PDNS_ARRAY DnsAddrArray, IN IN_ADDR Address, IN DWORD AddressType)
Definition: dnsaddr.c:42
#define IpV4Address
Definition: dnslib.h:22
LPWSTR WINAPI Dns_CreateStringCopy_W(IN LPWSTR Name)
Definition: string.c:141
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
Definition: glfuncs.h:248
PDNS_BLOB WINAPI SaBlob_Create(IN ULONG Count)
Definition: sablob.c:27
LPWSTR Name
Definition: dnslib.h:65

◆ SaBlob_CreateHostent()

PHOSTENT WINAPI SaBlob_CreateHostent ( IN OUT PULONG_PTR  BufferPosition,
IN OUT PSIZE_T  RemainingBufferSpace,
IN OUT PSIZE_T  HostEntrySize,
IN PDNS_BLOB  Blob,
IN DWORD  StringType,
IN BOOLEAN  Relative,
IN BOOLEAN  BufferAllocated 
)

Definition at line 131 of file sablob.c.

138{
139 PDNS_ARRAY DnsAddrArray = Blob->DnsAddrArray;
140 ULONG AliasCount = Blob->AliasCount;
142 ULONG AddressCount = 0, AddressSize = 0, TotalSize, NamePointerSize;
143 ULONG AliasPointerSize;
144 PDNS_FAMILY_INFO FamilyInfo = NULL;
145 ULONG StringLength = 0;
146 ULONG i;
147 ULONG HostentSize = 0;
148 PHOSTENT Hostent = NULL;
149 ULONG_PTR HostentPtr;
150 PVOID CurrentAddress;
151
152 /* Check if we actually have any addresses */
153 if (DnsAddrArray)
154 {
155 /* Get the address family */
156 AddressFamily = DnsAddrArray->Addresses[0].AddressFamily;
157
158 /* Get family information */
160
161 /* Save the current address count and their size */
162 AddressCount = DnsAddrArray->UsedAddresses;
163 AddressSize = FamilyInfo->AddressSize;
164 }
165
166 /* Calculate total size for all the addresses, and their pointers */
167 TotalSize = AddressSize * AddressCount;
168 NamePointerSize = AddressCount * sizeof(PVOID) + sizeof(PVOID);
169
170 /* Check if we have a name */
171 if (Blob->Name)
172 {
173 /* Find out the size we'll need for a copy */
174 StringLength = (Dns_GetBufferLengthForStringCopy(Blob->Name,
175 0,
177 StringType) + 1) & ~1;
178 }
179
180 /* Now do the same for the aliases */
181 for (i = AliasCount; i; i--)
182 {
183 /* Find out the size we'll need for a copy */
184 HostentSize += (Dns_GetBufferLengthForStringCopy(Blob->Aliases[i],
185 0,
187 StringType) + 1) & ~1;
188 }
189
190 /* Find out how much the pointers will take */
191 AliasPointerSize = AliasCount * sizeof(PVOID) + sizeof(PVOID);
192
193 /* Calculate Hostent Size */
194 HostentSize += TotalSize +
195 NamePointerSize +
196 AliasPointerSize +
197 StringLength +
198 sizeof(HOSTENT);
199
200 /* Check if we already have a buffer */
201 if (!BufferAllocated)
202 {
203 /* We don't, allocate space ourselves */
204 HostentPtr = (ULONG_PTR)Dns_AllocZero(HostentSize);
205 }
206 else
207 {
208 /* We do, so allocate space in the buffer */
209 HostentPtr = (ULONG_PTR)FlatBuf_Arg_ReserveAlignPointer(BufferPosition,
210 FreeBufferSpace,
211 HostentSize);
212 }
213
214 /* Make sure we got space */
215 if (HostentPtr)
216 {
217 /* Initialize it */
218 Hostent = Hostent_Init((PVOID)&HostentPtr,
220 AddressSize,
221 AddressCount,
222 AliasCount);
223 }
224
225 /* Loop the addresses */
226 for (i = 0; i < AddressCount; i++)
227 {
228 /* Get the pointer of the current address */
229 CurrentAddress = (PVOID)((ULONG_PTR)&DnsAddrArray->Addresses[i] +
230 FamilyInfo->AddressOffset);
231
232 /* Write the pointer */
233 Hostent->h_addr_list[i] = (PCHAR)HostentPtr;
234
235 /* Copy the address */
236 RtlCopyMemory((PVOID)HostentPtr, CurrentAddress, AddressSize);
237
238 /* Advance the buffer */
239 HostentPtr += AddressSize;
240 }
241
242 /* Check if we have a name */
243 if (Blob->Name)
244 {
245 /* Align our current position */
246 HostentPtr += 1 & ~1;
247
248 /* Save our name here */
249 Hostent->h_name = (LPSTR)HostentPtr;
250
251 /* Now copy it in the blob */
252 HostentPtr += Dns_StringCopy((PVOID)HostentPtr,
253 NULL,
254 Blob->Name,
255 0,
257 StringType);
258 }
259
260 /* Loop the Aliases */
261 for (i = AliasCount; i; i--)
262 {
263 /* Align our current position */
264 HostentPtr += 1 & ~1;
265
266 /* Save our alias here */
267 Hostent->h_aliases[i] = (LPSTR)HostentPtr;
268
269 /* Now copy it in the blob */
270 HostentPtr += Dns_StringCopy((PVOID)HostentPtr,
271 NULL,
272 Blob->Aliases[i],
273 0,
275 StringType);
276 }
277
278 /* Check if the caller didn't have a buffer */
279 if (!BufferAllocated)
280 {
281 /* Return the size; not needed if we had a blob, since it's internal */
282 *HostEntrySize = *BufferPosition - (ULONG_PTR)HostentPtr;
283 }
284
285 /* Convert to Offsets if requested */
286 if(Relative) Hostent_ConvertToOffsets(Hostent);
287
288 /* Return the full, complete, hostent */
289 return Hostent;
290}
PDNS_FAMILY_INFO WINAPI FamilyInfo_GetForFamily(IN WORD AddressFamily)
Definition: addr.c:42
ULONG WINAPI Dns_GetBufferLengthForStringCopy(IN PVOID String, IN ULONG Size OPTIONAL, IN DWORD InputType, IN DWORD OutputType)
Definition: string.c:176
PHOSTENT WINAPI Hostent_Init(IN PVOID *Buffer, IN WORD AddressFamily, IN ULONG AddressSize, IN ULONG AddressCount, IN ULONG AliasCount)
Definition: hostent.c:17
VOID WINAPI Hostent_ConvertToOffsets(IN PHOSTENT Hostent)
Definition: hostent.c:71
PVOID WINAPI FlatBuf_Arg_ReserveAlignPointer(IN PVOID Position, IN PSIZE_T FreeSize, IN SIZE_T Size)
Definition: sablob.c:17
WORD AddressFamily
Definition: dnslib.h:43
ULONG UsedAddresses
Definition: dnslib.h:58
DNS_ADDRESS Addresses[1]
Definition: dnslib.h:60
DWORD AddressSize
Definition: dnslib.h:77
DWORD AddressOffset
Definition: dnslib.h:79
char * h_name
Definition: winsock.h:134
struct hostent HOSTENT
Definition: winsock.h:496

◆ SaBlob_Free()

VOID WINAPI SaBlob_Free ( IN PDNS_BLOB  Blob)

Definition at line 103 of file sablob.c.

104{
105 /* Make sure we got a blob */
106 if (Blob)
107 {
108 /* Free the name */
109 Dns_Free(Blob->Name);
110
111 /* Loop the aliases */
112 while (Blob->AliasCount)
113 {
114 /* Free the alias */
115 Dns_Free(Blob->Aliases[Blob->AliasCount]);
116
117 /* Decrease number of aliases */
118 Blob->AliasCount--;
119 }
120
121 /* Free the DNS Address Array */
122 DnsAddrArray_Free(Blob->DnsAddrArray);
123
124 /* Free the blob itself */
125 Dns_Free(Blob);
126 }
127}
VOID WINAPI DnsAddrArray_Free(IN PDNS_ARRAY DnsAddrArray)
Definition: dnsaddr.c:34

Referenced by SaBlob_Create(), SaBlob_CreateFromIp4(), SaBlob_CreateFromRecords(), and SaBlob_Query().

◆ SaBlob_Query()

PDNS_BLOB WINAPI SaBlob_Query ( IN LPWSTR  Name,
IN WORD  DnsType,
IN ULONG  Flags,
IN PVOID Reserved,
IN DWORD  AddressFamily 
)

Definition at line 545 of file sablob.c.

550{
551 PDNS_RECORD DnsRecord = NULL;
553 PDNS_BLOB DnsBlob = NULL;
554 LPWSTR LocalName, LocalNameCopy;
555
556 /* If they want reserved data back, clear it out in case we fail */
557 if (Reserved) *Reserved = NULL;
558
559 /* Query DNS */
561 DnsType,
562 Flags,
563 NULL,
564 &DnsRecord,
565 Reserved);
567 {
568 /* We failed... did the caller use reserved data? */
569 if (Reserved && *Reserved)
570 {
571 /* He did, and it was valid. Free it */
573 *Reserved = NULL;
574 }
575
576 /* Normalize error code */
578 goto Quickie;
579 }
580
581 /* Now create the Blob from the DNS Records */
582 DnsBlob = SaBlob_CreateFromRecords(DnsRecord, TRUE, DnsType);
583 if (!DnsBlob)
584 {
585 /* Failed, get error code */
587 goto Quickie;
588 }
589
590 /* Make sure it has a name */
591 if (!DnsBlob->Name)
592 {
593 /* It doesn't, fail */
595 goto Quickie;
596 }
597
598 /* Check if the name is local or loopback */
599 if (!(DnsNameCompare_W(DnsBlob->Name, L"localhost")) &&
600 !(DnsNameCompare_W(DnsBlob->Name, L"loopback")))
601 {
602 /* Nothing left to do, exit! */
603 goto Quickie;
604 }
605
606 /* This is a local name...query it */
608 if (LocalName)
609 {
610 /* Create a copy for the caller */
611 LocalNameCopy = Dns_CreateStringCopy_W(LocalName);
612 if (LocalNameCopy)
613 {
614 /* Overwrite the one in the blob */
615 DnsBlob->Name = LocalNameCopy;
616 }
617 else
618 {
619 /* We failed to make a copy, free memory */
620 DnsApiFree(LocalName);
621 }
622 }
623
624Quickie:
625 /* Free the DNS Record if we have one */
626 if (DnsRecord) DnsRecordListFree(DnsRecord, DnsFreeRecordList);
627
628 /* Check if this is a failure path with an active blob */
629 if ((ErrorCode != ERROR_SUCCESS) && (DnsBlob))
630 {
631 /* Free the blob */
632 SaBlob_Free(DnsBlob);
633 DnsBlob = NULL;
634 }
635
636 /* Set the last error and return */
638 return DnsBlob;
639}
#define ERROR_SUCCESS
Definition: deptool.c:10
PVOID WINAPI DnsQueryConfigAllocEx(IN DNS_CONFIG_TYPE Config, OUT PVOID pBuffer, IN OUT PDWORD pBufferLength)
Definition: memory.c:32
VOID WINAPI DnsApiFree(IN PVOID Data)
Definition: memory.c:18
DNS_STATUS WINAPI DnsQuery_W(LPCWSTR Name, WORD Type, DWORD Options, PVOID Extra, PDNS_RECORD *QueryResultSet, PVOID *Reserved)
Definition: query.c:469
VOID WINAPI DnsRecordListFree(PDNS_RECORD list, DNS_FREE_TYPE type)
Definition: record.c:526
BOOL WINAPI DnsNameCompare_W(PCWSTR name1, PCWSTR name2)
Definition: names.c:51
PDNS_BLOB WINAPI SaBlob_CreateFromRecords(IN PDNS_RECORD DnsRecord, IN BOOLEAN DoAliases, IN DWORD DnsType)
Definition: sablob.c:446
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
@ DnsConfigFullHostName_W
Definition: windns.h:132
@ DnsFreeRecordList
Definition: windns.h:139
#define PDNS_RECORD
Definition: windns.h:636
#define WSATRY_AGAIN
Definition: winerror.h:2001
#define DNS_INFO_NO_RECORDS
Definition: winerror.h:1861
#define RPC_S_SERVER_UNAVAILABLE
Definition: winerror.h:1033
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

◆ SaBlob_WriteNameOrAlias()

INT WINAPI SaBlob_WriteNameOrAlias ( IN PDNS_BLOB  Blob,
IN LPWSTR  String,
IN BOOLEAN  IsAlias 
)

Definition at line 294 of file sablob.c.

297{
298 /* Check if this is an alias */
299 if (!IsAlias)
300 {
301 /* It's not. Simply create a copy of the string */
302 Blob->Name = Dns_CreateStringCopy_W(String);
303 if (!Blob->Name) return GetLastError();
304 }
305 else
306 {
307 /* Does it have a name, and less then 8 aliases? */
308 if ((Blob->Name) && (Blob->AliasCount <= 8))
309 {
310 /* Yup, create a copy of the string and increase the alias count */
311 Blob->Aliases[Blob->AliasCount] = Dns_CreateStringCopy_W(String);
312 Blob->AliasCount++;
313 }
314 else
315 {
316 /* Invalid request! */
317 return ERROR_MORE_DATA;
318 }
319 }
320
321 /* Return Success */
322 return ERROR_SUCCESS;
323}

Referenced by SaBlob_CreateFromRecords(), and SaBlob_WriteRecords().