-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdns.h
56 lines (48 loc) · 1.48 KB
/
dns.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef DNS_H
#define DNS_H
/* Contains the definitions of some common data structures used in DNS packets. */
#include <stdint.h>
#define DNS_QR_RESPONSE 0x8000
#define DNS_AUTH_ANS 0x0400
#define DNS_TRUNCATED 0x0200
#define DNS_USE_RECURSION 0x0100
#define DNS_RECURSION_AVAIL 0x0080
#define DNS_FORMAT_ERROR 0x0001
#define DNS_SERVER_FAILURE 0x0002
#define DNS_NAME_ERROR 0x0003
#define DNS_NOT_IMPLEMENTED 0x0004
#define DNS_REFUSED 0x0005
#define DNS_ERROR_MASK 0x000f
#define DNS_INET_ADDR 0x0001
#define DNS_A_RECORD 0x0001
#define DNS_NS_RECORD 0x0002
#define DNS_CNAME_RECORD 0x0005
#define DNS_MX_RECORD 0x000f
/* Specified in the RFC for DNS. */
#define MAX_DOMAIN_LENGTH 255
#define MAX_SUBDOMAIN_LENGTH 63
#define ERROR_BUFFER 100
struct dns_header {
uint16_t id;
uint16_t flags;
uint16_t qd_count;
uint16_t an_count;
uint16_t ns_count;
uint16_t ar_count;
};
struct dns_question_trailer {
uint16_t q_type;
uint16_t q_class;
};
/* Stores information from the response packet sent from the DNS server.
Only some of the fields will contain valid data, depending on the type
of response from the response_type field. */
struct dns_response {
uint16_t response_type; /* Either A, CNAME, MX, or NS. */
uint16_t preference; /* MX only. */
uint32_t cache_time; /* All. */
uint32_t ip_address; /* A only. */
char name[MAX_DOMAIN_LENGTH + 1]; /* CNAME, MX, and NS only. */
uint8_t authoritative; /* All. 0 false, 1 true. */
};
#endif /* DNS_H */