ReactOS 0.4.15-dev-8413-gc1c91f2
dnsaddr.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS DNS Shared Library
4 * FILE: lib/dnslib/dnsaddr.c
5 * PURPOSE: Functions dealing with DNS_ADDRESS and DNS_ARRAY addresses.
6 */
7
8/* INCLUDES ******************************************************************/
9#include "precomp.h"
10
11/* DATA **********************************************************************/
12
13/* FUNCTIONS *****************************************************************/
14
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}
31
32VOID
35{
36 /* Just free the entire array */
37 Dns_Free(DnsAddrArray);
38}
39
40BOOL
44 IN DWORD AddressType)
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}
54
55BOOL
58 IN PDNS_ADDRESS DnsAddress,
60 IN DWORD AddressType OPTIONAL)
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}
97
98VOID
102 IN WORD Port)
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}
113
114VOID
115WINAPI
118 IN ULONG ScopeId,
119 IN WORD Port)
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}
131
132VOID
133WINAPI
135 IN DWORD AddressType,
136 IN PVOID AddressData)
137{
139
140 /* Clear the address */
141 RtlZeroMemory(DnsAddress, sizeof(DNS_ADDRESS));
142
143 /* Build an ATM Address */
144 Address.AddressType = AddressType;
145 Address.NumofDigits = DNS_ATMA_MAX_ADDR_LENGTH;
147
148 /* Write data */
149 DnsAddress->AtmAddress = Address;
150 DnsAddress->AddressLength = sizeof(ATM_ADDRESS);
151}
152
154WINAPI
156 OUT PDNS_ADDRESS DnsAddr)
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}
190
191BOOL
192WINAPI
194 IN PDNS_ADDRESS DnsAddress,
195 IN DWORD AddressType)
196{
197 /* FIXME */
198 return TRUE;
199}
200
unsigned char BOOLEAN
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI DnsAddrArray_AddIp4(IN PDNS_ARRAY DnsAddrArray, IN IN_ADDR Address, IN DWORD AddressType)
Definition: dnsaddr.c:42
VOID WINAPI DnsAddr_BuildFromIp4(IN PDNS_ADDRESS DnsAddress, IN IN_ADDR Address, IN WORD Port)
Definition: dnsaddr.c:100
BOOLEAN WINAPI DnsAddr_BuildFromDnsRecord(IN PDNS_RECORD DnsRecord, OUT PDNS_ADDRESS DnsAddr)
Definition: dnsaddr.c:155
VOID WINAPI DnsAddrArray_Free(IN PDNS_ARRAY DnsAddrArray)
Definition: dnsaddr.c:34
BOOL WINAPI DnsAddrArray_ContainsAddr(IN PDNS_ARRAY DnsAddrArray, IN PDNS_ADDRESS DnsAddress, IN DWORD AddressType)
Definition: dnsaddr.c:193
VOID WINAPI DnsAddr_BuildFromAtm(IN PDNS_ADDRESS DnsAddress, IN DWORD AddressType, IN PVOID AddressData)
Definition: dnsaddr.c:134
BOOL WINAPI DnsAddrArray_AddAddr(IN PDNS_ARRAY DnsAddrArray, IN PDNS_ADDRESS DnsAddress, IN WORD AddressFamily OPTIONAL, IN DWORD AddressType OPTIONAL)
Definition: dnsaddr.c:57
PDNS_ARRAY WINAPI DnsAddrArray_Create(ULONG Count)
Definition: dnsaddr.c:17
VOID WINAPI DnsAddr_BuildFromIp6(IN PDNS_ADDRESS DnsAddress, IN PIN6_ADDR Address, IN ULONG ScopeId, IN WORD Port)
Definition: dnsaddr.c:116
PVOID WINAPI Dns_AllocZero(IN SIZE_T Size)
Definition: memory.c:42
VOID WINAPI Dns_Free(IN PVOID Address)
Definition: memory.c:25
#define AF_INET
Definition: tcpip.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
CPPORT Port[4]
Definition: headless.c:35
IN PCO_ADDRESS_FAMILY AddressFamily
Definition: ndis.h:1906
int Count
Definition: noreturn.cpp:7
static WCHAR Address[46]
Definition: ping.c:68
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
ULONG AllocatedAddresses
Definition: dnslib.h:57
Definition: tcpip.h:126
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define DNS_TYPE_ATMA
Definition: windns.h:74
#define DNS_TYPE_AAAA
Definition: windns.h:68
#define PDNS_RECORD
Definition: windns.h:636
#define DNS_ATMA_MAX_ADDR_LENGTH
Definition: windns.h:105
#define DNS_TYPE_A
Definition: windns.h:41
#define WINAPI
Definition: msvc.h:6
struct sockaddr_in SOCKADDR_IN
Definition: winsock.h:487
#define AF_INET6
Definition: winsock.h:369
SOCKADDR_IN6_LH SOCKADDR_IN6
Definition: ws2ipdef.h:199