1 /*
2  * Copyright 2005 Niels Provos <provos@citi.umich.edu>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Niels Provos.
16  * 4. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /*	$OpenBSD: resolv.h,v 1.15 2004/01/22 21:48:02 espie Exp $	*/
32 
33 /*
34  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
35  * All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  * 3. Neither the name of the project nor the names of its contributors
46  *    may be used to endorse or promote products derived from this software
47  *    without specific prior written permission.
48  *
49  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59  * SUCH DAMAGE.
60  */
61 
62 /*
63  * ++Copyright++ 1983, 1987, 1989, 1993
64  * -
65  * Copyright (c) 1983, 1987, 1989, 1993
66  *    The Regents of the University of California.  All rights reserved.
67  *
68  * Redistribution and use in source and binary forms, with or without
69  * modification, are permitted provided that the following conditions
70  * are met:
71  * 1. Redistributions of source code must retain the above copyright
72  *    notice, this list of conditions and the following disclaimer.
73  * 2. Redistributions in binary form must reproduce the above copyright
74  *    notice, this list of conditions and the following disclaimer in the
75  *    documentation and/or other materials provided with the distribution.
76  * 3. Neither the name of the University nor the names of its contributors
77  *    may be used to endorse or promote products derived from this software
78  *    without specific prior written permission.
79  *
80  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
81  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
82  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
83  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
84  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
85  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
86  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
87  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
88  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
89  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
90  * SUCH DAMAGE.
91  * -
92  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
93  *
94  * Permission to use, copy, modify, and distribute this software for any
95  * purpose with or without fee is hereby granted, provided that the above
96  * copyright notice and this permission notice appear in all copies, and that
97  * the name of Digital Equipment Corporation not be used in advertising or
98  * publicity pertaining to distribution of the document or software without
99  * specific, written prior permission.
100  *
101  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
102  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
103  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
104  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
105  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
106  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
107  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
108  * SOFTWARE.
109  * -
110  * --Copyright--
111  */
112 
113 /*
114  *	@(#)resolv.h	8.1 (Berkeley) 6/2/93
115  *	$From: resolv.h,v 8.17 1996/11/26 10:11:20 vixie Exp $
116  */
117 
118 #ifndef _RESOLV_H_
119 #define	_RESOLV_H_
120 
121 #include <sys/param.h>
122 #if (!defined(BSD)) || (BSD < 199306)
123 # include <sys/bitypes.h>
124 #else
125 # include <sys/types.h>
126 #endif
127 #include <sys/cdefs.h>
128 #include <sys/socket.h>
129 #include <stdio.h>
130 
131 /*
132  * Revision information.  This is the release date in YYYYMMDD format.
133  * It can change every day so the right thing to do with it is use it
134  * in preprocessor commands such as "#if (__RES > 19931104)".  Do not
135  * compare for equality; rather, use it to determine whether your resolver
136  * is new enough to contain a certain feature.
137  */
138 
139 #define	__RES	19960801
140 
141 /*
142  * Resolver configuration file.
143  * Normally not present, but may contain the address of the
144  * initial name server(s) to query and the domain search list.
145  */
146 
147 #ifndef _PATH_RESCONF
148 #define _PATH_RESCONF        "/etc/resolv.conf"
149 #endif
150 
151 #include "dnsres.h"
152 
153 /*
154  * Resolver options (keep these in synch with res_debug.c, please)
155  */
156 #define RES_INIT	0x00000001	/* address initialized */
157 #define RES_DEBUG	0x00000002	/* print debug messages */
158 #define RES_AAONLY	0x00000004	/* authoritative answers only (!IMPL)*/
159 #define RES_USEVC	0x00000008	/* use virtual circuit */
160 #define RES_PRIMARY	0x00000010	/* query primary server only (!IMPL) */
161 #define RES_IGNTC	0x00000020	/* ignore trucation errors */
162 #define RES_RECURSE	0x00000040	/* recursion desired */
163 #define RES_DEFNAMES	0x00000080	/* use default domain name */
164 #define RES_STAYOPEN	0x00000100	/* Keep TCP socket open */
165 #define RES_DNSRCH	0x00000200	/* search up local domain tree */
166 #define	RES_INSECURE1	0x00000400	/* type 1 security disabled */
167 #define	RES_INSECURE2	0x00000800	/* type 2 security disabled */
168 #define	RES_NOALIASES	0x00001000	/* shuts off HOSTALIASES feature */
169 #define	RES_USE_INET6	0x00002000	/* use/map IPv6 in gethostbyname() */
170 /* KAME extensions: use higher bit to avoid conflict with ISC use */
171 #define	RES_USE_EDNS0	0x40000000	/* use EDNS0 */
172 /* DNSSEC extensions: use higher bit to avoid conflict with ISC use */
173 #define	RES_USE_DNSSEC	0x20000000	/* use DNSSEC using OK bit in OPT */
174 
175 #define RES_DEFAULT	(RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
176 
177 /*
178  * Resolver "pfcode" values.  Used by dig.
179  */
180 #define RES_PRF_STATS	0x00000001
181 /*			0x00000002	*/
182 #define RES_PRF_CLASS   0x00000004
183 #define RES_PRF_CMD	0x00000008
184 #define RES_PRF_QUES	0x00000010
185 #define RES_PRF_ANS	0x00000020
186 #define RES_PRF_AUTH	0x00000040
187 #define RES_PRF_ADD	0x00000080
188 #define RES_PRF_HEAD1	0x00000100
189 #define RES_PRF_HEAD2	0x00000200
190 #define RES_PRF_TTLID	0x00000400
191 #define RES_PRF_HEADX	0x00000800
192 #define RES_PRF_QUERY	0x00001000
193 #define RES_PRF_REPLY	0x00002000
194 #define RES_PRF_INIT    0x00004000
195 /*			0x00008000	*/
196 
197 /* hooks are still experimental as of 4.9.2 */
198 typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
199 	res_sendhookact;
200 
201 typedef res_sendhookact (*res_send_qhook)(struct sockaddr_in * const *ns,
202 					      const unsigned char **query,
203 					      int *querylen,
204 					      unsigned char *ans,
205 					      int anssiz,
206 					      int *resplen);
207 
208 typedef res_sendhookact (*res_send_rhook)(const struct sockaddr_in *ns,
209 					      const unsigned char *query,
210 					      int querylen,
211 					      unsigned char *ans,
212 					      int anssiz,
213 					      int *resplen);
214 
215 struct res_sym {
216 	int	number;		/* Identifying number, like T_MX */
217 	char *	name;		/* Its symbolic name, like "MX" */
218 	char *	humanname;	/* Its fun name, like "mail exchanger" */
219 };
220 
221 extern const struct res_sym __dnsres_p_class_syms[];
222 extern const struct res_sym __dnsres_p_type_syms[];
223 
224 /* Private routines shared between libc/net, named, nslookup and others. */
225 #define	res_hnok	__dnsres_res_hnok
226 #define	res_ownok	__dnsres_res_ownok
227 #define	res_mailok	__dnsres_res_mailok
228 #define	res_dnok	__dnsres_res_dnok
229 #define	sym_ston	__dnsres_sym_ston
230 #define	sym_ntos	__dnsres_sym_ntos
231 #define	sym_ntop	__dnsres_sym_ntop
232 #define b64_ntop	__dnsres_b64_ntop
233 #define	b64_pton	__dnsres_b64_pton
234 #define	loc_ntoa	__dnsres_loc_ntoa
235 #define	loc_aton	__dnsres_loc_aton
236 #define	dn_skipname	__dnsres_dn_skipname
237 #define	fp_resstat	__dnsres_fp_resstat
238 #define	fp_query	__dnsres_fp_query
239 #define	fp_nquery	__dnsres_fp_nquery
240 #define	hostalias	__dnsres_hostalias
241 #define	putlong		__dnsres_putlong
242 #define	putshort	__dnsres_putshort
243 #define p_class		__dnsres_p_class
244 #define p_time		__dnsres_p_time
245 #define p_type		__dnsres_p_type
246 #define	p_query		__dnsres_p_query
247 #define	p_cdnname	__dnsres_p_cdnname
248 #define	p_cdname	__dnsres_p_cdname
249 #define	p_fqnname	__dnsres_p_fqnname
250 #define	p_fqname	__dnsres_p_fqname
251 #define	p_rr		__dnsres_p_rr
252 #define	p_option	__dnsres_p_option
253 #define	p_secstodate	__dnsres_p_secstodate
254 #define	dn_count_labels	__dnsres_dn_count_labels
255 #define	dn_comp		__dnsres_dn_comp
256 #define	res_randomid	__dnsres_res_randomid
257 #define	res_send	__dnsres_res_send
258 #define	res_isourserver	__dnsres_res_isourserver
259 #define	res_nameinquery	__dnsres_res_nameinquery
260 #define	res_queriesmatch __dnsres_res_queriesmatch
261 #define	res_close	__dnsres_res_close
262 #define	res_opt		__dnsres_res_opt
263 
264 #define	dn_expand	__dnsres_dn_expand
265 #define	res_init_socket	__dnsres_res_init_socket
266 #define	res_query	__dnsres_res_query
267 #define	res_search	__dnsres_res_search
268 #define	res_querydomain	__dnsres_res_querydomain
269 #define	res_mkquery	__dnsres_res_mkquery
270 #define	getshort	__dnsres_getshort
271 #define	getlong		__dnsres_getlong
272 
273 struct dnsres_cbstate;
274 struct dnsres_socket;
275 struct dnsres_target;
276 struct res_search_state;
277 
278 __BEGIN_DECLS
279 int			res_hnok(const char *);
280 int			res_ownok(const char *);
281 int			res_mailok(const char *);
282 int			res_dnok(const char *);
283 int			sym_ston(const struct res_sym *, char *, int *);
284 const char *		sym_ntos(const struct res_sym *, int, int *);
285 const char *		sym_ntop(const struct res_sym *, int, int *);
286 int			b64_ntop(unsigned char const *, size_t, char *, size_t);
287 int			b64_pton(char const *, unsigned char *, size_t);
288 int			loc_aton(const char *, unsigned char *);
289 const char *		loc_ntoa(const unsigned char *, char *);
290 int			dn_skipname(const unsigned char *,
291 			    const unsigned char *);
292 void			fp_resstat(struct dnsres *, FILE *);
293 void			fp_query(struct dnsres *,
294 			    const unsigned char *, FILE *);
295 void			fp_nquery(struct dnsres *,
296 			    const unsigned char *msg, int len, FILE *file);
297 const char *		hostalias(struct dnsres *, const char *);
298 void			putlong(u_int32_t, unsigned char *);
299 void			putshort(u_int16_t, unsigned char *);
300 const char *		p_class(int);
301 const char *		p_time(u_int32_t);
302 const char *		p_type(int);
303 void			p_query(struct dnsres *,
304 		            const unsigned char *);
305 const unsigned char *	p_cdnname(const unsigned char *, const unsigned char *,
306 			    int, FILE *);
307 const unsigned char *	p_cdname(const unsigned char *, const unsigned char *,
308 			    FILE *);
309 const unsigned char *	p_fqnname(const unsigned char *, const unsigned char *,
310 			    int, char *, int);
311 const unsigned char *	p_fqname(const unsigned char *, const unsigned char *,
312 			    FILE *);
313 const unsigned char *	p_rr(struct dnsres *,
314 			    const unsigned char *, const unsigned char *,
315 			    FILE *);
316 const char *		p_option(unsigned long);
317 char *			p_secstodate(unsigned long);
318 int			dn_count_labels(char *);
319 int			dn_comp(const char *, unsigned char *, int,
320 			    unsigned char **, unsigned char **);
321 int			dn_expand(const unsigned char *, const unsigned char *,
322 			    const unsigned char *, char *, int);
323 int			res_init(struct dnsres *);
324 void			res_init_socket(struct dnsres_socket *);
325 unsigned int		res_randomid(void);
326 void			res_query(struct dnsres *,
327 	                    const char *, struct dnsres_target *,
328 			    void (*)(int, void *), void *);
329 void			res_search(struct dnsres *,
330 			    const char *, struct dnsres_target * ,
331 			    void (*)(int, void *), void *);
332 void			res_querydomain(struct dnsres *,
333 			    const char *, const char *,
334 			    struct dnsres_target *,
335 			    void (*)(int, void *), void *);
336 int			res_mkquery(struct dnsres *,
337 			    int, const char *, int, int,
338 			    const unsigned char *, int, const unsigned char *,
339 			    unsigned char *, int);
340 void			res_send(struct dnsres *,
341 			    const unsigned char *, int, unsigned char *, int,
342 			    void (*)(int, struct res_search_state *),
343 			    struct res_search_state *)
344 			__attribute__((__bounded__(__string__,4,5)));
345 int			res_isourserver(struct dnsres *,
346 			    const struct sockaddr_in *);
347 int			res_nameinquery(const char *, int, int,
348 			    const unsigned char *, const unsigned char *);
349 int			res_opt(struct dnsres *_resp, int, u_char *, int, int);
350 int			res_queriesmatch(const unsigned char *,
351 			    const unsigned char *, const unsigned char *,
352 			    const unsigned char *);
353 void			res_close(struct dnsres_socket *);
354 unsigned short		getshort(const unsigned char *);
355 unsigned int		getlong(const unsigned char *);
356 __END_DECLS
357 
358 #ifndef HAVE_FGETLN
359 char			*fgetln(FILE *, size_t *);
360 #endif
361 
362 #ifndef HAVE_STRLCPY
363 size_t			strlcpy(char *dst, const char *src, size_t size);
364 #endif
365 
366 #ifndef ARC4RANDOM
367 u_int32_t		arc4random(void);
368 #endif
369 
370 #endif /* !_RESOLV_H_ */
371