bind - Upgraded vendor branch to 9.5.2-P1
[dragonfly.git] / contrib / bind-9.2.4rc7 / bin / dig / include / dig / dig.h
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000, 2001, 2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: dig.h,v 1.71.2.7 2004/03/09 06:09:14 marka Exp $ */
19
20 #ifndef DIG_H
21 #define DIG_H
22
23 #include <dns/rdatalist.h>
24
25 #include <dst/dst.h>
26
27 #include <isc/boolean.h>
28 #include <isc/buffer.h>
29 #include <isc/bufferlist.h>
30 #include <isc/formatcheck.h>
31 #include <isc/lang.h>
32 #include <isc/list.h>
33 #include <isc/mem.h>
34 #include <isc/print.h>
35 #include <isc/sockaddr.h>
36 #include <isc/socket.h>
37
38 #define MXSERV 6
39 #define MXNAME (DNS_NAME_MAXTEXT+1)
40 #define MXRD 32
41 #define BUFSIZE 512
42 #define COMMSIZE 0xffff
43 #ifndef RESOLV_CONF
44 #define RESOLV_CONF "/etc/resolv.conf"
45 #endif
46 #define OUTPUTBUF 32767
47 #define MAXRRLIMIT 0xffffffff
48 #define MAXTIMEOUT 0xffff
49 #define MAXTRIES 0xffffffff
50 #define MAXNDOTS 0xffff
51 #define MAXPORT 0xffff
52 #define MAXSERIAL 0xffffffff
53
54 /*
55  * Default timeout values
56  */
57 #define TCP_TIMEOUT 10
58 #define UDP_TIMEOUT 5
59
60 #define SERVER_TIMEOUT 1
61
62 #define LOOKUP_LIMIT 64
63 /*
64  * Lookup_limit is just a limiter, keeping too many lookups from being
65  * created.  It's job is mainly to prevent the program from running away
66  * in a tight loop of constant lookups.  It's value is arbitrary.
67  */
68
69 #define ROOTNS 1
70 /*
71  * Set the number of root servers to ask for information when running in
72  * trace mode.
73  * XXXMWS -- trace mode is currently semi-broken, and this number *MUST*
74  * be 1.
75  */
76
77 ISC_LANG_BEGINDECLS
78
79 typedef struct dig_lookup dig_lookup_t;
80 typedef struct dig_query dig_query_t;
81 typedef struct dig_server dig_server_t;
82 typedef ISC_LIST(dig_server_t) dig_serverlist_t;
83 typedef struct dig_searchlist dig_searchlist_t;
84
85 struct dig_lookup {
86         isc_boolean_t
87                 pending, /* Pending a successful answer */
88                 waiting_connect,
89                 doing_xfr,
90                 ns_search_only, /* dig +nssearch, host -C */
91                 identify, /* Append an "on server <foo>" message */
92                 identify_previous_line, /* Prepend a "Nameserver <foo>:"
93                                            message, with newline and tab */
94                 ignore,
95                 recurse,
96                 aaonly,
97                 adflag,
98                 cdflag,
99                 trace, /* dig +trace */
100                 trace_root, /* initial query for either +trace or +nssearch */
101                 tcp_mode,
102                 ip6_int,
103                 comments,
104                 stats,
105                 section_question,
106                 section_answer,
107                 section_authority,
108                 section_additional,
109                 servfail_stops,
110                 new_search,
111                 besteffort,
112                 dnssec;
113         char textname[MXNAME]; /* Name we're going to be looking up */
114         char cmdline[MXNAME];
115         dns_rdatatype_t rdtype;
116         dns_rdatatype_t qrdtype;
117         dns_rdataclass_t rdclass;
118         isc_boolean_t rdtypeset;
119         isc_boolean_t rdclassset;
120         char namespace[BUFSIZE];
121         char onamespace[BUFSIZE];
122         isc_buffer_t namebuf;
123         isc_buffer_t onamebuf;
124         isc_buffer_t sendbuf;
125         char *sendspace;
126         dns_name_t *name;
127         isc_timer_t *timer;
128         isc_interval_t interval;
129         dns_message_t *sendmsg;
130         dns_name_t *oname;
131         ISC_LINK(dig_lookup_t) link;
132         ISC_LIST(dig_query_t) q;
133         dig_query_t *current_query;
134         dig_serverlist_t my_server_list;
135         dig_searchlist_t *origin;
136         dig_query_t *xfr_q;
137         isc_uint32_t retries;
138         int nsfound;
139         isc_uint16_t udpsize;
140         isc_uint32_t ixfr_serial;
141         isc_buffer_t rdatabuf;
142         char rdatastore[MXNAME];
143         dst_context_t *tsigctx;
144         isc_buffer_t *querysig;
145         isc_uint32_t msgcounter;
146 };
147
148 struct dig_query {
149         dig_lookup_t *lookup;
150         isc_boolean_t waiting_connect,
151                 first_pass,
152                 first_soa_rcvd,
153                 second_rr_rcvd,
154                 first_repeat_rcvd,
155                 recv_made,
156                 warn_id;
157         isc_uint32_t first_rr_serial;
158         isc_uint32_t second_rr_serial;
159         isc_uint32_t rr_count;
160         char *servname;
161         isc_bufferlist_t sendlist,
162                 recvlist,
163                 lengthlist;
164         isc_buffer_t recvbuf,
165                 lengthbuf,
166                 slbuf;
167         char *recvspace,
168                 lengthspace[4],
169                 slspace[4];
170         isc_socket_t *sock;
171         ISC_LINK(dig_query_t) link;
172         isc_sockaddr_t sockaddr;
173         isc_time_t time_sent;
174 };
175
176 struct dig_server {
177         char servername[MXNAME];
178         ISC_LINK(dig_server_t) link;
179 };
180
181 struct dig_searchlist {
182         char origin[MXNAME];
183         ISC_LINK(dig_searchlist_t) link;
184 };
185
186 /*
187  * Routines in dighost.c.
188  */
189 void
190 get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
191
192 isc_result_t
193 get_reverse(char *reverse, char *value, isc_boolean_t ip6int,
194             isc_boolean_t strict);
195
196 void
197 fatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
198
199 void
200 debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
201
202 void
203 check_result(isc_result_t result, const char *msg);
204
205 void
206 setup_lookup(dig_lookup_t *lookup);
207
208 void
209 do_lookup(dig_lookup_t *lookup);
210
211 void
212 start_lookup(void);
213
214 void
215 onrun_callback(isc_task_t *task, isc_event_t *event);
216
217 int
218 dhmain(int argc, char **argv);
219
220 void
221 setup_libs(void);
222
223 void
224 setup_system(void);
225
226 dig_lookup_t *
227 requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
228
229 dig_lookup_t *
230 make_empty_lookup(void);
231
232 dig_lookup_t *
233 clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
234
235 dig_server_t *
236 make_server(const char *servname);
237
238 void
239 clone_server_list(dig_serverlist_t src,
240                   dig_serverlist_t *dest);
241
242 void
243 cancel_all(void);
244
245 void
246 destroy_libs(void);
247
248 void
249 set_search_domain(char *domain);
250
251 /*
252  * Routines to be defined in dig.c, host.c, and nslookup.c.
253  */
254
255 isc_result_t
256 printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
257 /*
258  * Print the final result of the lookup.
259  */
260
261 void
262 received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
263 /*
264  * Print a message about where and when the response
265  * was received from, like the final comment in the
266  * output of "dig".
267  */
268
269 void
270 trying(char *frm, dig_lookup_t *lookup);
271
272 void
273 dighost_shutdown(void);
274
275 char *
276 next_token(char **stringp, const char *delim);
277
278 ISC_LANG_ENDDECLS
279
280 #endif