Watt-32 tcp/ip  2.2 dev-rel.10
pcdns.h
Go to the documentation of this file.
1 
3 #ifndef _w32_UDP_DOM_H
4 #define _w32_UDP_DOM_H
5 
6 #define MAX_LABEL_SIZE 63 /* maximum length of a single domain label */
7 #define DOMSIZE 512 /* maximum domain message size to mess with */
8 #define DOM_DST_PORT 53 /* destination port number for DNS protocol */
9 #define DOM_SRC_PORT 1415 /* local port number for DNS protocol. Old */
10  /* port 997 didn't work with some firewalls */
11 #include <sys/pack_on.h>
12 
13 /*
14  * Header format (struct DNS_head), from RFC 1035:
15  * 1 1 1 1 1 1
16  * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
17  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
18  * | ID |
19  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
20  * |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
21  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
22  * | QDCOUNT |
23  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
24  * | ANCOUNT |
25  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
26  * | NSCOUNT |
27  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
28  * | ARCOUNT |
29  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
30  *
31  * AA, TC, RA, and RCODE are only set in responses.
32  * Brief description of the remaining fields:
33  * ID Identifier to match responses with queries
34  * QR Query (0) or response (1)
35  * Opcode For our purposes, always QUERY
36  * RD Recursion desired
37  * Z Reserved (zero)
38  * QDCOUNT Number of queries
39  * ANCOUNT Number of answers
40  * NSCOUNT Number of name server records
41  * ARCOUNT Number of additional records
42  *
43  * Question format, from RFC 1035:
44  * 1 1 1 1 1 1
45  * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
46  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
47  * | |
48  * / QNAME /
49  * / /
50  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
51  * | QTYPE |
52  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
53  * | QCLASS |
54  * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
55  *
56  * The QNAME is encoded as a series of labels, each represented
57  * as a one-byte length (maximum 63) followed by the text of the
58  * label. The list is terminated by a label of length zero (which can
59  * be thought of as the root domain).
60  */
61 
62 /*
63  * Header for the DOMAIN queries.
64  * ALL OF THESE ARE BYTE SWAPPED QUANTITIES!
65  * We are the poor slobs who are incompatible with the world's byte order.
66  */
67 struct DNS_head {
68  WORD ident; /* Unique identifier */
69 #if 1
70  WORD flags; /* See below */
71 #else
72  unsigned rd : 1; /* Recursion desired */
73  unsigned tc : 1; /* Truncated message */
74  unsigned aa : 1; /* Authoritative answer */
75  unsigned opcode : 4; /* See below */
76  unsigned qr : 1; /* Response = 1, Query = 0 */
77  unsigned rcode : 4; /* Response code */
78  unsigned cd : 1; /* Checking disabled by resolver */
79  unsigned ad : 1; /* Authentic data from named */
80  unsigned unused : 1; /* Unused bits */
81  unsigned ra : 1; /* Recursion available */
82 #endif
83  WORD qdcount; /* Question section, # of entries */
84  WORD ancount; /* Answers, how many */
85  WORD nscount; /* Count of name server RRs */
86  WORD arcount; /* Number of "additional" records */
87  };
88 
89 
93 struct DNS_Header {
94  WORD dns_id;
95 #if defined(USE_BIGENDIAN)
96  WORD dns_fl_qr : 1;
97  WORD dns_fl_opcode: 4;
98  WORD dns_fl_aa : 1;
99  WORD dns_fl_tc : 1;
100  WORD dns_fl_rd : 1;
101 
102  WORD dns_fl_ra : 1;
103  WORD dns_fl_unused: 1;
104  WORD dns_fl_ad : 1;
105  WORD dns_fl_cd : 1;
106  WORD dns_fl_rcode : 4;
107 #else
108  WORD dns_fl_rd : 1; /* recursion desired */
109  WORD dns_fl_tc : 1; /* truncated message */
110  WORD dns_fl_aa : 1; /* authoritative answer */
111  WORD dns_fl_opcode: 4; /* purpose of message */
112  WORD dns_fl_qr : 1; /* response flag */
113  WORD dns_fl_rcode : 4; /* response code */
114  WORD dns_fl_cd : 1; /* checking disabled by resolver */
115  WORD dns_fl_ad : 1; /* authentic data from named */
116  WORD dns_fl_unused: 1; /* unused bits (MBZ as of 4.9.3a3) */
117  WORD dns_fl_ra : 1; /* recursion available */
118 #endif
119  WORD dns_num_q;
120  WORD dns_num_ans;
121  WORD dns_num_auth;
122  WORD dns_num_add;
123  };
124 
125 
126 /*
127  * DNS_head::flags
128  */
129 #define DQR 0x8000 /* Query = 0, Response = 1 */
130 #define DOPCODE 0x7100 /* Opcode mask, see below */
131 #define DAA 0x0400 /* Authoritative answer */
132 #define DTC 0x0200 /* Truncated response */
133 #define DRD 0x0100 /* Recursion desired */
134 #define DRA 0x0080 /* Recursion available */
135 #define DRCODE 0x000F /* Response code mask, see below */
136 
137 /*
138  * Opcode possible values:
139  */
140 #define DOPQUERY 0 /* a standard query */
141 #define DOPIQ 1 /* an inverse query */
142 #define DOPCQM 2 /* a completion query, multiple reply */
143 #define DOPCQU 3 /* a completion query, single reply */
144 #define DUPDATE 5 /* DNS update (RFC-2136) */
145 /* the rest reserved for future */
146 
147 /*
148  * DNS server response codes; RCODE (stored in dom_errno)
149  */
150 enum DNS_serv_resp {
151  DNS_SRV_OK = 0, /* 0 = okay response */
152  DNS_SRV_FORM, /* 1 = format error */
153  DNS_SRV_FAIL, /* 2 = server failed */
154  DNS_SRV_NAME, /* 3 = name error (NXDOMAIN) */
155  DNS_SRV_NOTIMPL, /* 4 = function not implemented */
156  DNS_SRV_REFUSE, /* 5 = service refused */
157  DNS_SRV_MAX = 15
158  };
159 
160 /*
161  * DNS client codes (stored in dom_errno)
162  */
163 enum DNS_client_code {
164  DNS_CLI_SYSTEM = DNS_SRV_MAX, /* See 'errno' */
165  DNS_CLI_REFUSE, /* Name server refused */
166  DNS_CLI_USERQUIT, /* User terminated via hook or ^C */
167  DNS_CLI_NOSERV, /* No nameserver defined */
168  DNS_CLI_TIMEOUT, /* Timeout, no reply */
169  DNS_CLI_ILL_RESP, /* Illegal/short response */
170  DNS_CLI_ILL_IDNA, /* Convert to/from international name failed */
171  DNS_CLI_TOOBIG, /* Name/label too large */
172  DNS_CLI_NOIP, /* my_ip_addr == 0 */
173  DNS_CLI_NOIPV6, /* IPv6 DNS disabled */
174  DNS_CLI_OTHER, /* Other general error */
175  DNS_CLI_MAX
176  };
177 
178 /*
179  * Query types (QTYPE)
180  */
181 #define DTYPE_A 1 /* host address resource record (A) */
182 #define DTYPE_CNAME 5 /* host's canonical name record (CNAME) */
183 #define DTYPE_AAAA 28 /* host address resource record (AAAA) */
184 #define DTYPE_PTR 12 /* domain name ptr (PTR) */
185 #define DTYPE_SOA 6 /* start of authority zone (SOA) */
186 #define DTYPE_SRV 33 /* server selection (SRV), RFC-2052 */
187 
188 /*
189  * Query class (QCLASS)
190  */
191 #define DIN 1 /* ARPA internet class */
192 #define DWILD 255 /* Wildcard for several classifications */
193 
194 /*
195  * DNS Query request/response header.
196  */
197 struct DNS_query {
198  struct DNS_head head;
199  BYTE body [DOMSIZE];
200  };
201 
202 struct DNS_Query {
203  struct DNS_Header head;
204  BYTE body [DOMSIZE];
205  };
206 
207 /*
208  * A resource record is made up of a compressed domain name followed by
209  * this structure. All of these words need to be byteswapped before use.
210  * Part of 'struct DNS_query::body'.
211  */
212 struct DNS_resource {
213  WORD rtype; /* resource record type = DTYPE_A/AAAA */
214  WORD rclass; /* RR class = DIN */
215  DWORD ttl; /* time-to-live, changed to 32 bits */
216  WORD rdlength; /* length of next field */
217  BYTE rdata [DOMSIZE-10]; /* data field */
218  };
219 
220 #define RESOURCE_HEAD_SIZE 10
221 
222 #include <sys/pack_off.h>
223 
224 extern char dom_cname [MAX_HOSTLEN+1];
225 extern DWORD dom_ttl;
226 extern BOOL dns_do_ipv6;
227 extern BOOL dns_do_idna;
228 extern WORD dns_windns;
229 extern BOOL called_from_resolve;
230 extern BOOL called_from_ghbn;
231 extern BOOL from_windns;
232 
233 extern DWORD dom_a4list [MAX_ADDRESSES+1];
234 extern ip6_address dom_a6list [MAX_ADDRESSES+1];
235 
236 /* In udp_rev.c
237  */
238 extern int reverse_lookup_myip (void);
239 extern int reverse_resolve_ip4 (DWORD ipv4, char *result, size_t size);
240 extern int reverse_resolve_ip6 (const void *ipv6, char *result, size_t size);
241 
242 #endif
int reverse_lookup_myip(void)
Do a reverse lookup on `my_ip_addr'.
Definition: udp_rev.c:176
Another definition of 'struct DNS_head'.
Definition: pcdns.h:93
Definition: pcdns.h:67
BOOL called_from_resolve
Hacks to make gethostbyname() and resolve() cooperate.
Definition: pcdns.c:60