-
Notifications
You must be signed in to change notification settings - Fork 6
/
DNS.h
134 lines (119 loc) · 3.73 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* XMail by Davide Libenzi (Intranet and Internet mail server)
* Copyright (C) 1999,..,2010 Davide Libenzi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Davide Libenzi <[email protected]>
*
*/
#ifndef _DNS_H
#define _DNS_H
#define DNS_QUERY_TCP 1
#define DNS_QUERY_UDP 2
#define DNS_STD_MAXDEPTH 32
#define QTYPE_A 1
#define QTYPE_NS 2
#define QTYPE_MD 3
#define QTYPE_MF 4
#define QTYPE_CNAME 5
#define QTYPE_SOA 6
#define QTYPE_MB 7
#define QTYPE_MG 8
#define QTYPE_MR 9
#define QTYPE_NULL 10
#define QTYPE_WKS 11
#define QTYPE_PTR 12
#define QTYPE_HINFO 13
#define QTYPE_MINFO 14
#define QTYPE_MX 15
#define QTYPE_TXT 16
#define QTYPE_AAAA 28
#define QTYPE_ANSWER_MAX 29
#define QTYPE_AXFR 252
#define QTYPE_MAILB 253
#define QTYPE_MAILA 254
#define QTYPE_ALL 255
#define QCLASS_IN 1
#define QCLASS_CS 2
#define QCLASS_CH 3
#define QCLASS_HS 4
#define QCLASS_ALL 255
#define RCODE_FORMAT 1
#define RCODE_SVRFAIL 2
#define RCODE_NXDOMAIN 3
#define RCODE_NOTSUPPORTED 4
#define RCODE_REFUSED 5
struct DNS_HEADER {
SYS_UINT16 Id;
#ifdef BIG_ENDIAN_BITFIELD
SYS_UINT8 QR:1, OpCode:4, AA:1, TC:1, RD:1;
SYS_UINT8 RA:1, Z:3, RCode:4;
#else
SYS_UINT8 RD:1, TC:1, AA:1, OpCode:4, QR:1;
SYS_UINT8 RCode:4, Z:3, RA:1;
#endif // #ifdef BIG_ENDIAN_BITFIELD
SYS_UINT16 QDCount;
SYS_UINT16 ANCount;
SYS_UINT16 NSCount;
SYS_UINT16 ARCount;
};
struct DNSRecord {
struct SysListHead Lnk;
char szName[MAX_HOST_NAME];
SYS_UINT32 TTL;
SYS_UINT32 Class;
union {
struct {
char szName[MAX_HOST_NAME];
} NAME;
struct {
char szName[MAX_HOST_NAME];
SYS_UINT16 Pref;
} MX;
struct {
SYS_UINT32 IAddr4;
} A;
struct {
SYS_UINT8 IAddr6[16];
} AAAA;
struct {
char szName[MAX_HOST_NAME];
char szAddr[MAX_ADDR_NAME];
SYS_UINT32 Serial;
SYS_UINT32 Refresh;
SYS_UINT32 Retry;
SYS_UINT32 Expire;
SYS_UINT32 MinTTL;
} SOA;
} U;
};
struct DNSAnswer {
int iQDCount;
int iANCount;
int iNSCount;
int iARCount;
int iAuth;
struct SysListHead RecsLst[QTYPE_ANSWER_MAX];
};
void DNS_InitAnswer(DNSAnswer *pAns);
void DNS_FreeRecList(SysListHead *pHead);
void DNS_FreeAnswer(DNSAnswer *pAns);
int DNS_FatalError(int iError);
int DNS_Query(char const *pszName, unsigned int uQType, DNSAnswer *pAns,
int iMaxDepth = DNS_STD_MAXDEPTH);
int DNS_QueryDirect(char const *pszDNSServer, char const *pszName,
unsigned int uQType, int iQuerySockType, DNSAnswer *pAns);
#endif