mikroSDK Reference Manual
dns_common.h
Go to the documentation of this file.
1
31#ifndef _DNS_COMMON_H
32#define _DNS_COMMON_H
33
34//Dependencies
35#include "core/net.h"
36
37//Maximum recursion limit when parsing domain names
38#ifndef DNS_NAME_MAX_RECURSION
39 #define DNS_NAME_MAX_RECURSION 4
40#elif (DNS_NAME_MAX_RECURSION < 1 || DNS_NAME_MAX_RECURSION > 8)
41 #error DNS_NAME_MAX_RECURSION parameter is not valid
42#endif
43
44//Maximum size of DNS messages
45#define DNS_MESSAGE_MAX_SIZE 512
46//Maximum size of names
47#define DNS_NAME_MAX_SIZE 255
48//Maximum size of labels
49#define DNS_LABEL_MAX_SIZE 63
50
51//Maximum length of reverse DNS names (IPv4)
52#define DNS_MAX_IPV4_REVERSE_NAME_LEN 15
53//Maximum length of reverse DNS names (IPv6)
54#define DNS_MAX_IPV6_REVERSE_NAME_LEN 63
55
56//DNS port number
57#define DNS_PORT 53
58
59//Label compression tag
60#define DNS_COMPRESSION_TAG 0xC0
61
62//Macro definition
63#define DNS_GET_QUESTION(message, offset) (DnsQuestion *) ((uint8_t *) (message) + (offset))
64#define DNS_GET_RESOURCE_RECORD(message, offset) (DnsResourceRecord *) ((uint8_t *) (message) + (offset))
65
66#define DNS_SET_NSEC_BITMAP(bitmap, type) bitmap[(type) / 8] |= 0x80 >> ((type) % 8)
67#define DNS_CLR_NSEC_BITMAP(bitmap, type) bitmap[(type) / 8] &= ~(0x80 >> ((type) % 8))
68
69//C++ guard
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74
87
88
116
117
129
130
158
159
160//CodeWarrior or Win32 compiler?
161#if defined(__CWCC__) || defined(_WIN32)
162 #pragma pack(push, 1)
163#endif
164
165
171{
172 uint16_t id; //0-1
173#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
174 uint8_t qr : 1; //2
175 uint8_t opcode : 4;
176 uint8_t aa : 1;
177 uint8_t tc : 1;
178 uint8_t rd : 1;
179 uint8_t ra : 1; //3
180 uint8_t z : 3;
181 uint8_t rcode : 4;
182#else
183 uint8_t rd : 1; //2
184 uint8_t tc : 1;
185 uint8_t aa : 1;
186 uint8_t opcode : 4;
187 uint8_t qr : 1;
188 uint8_t rcode : 4; //3
189 uint8_t z : 3;
190 uint8_t ra : 1;
191#endif
192 uint16_t qdcount; //4-5
193 uint16_t ancount; //6-7
194 uint16_t nscount; //8-9
195 uint16_t arcount; //10-11
196 uint8_t questions[]; //12
197} DnsHeader;
198
199
204typedef __packed_struct
205{
206 uint16_t qtype;
207 uint16_t qclass;
208} DnsQuestion;
209
210
215typedef __packed_struct
216{
217 uint16_t rtype; //0-1
218 uint16_t rclass; //2-3
219 uint32_t ttl; //4-7
220 uint16_t rdlength; //8-9
221 uint8_t rdata[]; //10
222} DnsResourceRecord;
223
224
229typedef __packed_struct
230{
231 uint16_t rtype; //0-1
232 uint16_t rclass; //2-3
233 uint32_t ttl; //4-7
234 uint16_t rdlength; //8-9
235 uint8_t rdata[4]; //10-13
236} DnsIpv4AddrResourceRecord;
237
238
243typedef __packed_struct
244{
245 uint16_t rtype; //0-1
246 uint16_t rclass; //2-3
247 uint32_t ttl; //4-7
248 uint16_t rdlength; //8-9
249 uint8_t rdata[16]; //10-25
250} DnsIpv6AddrResourceRecord;
251
252
257typedef __packed_struct
258{
259 uint16_t rtype; //0-1
260 uint16_t rclass; //2-3
261 uint32_t ttl; //4-7
262 uint16_t rdlength; //8-9
263 uint16_t priority; //10-11
264 uint16_t weight; //12-13
265 uint16_t port; //14-15
266 uint8_t target[]; //16
267} DnsSrvResourceRecord;
268
269
270//CodeWarrior or Win32 compiler?
271#if defined(__CWCC__) || defined(_WIN32)
272 #pragma pack(pop)
273#endif
274
275//DNS related functions
276size_t dnsEncodeName(const char_t *src, uint8_t *dest);
277
278size_t dnsParseName(const DnsHeader *message, size_t length, size_t pos,
279 char_t *dest, uint_t level);
280
281int_t dnsCompareName(const DnsHeader *message, size_t length, size_t pos,
282 const char_t *name, uint_t level);
283
284int_t dnsCompareEncodedName(const DnsHeader *message1, size_t length1,
285 size_t pos1, const DnsHeader *message2, size_t length2, size_t pos2,
286 uint_t level);
287
288void dnsGenerateIpv4ReverseName(Ipv4Addr ipv4Addr, char_t *buffer);
289void dnsGenerateIpv6ReverseName(const Ipv6Addr *ipv6Addr, char_t *buffer);
290
291//C++ guard
292#ifdef __cplusplus
293}
294#endif
295
296#endif
DnsResponseCode
DNS response codes.
Definition dns_common.h:94
@ DNS_RCODE_BADALG
Algorithm not supported.
Definition dns_common.h:112
@ DNS_RCODE_SERVFAIL
Server failure.
Definition dns_common.h:97
@ DNS_RCODE_BADKEY
Key not recognized.
Definition dns_common.h:108
@ DNS_RCODE_REFUSED
Query refused.
Definition dns_common.h:100
@ DNS_RCODE_NXRRSET
RR set that should exist does not.
Definition dns_common.h:103
@ DNS_RCODE_NXDOMAIN
Non-existent domain.
Definition dns_common.h:98
@ DNS_RCODE_BADVERS
Bad OPT version.
Definition dns_common.h:106
@ DNS_RCODE_BADTIME
Signature out of time window.
Definition dns_common.h:109
@ DNS_RCODE_BADNAME
Duplicate key name.
Definition dns_common.h:111
@ DNS_RCODE_BADCOOKIE
Bad server cookie.
Definition dns_common.h:114
@ DNS_RCODE_BADTRUC
Bad truncation.
Definition dns_common.h:113
@ DNS_RCODE_NOERROR
No error.
Definition dns_common.h:95
@ DNS_RCODE_NOTAUTH
Server not authoritative for zone.
Definition dns_common.h:104
@ DNS_RCODE_YXDOMAIN
Name exists when it should not.
Definition dns_common.h:101
@ DNS_RCODE_YXRRSET
RR set exists when it should not.
Definition dns_common.h:102
@ DNS_RCODE_BADMODE
Bad TKEY mode.
Definition dns_common.h:110
@ DNS_RCODE_NOTIMP
Not implemented.
Definition dns_common.h:99
@ DNS_RCODE_NOTZONE
Name not contained in zone.
Definition dns_common.h:105
@ DNS_RCODE_BADSIG
TSIG signature failure.
Definition dns_common.h:107
@ DNS_RCODE_FORMERR
Format error.
Definition dns_common.h:96
DnsOpcode
DNS opcodes.
Definition dns_common.h:80
@ DNS_OPCODE_NOTIFY
Notify.
Definition dns_common.h:84
@ DNS_OPCODE_IQUERY
Inverse query.
Definition dns_common.h:82
@ DNS_OPCODE_UPDATE
Update.
Definition dns_common.h:85
@ DNS_OPCODE_STATUS
Status.
Definition dns_common.h:83
@ DNS_OPCODE_QUERY
Query.
Definition dns_common.h:81
DnsResourceRecordType
DNS resource record types.
Definition dns_common.h:136
@ DNS_RR_TYPE_MX
Mail exchange.
Definition dns_common.h:145
@ DNS_RR_TYPE_PTR
Domain name pointer.
Definition dns_common.h:142
@ DNS_RR_TYPE_CNAME
Canonical name for an alias.
Definition dns_common.h:139
@ DNS_RR_TYPE_NB
NetBIOS name service.
Definition dns_common.h:148
@ DNS_RR_TYPE_SRV
Server selection.
Definition dns_common.h:149
@ DNS_RR_TYPE_WKS
Well known service description.
Definition dns_common.h:141
@ DNS_RR_TYPE_HINFO
Host information.
Definition dns_common.h:143
@ DNS_RR_TYPE_A
Host address.
Definition dns_common.h:137
@ DNS_RR_TYPE_AXFR
Transfer of an entire zone.
Definition dns_common.h:154
@ DNS_RR_TYPE_AAAA
IPv6 address.
Definition dns_common.h:147
@ DNS_RR_TYPE_EUI64
EUI-64 address.
Definition dns_common.h:153
@ DNS_RR_TYPE_TXT
Text strings.
Definition dns_common.h:146
@ DNS_RR_TYPE_ANY
A request for all records.
Definition dns_common.h:155
@ DNS_RR_TYPE_NS
Authoritative name server.
Definition dns_common.h:138
@ DNS_RR_TYPE_URI
Uniform resource identifier.
Definition dns_common.h:156
@ DNS_RR_TYPE_MINFO
Mailbox or mail list information.
Definition dns_common.h:144
@ DNS_RR_TYPE_NAPTR
Naming authority pointer.
Definition dns_common.h:150
@ DNS_RR_TYPE_NSEC
NSEC record.
Definition dns_common.h:151
@ DNS_RR_TYPE_SOA
Start of a zone of authority.
Definition dns_common.h:140
@ DNS_RR_TYPE_EUI48
EUI-48 address.
Definition dns_common.h:152
DnsResourceRecordClass
DNS resource record classes.
Definition dns_common.h:123
@ DNS_RR_CLASS_HS
Hesiod.
Definition dns_common.h:126
@ DNS_RR_CLASS_ANY
Any class.
Definition dns_common.h:127
@ DNS_RR_CLASS_CH
Chaos.
Definition dns_common.h:125
@ DNS_RR_CLASS_IN
Internet.
Definition dns_common.h:124
typedef __packed_struct
DNS message header.
Definition dns_common.h:171
uint32_t Ipv4Addr
IPv4 network address.
Definition ipv4.h:267
TCP/IP stack core.