resolv.h revision 93032
11539Srgrimes/*-
21539Srgrimes * Copyright (c) 1983, 1987, 1989, 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes *
51539Srgrimes * Redistribution and use in source and binary forms, with or without
61539Srgrimes * modification, are permitted provided that the following conditions
71539Srgrimes * are met:
81539Srgrimes * 1. Redistributions of source code must retain the above copyright
91539Srgrimes *    notice, this list of conditions and the following disclaimer.
101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111539Srgrimes *    notice, this list of conditions and the following disclaimer in the
121539Srgrimes *    documentation and/or other materials provided with the distribution.
131539Srgrimes * 3. All advertising materials mentioning features or use of this software
141539Srgrimes *    must display the following acknowledgement:
151539Srgrimes *	This product includes software developed by the University of
161539Srgrimes *	California, Berkeley and its contributors.
171539Srgrimes * 4. Neither the name of the University nor the names of its contributors
181539Srgrimes *    may be used to endorse or promote products derived from this software
191539Srgrimes *    without specific prior written permission.
201539Srgrimes *
211539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311539Srgrimes * SUCH DAMAGE.
3236888Speter */
3336888Speter
3436888Speter/*
3536888Speter * Portions Copyright (c) 1996 by Internet Software Consortium.
361539Srgrimes *
371539Srgrimes * Permission to use, copy, modify, and distribute this software for any
381539Srgrimes * purpose with or without fee is hereby granted, provided that the above
3936888Speter * copyright notice and this permission notice appear in all copies.
408858Srgrimes *
4136888Speter * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
4236888Speter * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
4336888Speter * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
4436888Speter * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
451539Srgrimes * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
461539Srgrimes * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
471539Srgrimes * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
481539Srgrimes * SOFTWARE.
4936888Speter */
5036888Speter
5136888Speter/*
523070Spst *	@(#)resolv.h	8.1 (Berkeley) 6/2/93
5336888Speter *	From Id: resolv.h,v 8.12 1998/04/28 19:36:46 halley Exp $
5450473Speter * $FreeBSD: head/include/resolv.h 93032 2002-03-23 17:24:55Z imp $
551539Srgrimes */
561539Srgrimes
571539Srgrimes#ifndef _RESOLV_H_
581539Srgrimes#define	_RESOLV_H_
591539Srgrimes
603070Spst#include <sys/param.h>
611539Srgrimes#include <sys/types.h>
623070Spst#include <sys/cdefs.h>
6355163Sshin#include <sys/socket.h>
643070Spst#include <stdio.h>
653070Spst
661539Srgrimes/*
6721055Speter * Revision information.  This is the release date in YYYYMMDD format.
6821055Speter * It can change every day so the right thing to do with it is use it
6921055Speter * in preprocessor commands such as "#if (__RES > 19931104)".  Do not
703070Spst * compare for equality; rather, use it to determine whether your resolver
713070Spst * is new enough to contain a certain feature.
723070Spst */
733070Spst
7421055Speter#define	__RES	19960801
753070Spst
763070Spst/*
771539Srgrimes * Resolver configuration file.
781539Srgrimes * Normally not present, but may contain the address of the
791539Srgrimes * inital name server(s) to query and the domain search list.
801539Srgrimes */
811539Srgrimes
821539Srgrimes#ifndef _PATH_RESCONF
833070Spst#define	_PATH_RESCONF        "/etc/resolv.conf"
841539Srgrimes#endif
851539Srgrimes
861539Srgrimes/*
871539Srgrimes * Global defines and variables for resolver stub.
881539Srgrimes */
891539Srgrimes#define	MAXNS			3	/* max # name servers we'll track */
901539Srgrimes#define	MAXDFLSRCH		3	/* # default domain levels to try */
911539Srgrimes#define	MAXDNSRCH		6	/* max # domains in search path */
921539Srgrimes#define	LOCALDOMAINPARTS	2	/* min levels in name that is "local" */
931539Srgrimes
941539Srgrimes#define	RES_TIMEOUT		5	/* min. seconds between retries */
953070Spst#define	MAXRESOLVSORT		10	/* number of net to sort on */
963070Spst#define	RES_MAXNDOTS		15	/* should reflect bit field size */
971539Srgrimes
981539Srgrimesstruct __res_state {
991539Srgrimes	int	retrans;	 	/* retransmition time interval */
1001539Srgrimes	int	retry;			/* number of times to retransmit */
1013070Spst	u_long	options;		/* option flags - see below. */
1021539Srgrimes	int	nscount;		/* number of name servers */
1033070Spst	struct sockaddr_in
1043070Spst		nsaddr_list[MAXNS];	/* address of name server */
1051539Srgrimes#define	nsaddr	nsaddr_list[0]		/* for backward compatibility */
10621055Speter	u_short	id;			/* current message id */
1071539Srgrimes	char	*dnsrch[MAXDNSRCH+1];	/* components of domain to search */
10821055Speter	char	defdname[256];		/* default domain (deprecated) */
1093070Spst	u_long	pfcode;			/* RES_PRF_ flags - see below. */
1103070Spst	unsigned ndots:4;		/* threshold for initial abs. query */
1113070Spst	unsigned nsort:4;		/* number of elements in sort_list[] */
1123070Spst	char	unused[3];
1133070Spst	struct {
1143070Spst		struct in_addr	addr;
1153070Spst		u_int32_t	mask;
1163070Spst	} sort_list[MAXRESOLVSORT];
11721055Speter	char	pad[72];		/* on an i386 this means 512b total */
1181539Srgrimes};
1191539Srgrimes
12055163Sshin/* for INET6 */
1211539Srgrimes/*
12255163Sshin * replacement of __res_state, separated to keep binary compatibility.
12355163Sshin */
12455163Sshinstruct __res_state_ext {
12555163Sshin	struct sockaddr_storage nsaddr_list[MAXNS];
12655163Sshin	struct {
12755163Sshin		int	af;		/* address family for addr, mask */
12855163Sshin		union {
12955163Sshin			struct	in_addr ina;
13055163Sshin			struct	in6_addr in6a;
13155163Sshin		} addr, mask;
13255163Sshin	} sort_list[MAXRESOLVSORT];
13355163Sshin};
13455163Sshin
13555163Sshin/*
1361539Srgrimes * Resolver options (keep these in synch with res_debug.c, please)
1371539Srgrimes */
13810132Speter#define RES_INIT	0x00000001	/* address initialized */
13910132Speter#define RES_DEBUG	0x00000002	/* print debug messages */
14010132Speter#define RES_AAONLY	0x00000004	/* authoritative answers only (!IMPL)*/
14110132Speter#define RES_USEVC	0x00000008	/* use virtual circuit */
14210132Speter#define RES_PRIMARY	0x00000010	/* query primary server only (!IMPL) */
14313771Smpp#define RES_IGNTC	0x00000020	/* ignore truncation errors */
14410132Speter#define RES_RECURSE	0x00000040	/* recursion desired */
14510132Speter#define RES_DEFNAMES	0x00000080	/* use default domain name */
14610132Speter#define RES_STAYOPEN	0x00000100	/* Keep TCP socket open */
14710132Speter#define RES_DNSRCH	0x00000200	/* search up local domain tree */
1483070Spst#define	RES_INSECURE1	0x00000400	/* type 1 security disabled */
1493070Spst#define	RES_INSECURE2	0x00000800	/* type 2 security disabled */
15010132Speter#define	RES_NOALIASES	0x00001000	/* shuts off HOSTALIASES feature */
15117902Speter#define	RES_USE_INET6	0x00002000	/* use/map IPv6 in gethostbyname() */
15228982Sbrian#define	RES_NOTLDQUERY	0x00004000	/* Don't query TLD names */
15378012Sume/* KAME extensions: use higher bit to avoid conflict with ISC use */
15478012Sume#define	RES_USE_EDNS0	0x40000000	/* use EDNS0 */
1551539Srgrimes
15610132Speter#define RES_DEFAULT	(RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
1571539Srgrimes
1581539Srgrimes/*
1591539Srgrimes * Resolver "pfcode" values.  Used by dig.
1601539Srgrimes */
1613070Spst#define	RES_PRF_STATS	0x00000001
16236888Speter#define	RES_PRF_UPDATE	0x00000002
1633070Spst#define	RES_PRF_CLASS   0x00000004
1643070Spst#define	RES_PRF_CMD	0x00000008
1653070Spst#define	RES_PRF_QUES	0x00000010
1663070Spst#define	RES_PRF_ANS	0x00000020
1673070Spst#define	RES_PRF_AUTH	0x00000040
1683070Spst#define	RES_PRF_ADD	0x00000080
1693070Spst#define	RES_PRF_HEAD1	0x00000100
1703070Spst#define	RES_PRF_HEAD2	0x00000200
1713070Spst#define	RES_PRF_TTLID	0x00000400
1723070Spst#define	RES_PRF_HEADX	0x00000800
1733070Spst#define	RES_PRF_QUERY	0x00001000
1743070Spst#define	RES_PRF_REPLY	0x00002000
1753070Spst#define	RES_PRF_INIT    0x00004000
1763070Spst/*			0x00008000	*/
1771539Srgrimes
1783070Spsttypedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
1793070Spst	res_sendhookact;
1801539Srgrimes
18193032Simptypedef res_sendhookact (*res_send_qhook)(struct sockaddr_in * const *ns,
18293032Simp					  const u_char **query,
18393032Simp					  int *querylen,
18493032Simp					  u_char *ans,
18593032Simp					  int anssiz,
18693032Simp					  int *resplen);
1873070Spst
18893032Simptypedef res_sendhookact (*res_send_rhook)(const struct sockaddr_in *ns,
18993032Simp					  const u_char *query,
19093032Simp					  int querylen,
19193032Simp					  u_char *ans,
19293032Simp					  int anssiz,
19393032Simp					  int *resplen);
1943070Spst
19521055Speterstruct res_sym {
19621055Speter	int	number;		/* Identifying number, like T_MX */
19721055Speter	char *	name;		/* Its symbolic name, like "MX" */
19821055Speter	char *	humanname;	/* Its fun name, like "mail exchanger" */
19921055Speter};
20021055Speter
2011539Srgrimesextern struct __res_state _res;
20255163Sshin/* for INET6 */
20355163Sshinextern struct __res_state_ext _res_ext;
20455163Sshin
20521055Speterextern const struct res_sym __p_class_syms[];
20621055Speterextern const struct res_sym __p_type_syms[];
2071539Srgrimes
2081539Srgrimes/* Private routines shared between libc/net, named, nslookup and others. */
20917902Speter#define	res_hnok	__res_hnok
21017902Speter#define	res_ownok	__res_ownok
21117902Speter#define	res_mailok	__res_mailok
21217902Speter#define	res_dnok	__res_dnok
21321055Speter#define	sym_ston	__sym_ston
21421055Speter#define	sym_ntos	__sym_ntos
21521055Speter#define	sym_ntop	__sym_ntop
21621055Speter#define	b64_ntop	__b64_ntop
21721055Speter#define	b64_pton	__b64_pton
21817902Speter#define	loc_ntoa	__loc_ntoa
21917902Speter#define	loc_aton	__loc_aton
22036898Speter#define	fp_resstat	__fp_resstat
22136898Speter#define	p_query		__p_query
2221539Srgrimes#define	dn_skipname	__dn_skipname
22321055Speter#define	fp_resstat	__fp_resstat
2241539Srgrimes#define	fp_query	__fp_query
2253070Spst#define	fp_nquery	__fp_nquery
2261539Srgrimes#define	hostalias	__hostalias
2271539Srgrimes#define	putlong		__putlong
2281539Srgrimes#define	putshort	__putshort
2293070Spst#define	p_class		__p_class
2303070Spst#define	p_time		__p_time
2313070Spst#define	p_type		__p_type
23221055Speter#define	p_query		__p_query
2333070Spst#define	p_cdnname	__p_cdnname
23436898Speter#define	p_section	__p_section
2353070Spst#define	p_cdname	__p_cdname
23621055Speter#define	p_fqnname	__p_fqnname
2373070Spst#define	p_fqname	__p_fqname
2383070Spst#define	p_option	__p_option
23921055Speter#define	p_secstodate	__p_secstodate
24021055Speter#define	dn_count_labels	__dn_count_labels
24121055Speter#define	dn_comp		__dn_comp
24236898Speter#define	dn_expand	__dn_expand
24336898Speter#define	res_init	__res_init
24410132Speter#define	res_randomid	__res_randomid
24536898Speter#define	res_query	__res_query
24636898Speter#define	res_search	__res_search
24736898Speter#define	res_querydomain	__res_querydomain
24836898Speter#define	res_mkquery	__res_mkquery
24936898Speter#define	res_send	__res_send
25010132Speter#define	res_isourserver	__res_isourserver
25110132Speter#define	res_nameinquery	__res_nameinquery
25210132Speter#define	res_queriesmatch __res_queriesmatch
25321055Speter#define	res_close	__res_close
25478012Sume#define	res_opt		__res_opt
25536898Speter#define	res_mkupdate	__res_mkupdate
25636898Speter#define	res_mkupdrec	__res_mkupdrec
25736898Speter#define	res_freeupdrec	__res_freeupdrec
2583070Spst
2591539Srgrimes__BEGIN_DECLS
26093032Simpint		res_hnok(const char *);
26193032Simpint		res_ownok(const char *);
26293032Simpint		res_mailok(const char *);
26393032Simpint		res_dnok(const char *);
26493032Simpint		sym_ston(const struct res_sym *, const char *, int *);
26593032Simpconst char *	sym_ntos(const struct res_sym *, int, int *);
26693032Simpconst char *	sym_ntop(const struct res_sym *, int, int *);
26793032Simpint		b64_ntop(u_char const *, size_t, char *, size_t);
26893032Simpint		b64_pton(char const *, u_char *, size_t);
26993032Simpint		loc_aton(const char *, u_char *);
27093032Simpconst char *	loc_ntoa(const u_char *, char *);
27193032Simpint		dn_skipname(const u_char *, const u_char *);
27293032Simpvoid		fp_resstat(struct __res_state *, FILE *);
27393032Simpvoid		fp_query(const u_char *, FILE *);
27493032Simpvoid		fp_nquery(const u_char *, int, FILE *);
27593032Simpconst char *	hostalias(const char *);
27693032Simpvoid		putlong(u_int32_t, u_char *);
27793032Simpvoid		putshort(u_int16_t, u_char *);
27893032Simpconst char *	p_class(int);
27993032Simpconst char *	p_time(u_int32_t);
28093032Simpconst char *	p_type(int);
28193032Simpvoid		p_query(const u_char *);
28293032Simpconst u_char *	p_cdnname(const u_char *, const u_char *, int, FILE *);
28393032Simpconst u_char *	p_cdname(const u_char *, const u_char *, FILE *);
28493032Simpconst u_char *	p_fqnname(const u_char *, const u_char *,
28593032Simp			  int, char *, int);
28693032Simpconst u_char *	p_fqname(const u_char *, const u_char *, FILE *);
28793032Simpconst char *	p_option(u_long);
28893032Simpchar *		p_secstodate(u_long);
28993032Simpint		dn_count_labels(const char *);
29093032Simpint		dn_comp(const char *, u_char *, int, u_char **, u_char **);
29193032Simpint		dn_expand(const u_char *, const u_char *, const u_char *,
29293032Simp			  char *, int);
29393032Simpint		res_init(void);
29493032Simpu_int		res_randomid(void);
29593032Simpint		res_query(const char *, int, int, u_char *, int);
29693032Simpint		res_search(const char *, int, int, u_char *, int);
29793032Simpint		res_querydomain(const char *, const char *, int, int,
29893032Simp				u_char *, int);
29993032Simpint		res_mkquery(int, const char *, int, int, const u_char *,
30093032Simp			    int, const u_char *, u_char *, int);
30193032Simpint		res_send(const u_char *, int, u_char *, int);
30293032Simpint		res_isourserver(const struct sockaddr_in *);
30393032Simpint		res_nameinquery(const char *, int, int,
30493032Simp				const u_char *, const u_char *);
30593032Simpint		res_queriesmatch(const u_char *, const u_char *,
30693032Simp				 const u_char *, const u_char *);
30793032Simpvoid		res_close(void);
30893032Simpint		res_opt(int, u_char *, int, int);
30993032Simpconst char *	p_section(int, int);
31036898Speter/* XXX The following depend on the ns_updrec typedef in arpa/nameser.h */
31136898Speter#ifdef _ARPA_NAMESER_H_
31293032Simpint		res_update(ns_updrec *);
31393032Simpint		res_mkupdate(ns_updrec *, u_char *, int);
31493032Simpns_updrec *	res_mkupdrec(int, const char *, u_int, u_int, u_long);
31593032Simpvoid		res_freeupdrec(ns_updrec *);
31636898Speter#endif
3171539Srgrimes__END_DECLS
3181539Srgrimes
3191539Srgrimes#endif /* !_RESOLV_H_ */
320