xref: /netbsd-src/external/bsd/libbind/dist/doc/resolver.man3 (revision 5bbd2a12505d72a8177929a37b5cee489d0a1cfd)
1*b5677b36Schristos.\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
2*b5677b36Schristos.\"
3*b5677b36Schristos.\" Permission to use, copy, modify, and distribute this software for any
4*b5677b36Schristos.\" purpose with or without fee is hereby granted, provided that the above
5*b5677b36Schristos.\" copyright notice and this permission notice appear in all copies.
6*b5677b36Schristos.\"
7*b5677b36Schristos.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
8*b5677b36Schristos.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9*b5677b36Schristos.\" MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
10*b5677b36Schristos.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11*b5677b36Schristos.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12*b5677b36Schristos.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13*b5677b36Schristos.\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14*b5677b36Schristos.\"
15*b5677b36Schristos.\" Copyright (c) 1985, 1995 The Regents of the University of California.
16*b5677b36Schristos.\" All rights reserved.
17*b5677b36Schristos.\"
18*b5677b36Schristos.\" Redistribution and use in source and binary forms are permitted provided
19*b5677b36Schristos.\" that: (1) source distributions retain this entire copyright notice and
20*b5677b36Schristos.\" comment, and (2) distributions including binaries display the following
21*b5677b36Schristos.\" acknowledgement:  ``This product includes software developed by the
22*b5677b36Schristos.\" University of California, Berkeley and its contributors'' in the
23*b5677b36Schristos.\" documentation or other materials provided with the distribution and in
24*b5677b36Schristos.\" all advertising materials mentioning features or use of this software.
25*b5677b36Schristos.\" Neither the name of the University nor the names of its contributors may
26*b5677b36Schristos.\" be used to endorse or promote products derived from this software without
27*b5677b36Schristos.\" specific prior written permission.
28*b5677b36Schristos.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
29*b5677b36Schristos.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
30*b5677b36Schristos.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
31*b5677b36Schristos.\"
32*b5677b36Schristos.\"	@(#)resolver.3	6.5 (Berkeley) 6/23/90
33*b5677b36Schristos.\"	Id: resolver.man3,v 1.2 2009/01/21 00:12:34 each Exp
34*b5677b36Schristos.\"
35*b5677b36Schristos.Dd July 4, 2000
36*b5677b36Schristos.Dt RESOLVER 3
37*b5677b36Schristos.Os BSD 4
38*b5677b36Schristos.Sh NAME
39*b5677b36Schristos.Nm res_ninit ,
40*b5677b36Schristos.Nm res_ourserver_p ,
41*b5677b36Schristos.Nm fp_resstat ,
42*b5677b36Schristos.Nm res_hostalias ,
43*b5677b36Schristos.Nm res_pquery ,
44*b5677b36Schristos.Nm res_nquery ,
45*b5677b36Schristos.Nm res_nsearch ,
46*b5677b36Schristos.Nm res_nquerydomain ,
47*b5677b36Schristos.Nm res_nmkquery ,
48*b5677b36Schristos.Nm res_nsend ,
49*b5677b36Schristos.Nm res_nupdate ,
50*b5677b36Schristos.Nm res_nmkupdate ,
51*b5677b36Schristos.Nm res_nclose ,
52*b5677b36Schristos.Nm res_nsendsigned ,
53*b5677b36Schristos.Nm res_findzonecut ,
54*b5677b36Schristos.Nm res_getservers ,
55*b5677b36Schristos.Nm res_setservers ,
56*b5677b36Schristos.Nm res_ndestroy ,
57*b5677b36Schristos.Nm dn_comp ,
58*b5677b36Schristos.Nm dn_expand ,
59*b5677b36Schristos.Nm hstrerror ,
60*b5677b36Schristos.Nm res_init ,
61*b5677b36Schristos.Nm res_isourserver ,
62*b5677b36Schristos.Nm fp_nquery ,
63*b5677b36Schristos.Nm p_query ,
64*b5677b36Schristos.Nm hostalias ,
65*b5677b36Schristos.Nm res_query ,
66*b5677b36Schristos.Nm res_search ,
67*b5677b36Schristos.Nm res_querydomain ,
68*b5677b36Schristos.Nm res_mkquery ,
69*b5677b36Schristos.Nm res_send ,
70*b5677b36Schristos.Nm res_update ,
71*b5677b36Schristos.Nm res_close ,
72*b5677b36Schristos.Nm herror
73*b5677b36Schristos.Nd resolver routines
74*b5677b36Schristos.Sh SYNOPSIS
75*b5677b36Schristos.Fd #include <sys/types.h>
76*b5677b36Schristos.Fd #include <netinet/in.h>
77*b5677b36Schristos.Fd #include <arpa/nameser.h>
78*b5677b36Schristos.Fd #include <resolv.h>
79*b5677b36Schristos.Fd #include <res_update.h>
80*b5677b36Schristos.Vt typedef struct __res_state *res_state ;
81*b5677b36Schristos.Pp
82*b5677b36Schristos.Ft int
83*b5677b36Schristos.Fn res_ninit "res_state statp"
84*b5677b36Schristos.Ft int
85*b5677b36Schristos.Fn res_ourserver_p "const res_state statp" "const struct sockaddr_in *addr"
86*b5677b36Schristos.Ft void
87*b5677b36Schristos.Fn fp_resstat "const res_state statp" "FILE *fp"
88*b5677b36Schristos.Ft "const char *"
89*b5677b36Schristos.Fn res_hostalias "const res_state statp" "const char *name" "char *buf" "size_t buflen"
90*b5677b36Schristos.Ft int
91*b5677b36Schristos.Fn res_pquery "const res_state statp" "const u_char *msg" "int msglen" "FILE *fp"
92*b5677b36Schristos.Ft int
93*b5677b36Schristos.Fn res_nquery "res_state statp" "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
94*b5677b36Schristos.Ft int
95*b5677b36Schristos.Fn res_nsearch "res_state statp" "const char *dname" "int class" "int type" "u_char * answer" "int anslen"
96*b5677b36Schristos.Ft int
97*b5677b36Schristos.Fn res_nquerydomain "res_state statp" "const char *name" "const char *domain" "int class" "int type" "u_char *answer" "int anslen"
98*b5677b36Schristos.Ft int
99*b5677b36Schristos.Fo res_nmkquery
100*b5677b36Schristos.Fa "res_state statp"
101*b5677b36Schristos.Fa "int op"
102*b5677b36Schristos.Fa "const char *dname"
103*b5677b36Schristos.Fa "int class"
104*b5677b36Schristos.Fa "int type"
105*b5677b36Schristos.Fa "const u_char *data"
106*b5677b36Schristos.Fa "int datalen"
107*b5677b36Schristos.Fa "const u_char *newrr"
108*b5677b36Schristos.Fa "u_char *buf"
109*b5677b36Schristos.Fa "int buflen"
110*b5677b36Schristos.Fc
111*b5677b36Schristos.Ft int
112*b5677b36Schristos.Fn res_nsend "res_state statp" "const u_char *msg" "int msglen" "u_char *answer" "int anslen"
113*b5677b36Schristos.Ft int
114*b5677b36Schristos.Fn res_nupdate "res_state statp" "ns_updrec *rrecp_in"
115*b5677b36Schristos.Ft int
116*b5677b36Schristos.Fn res_nmkupdate "res_state statp" "ns_updrec *rrecp_in" "u_char *buf" "int buflen"
117*b5677b36Schristos.Ft void
118*b5677b36Schristos.Fn res_nclose "res_state statp"
119*b5677b36Schristos.Ft int
120*b5677b36Schristos.Fn res_nsendsigned "res_state statp" "const u_char *msg" "int msglen" "ns_tsig_key *key" "u_char *answer" "int anslen"
121*b5677b36Schristos.Ft int
122*b5677b36Schristos.Fn res_findzonecut "res_state statp" "const char *dname" "ns_class class" "int options" "char *zname" "size_t zsize" "struct in_addr *addrs" "int naddrs"
123*b5677b36Schristos.Ft int
124*b5677b36Schristos.Fn res_getservers "res_state statp" "union res_sockaddr_union *set" "int cnt"
125*b5677b36Schristos.Ft void
126*b5677b36Schristos.Fn res_setservers "res_state statp" "const union res_sockaddr_union *set" "int cnt"
127*b5677b36Schristos.Ft void
128*b5677b36Schristos.Fn res_ndestroy "res_state statp"
129*b5677b36Schristos.Ft int
130*b5677b36Schristos.Fn dn_comp "const char *exp_dn" "u_char *comp_dn" "int length" "u_char **dnptrs" "u_char **lastdnptr"
131*b5677b36Schristos.Ft int
132*b5677b36Schristos.Fn dn_expand "const u_char *msg" "const u_char *eomorig" "const u_char *comp_dn" "char *exp_dn" "int  length"
133*b5677b36Schristos.Ft "const char *"
134*b5677b36Schristos.Fn hstrerror "int err"
135*b5677b36Schristos.Ss DEPRECATED
136*b5677b36Schristos.Fd #include <sys/types.h>
137*b5677b36Schristos.Fd #include <netinet/in.h>
138*b5677b36Schristos.Fd #include <arpa/nameser.h>
139*b5677b36Schristos.Fd #include <resolv.h>
140*b5677b36Schristos.Fd #include <res_update.h>
141*b5677b36Schristos.Ft int
142*b5677b36Schristos.Fn res_init "void"
143*b5677b36Schristos.Ft int
144*b5677b36Schristos.Fn res_isourserver "const struct sockaddr_in *addr"
145*b5677b36Schristos.Ft int
146*b5677b36Schristos.Fn fp_nquery "const u_char *msg" "int msglen" "FILE *fp"
147*b5677b36Schristos.Ft void
148*b5677b36Schristos.Fn p_query "const u_char *msg" "FILE *fp"
149*b5677b36Schristos.Ft "const char *"
150*b5677b36Schristos.Fn hostalias "const char *name"
151*b5677b36Schristos.Ft int
152*b5677b36Schristos.Fn res_query "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
153*b5677b36Schristos.Ft int
154*b5677b36Schristos.Fn res_search "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
155*b5677b36Schristos.Ft int
156*b5677b36Schristos.Fn res_querydomain "const char *name" "const char *domain" "int class" "int type" "u_char *answer" "int anslen"
157*b5677b36Schristos.Ft int
158*b5677b36Schristos.Fo res_mkquery
159*b5677b36Schristos.Fa "int op"
160*b5677b36Schristos.Fa "const char *dname"
161*b5677b36Schristos.Fa "int class"
162*b5677b36Schristos.Fa "int type"
163*b5677b36Schristos.Fa "const char *data"
164*b5677b36Schristos.Fa "int datalen"
165*b5677b36Schristos.Fa "struct rrec *newrr"
166*b5677b36Schristos.Fa "u_char *buf"
167*b5677b36Schristos.Fa "int buflen"
168*b5677b36Schristos.Fc
169*b5677b36Schristos.Ft int
170*b5677b36Schristos.Fn res_send "const u_char *msg" "int msglen" "u_char *answer" "int anslen"
171*b5677b36Schristos.Ft int
172*b5677b36Schristos.Fn res_update "ns_updrec *rrecp_in"
173*b5677b36Schristos.Ft void
174*b5677b36Schristos.Fn res_close "void"
175*b5677b36Schristos.Ft void
176*b5677b36Schristos.Fn herror "const char *s"
177*b5677b36Schristos.Sh DESCRIPTION
178*b5677b36SchristosThese routines are used for making, sending and interpreting
179*b5677b36Schristosquery and reply messages with Internet domain name servers.
180*b5677b36Schristos.Pp
181*b5677b36SchristosState information is kept in
182*b5677b36Schristos.Fa statp
183*b5677b36Schristosand is used to control the behavior of these functions.
184*b5677b36Schristos.Fa statp
185*b5677b36Schristosshould be set to all zeros prior to the first call to any of these functions.
186*b5677b36Schristos.Pp
187*b5677b36SchristosThe functions
188*b5677b36Schristos.Fn res_init ,
189*b5677b36Schristos.Fn res_isourserver ,
190*b5677b36Schristos.Fn fp_nquery ,
191*b5677b36Schristos.Fn p_query ,
192*b5677b36Schristos.Fn hostalias ,
193*b5677b36Schristos.Fn res_query ,
194*b5677b36Schristos.Fn res_search ,
195*b5677b36Schristos.Fn res_querydomain ,
196*b5677b36Schristos.Fn res_mkquery ,
197*b5677b36Schristos.Fn res_send ,
198*b5677b36Schristos.Fn res_update ,
199*b5677b36Schristos.Fn res_close
200*b5677b36Schristosand
201*b5677b36Schristos.Fn herror
202*b5677b36Schristosare deprecated and are supplied for compatability with old source
203*b5677b36Schristoscode.
204*b5677b36SchristosThey use global configuration and state information that is
205*b5677b36Schristoskept in the structure
206*b5677b36Schristos.Ft _res
207*b5677b36Schristosrather than that referenced through
208*b5677b36Schristos.Ft statp .
209*b5677b36Schristos.Pp
210*b5677b36SchristosMost of the values in
211*b5677b36Schristos.Ft statp
212*b5677b36Schristosand
213*b5677b36Schristos.Ft _res
214*b5677b36Schristosare initialized on the first call to
215*b5677b36Schristos.Fn res_ninit
216*b5677b36Schristos/
217*b5677b36Schristos.Fn res_init
218*b5677b36Schristosto reasonable defaults and can be ignored.
219*b5677b36SchristosOptions
220*b5677b36Schristosstored in
221*b5677b36Schristos.Ft statp->options
222*b5677b36Schristos/
223*b5677b36Schristos.Ft _res.options
224*b5677b36Schristosare defined in
225*b5677b36Schristos.Pa resolv.h
226*b5677b36Schristosand are as follows.
227*b5677b36SchristosOptions are stored as a simple bit mask containing the bitwise
228*b5677b36Schristos.Dq OR
229*b5677b36Schristosof the options enabled.
230*b5677b36Schristos.Bl -tag -width "RES_DEB"
231*b5677b36Schristos.It Dv RES_INIT
232*b5677b36SchristosTrue if the initial name server address and default domain name are
233*b5677b36Schristosinitialized (i.e.,
234*b5677b36Schristos.Fn res_ninit
235*b5677b36Schristos/
236*b5677b36Schristos.Fn res_init
237*b5677b36Schristoshas been called).
238*b5677b36Schristos.It Dv RES_DEBUG
239*b5677b36SchristosPrint debugging messages.
240*b5677b36Schristos.It Dv RES_AAONLY
241*b5677b36SchristosAccept authoritative answers only.
242*b5677b36SchristosShould continue until it finds an authoritative answer or finds an error.
243*b5677b36SchristosCurrently this is not implemented.
244*b5677b36Schristos.It Dv RES_USEVC
245*b5677b36SchristosUse TCP connections for queries instead of UDP datagrams.
246*b5677b36Schristos.It Dv RES_STAYOPEN
247*b5677b36SchristosUsed with
248*b5677b36Schristos.Dv RES_USEVC
249*b5677b36Schristosto keep the TCP connection open between queries.
250*b5677b36SchristosThis is useful only in programs that regularly do many queries.
251*b5677b36SchristosUDP should be the normal mode used.
252*b5677b36Schristos.It Dv RES_IGNTC
253*b5677b36SchristosIgnore truncation errors, i.e., don't retry with TCP.
254*b5677b36Schristos.It Dv RES_RECURSE
255*b5677b36SchristosSet the recursion-desired bit in queries.
256*b5677b36SchristosThis is the default.
257*b5677b36Schristos(\c
258*b5677b36Schristos.Fn res_nsend
259*b5677b36Schristos/
260*b5677b36Schristos.Fn res_send
261*b5677b36Schristosdoes not do iterative queries and expects the name server
262*b5677b36Schristosto handle recursion.)
263*b5677b36Schristos.It Dv RES_DEFNAMES
264*b5677b36SchristosIf set,
265*b5677b36Schristos.Fn res_nsearch
266*b5677b36Schristos/
267*b5677b36Schristos.Fn res_search
268*b5677b36Schristoswill append the default domain name to single-component names
269*b5677b36Schristos(those that do not contain a dot).
270*b5677b36SchristosThis option is enabled by default.
271*b5677b36Schristos.It Dv RES_DNSRCH
272*b5677b36SchristosIf this option is set,
273*b5677b36Schristos.Fn res_nsearch
274*b5677b36Schristos/
275*b5677b36Schristos.Fn res_search
276*b5677b36Schristoswill search for host names in the current domain and in parent domains; see
277*b5677b36Schristos.Xr hostname 7 .
278*b5677b36SchristosThis is used by the standard host lookup routine
279*b5677b36Schristos.Xr gethostbyname 3 .
280*b5677b36SchristosThis option is enabled by default.
281*b5677b36Schristos.It Dv RES_NOALIASES
282*b5677b36SchristosThis option turns off the user level aliasing feature controlled by
283*b5677b36Schristosthe
284*b5677b36Schristos.Ev HOSTALIASES
285*b5677b36Schristosenvironment variable.
286*b5677b36SchristosNetwork daemons should set this option.
287*b5677b36Schristos.It Dv RES_USE_INET6
288*b5677b36SchristosThis option causes
289*b5677b36Schristos.Xr gethostbyname 3
290*b5677b36Schristosto look for AAAA records before looking for A records if none are found.
291*b5677b36Schristos.It Dv RES_ROTATE
292*b5677b36SchristosThis options causes the
293*b5677b36Schristos.Fn res_nsend
294*b5677b36Schristos/
295*b5677b36Schristos.Fn res_send
296*b5677b36Schristosto rotate the list of nameservers in
297*b5677b36Schristos.Fa statp->nsaddr_list
298*b5677b36Schristos/
299*b5677b36Schristos.Fa _res.nsaddr_list .
300*b5677b36Schristos.It Dv RES_KEEPTSIG
301*b5677b36SchristosThis option causes
302*b5677b36Schristos.Fn res_nsendsigned
303*b5677b36Schristosto leave the message unchanged after TSIG verification; otherwise the TSIG
304*b5677b36Schristosrecord would be removed and the header updated.
305*b5677b36Schristos.It Dv RES_NOTLDQUERY
306*b5677b36SchristosThis option causes
307*b5677b36Schristos.Fn res_nsearch
308*b5677b36Schristosto not attempt to resolve a unqualified name as if it were a top level
309*b5677b36Schristosdomain (TLD).
310*b5677b36SchristosThis option can cause problems if the site has "localhost" as a TLD rather
311*b5677b36Schristosthan having localhost on one or more elements of the search list.
312*b5677b36SchristosThis option has no effect if neither
313*b5677b36Schristos.Dv RES_DEFNAMES
314*b5677b36Schristosor
315*b5677b36Schristos.Dv RES_DNSRCH
316*b5677b36Schristosis set.
317*b5677b36Schristos.El
318*b5677b36Schristos.Pp
319*b5677b36SchristosThe
320*b5677b36Schristos.Fn res_ninit
321*b5677b36Schristos/
322*b5677b36Schristos.Fn res_init
323*b5677b36Schristosroutine
324*b5677b36Schristosreads the configuration file (if any; see
325*b5677b36Schristos.Xr resolver 5 )
326*b5677b36Schristosto get the default domain name, search list and
327*b5677b36Schristosthe Internet address of the local name server(s).
328*b5677b36SchristosIf no server is configured, the host running the resolver is tried.
329*b5677b36SchristosThe current domain name is defined by the hostname
330*b5677b36Schristosif not specified in the configuration file;
331*b5677b36Schristosit can be overridden by the environment variable
332*b5677b36Schristos.Ev LOCALDOMAIN .
333*b5677b36SchristosThis environment variable may contain several blank-separated
334*b5677b36Schristostokens if you wish to override the
335*b5677b36Schristos.Dq search list
336*b5677b36Schristoson a per-process basis.  This is similar to the
337*b5677b36Schristos.Ic search
338*b5677b36Schristoscommand in the configuration file.
339*b5677b36SchristosAnother environment variable
340*b5677b36Schristos.Pq Dq Ev RES_OPTIONS
341*b5677b36Schristoscan be set to override certain internal resolver options which are otherwise
342*b5677b36Schristosset by changing fields in the
343*b5677b36Schristos.Ft statp
344*b5677b36Schristos/
345*b5677b36Schristos.Ft _res
346*b5677b36Schristosstructure or are inherited from the configuration file's
347*b5677b36Schristos.Ic options
348*b5677b36Schristoscommand.  The syntax of the
349*b5677b36Schristos.Dq Ev RES_OPTIONS
350*b5677b36Schristosenvironment variable is explained in
351*b5677b36Schristos.Xr resolver 5 .
352*b5677b36SchristosInitialization normally occurs on the first call
353*b5677b36Schristosto one of the other resolver routines.
354*b5677b36Schristos.Pp
355*b5677b36SchristosThe memory referred to by
356*b5677b36Schristos.Ft statp
357*b5677b36Schristosmust be set to all zeros prior to the first call to
358*b5677b36Schristos.Fn res_ninit .
359*b5677b36Schristos.Fn res_ndestroy
360*b5677b36Schristosshould be call to free memory allocated by
361*b5677b36Schristos.Fn res_ninit
362*b5677b36Schristosafter last use.
363*b5677b36Schristos.Pp
364*b5677b36SchristosThe
365*b5677b36Schristos.Fn res_nquery
366*b5677b36Schristos/
367*b5677b36Schristos.Fn res_query
368*b5677b36Schristosfunctions provides interfaces to the server query mechanism.
369*b5677b36SchristosThey constructs a query, sends it to the local server,
370*b5677b36Schristosawaits a response, and makes preliminary checks on the reply.
371*b5677b36SchristosThe query requests information of the specified
372*b5677b36Schristos.Fa type
373*b5677b36Schristosand
374*b5677b36Schristos.Fa class
375*b5677b36Schristosfor the specified fully-qualified domain name
376*b5677b36Schristos.Fa dname .
377*b5677b36SchristosThe reply message is left in the
378*b5677b36Schristos.Fa answer
379*b5677b36Schristosbuffer with length
380*b5677b36Schristos.Fa anslen
381*b5677b36Schristossupplied by the caller.
382*b5677b36Schristos.Fn res_nquery
383*b5677b36Schristos/
384*b5677b36Schristos.Fn res_query
385*b5677b36Schristosreturn -1 on error or the length of the answer.
386*b5677b36Schristos.Pp
387*b5677b36SchristosThe
388*b5677b36Schristos.Fn res_nsearch
389*b5677b36Schristos/
390*b5677b36Schristos.Fn res_search
391*b5677b36Schristosroutines make a query and awaits a response like
392*b5677b36Schristos.Fn res_nquery
393*b5677b36Schristos/
394*b5677b36Schristos.Fn res_query ,
395*b5677b36Schristosbut in addition, it implements the default and search rules
396*b5677b36Schristoscontrolled by the
397*b5677b36Schristos.Dv RES_DEFNAMES
398*b5677b36Schristosand
399*b5677b36Schristos.Dv RES_DNSRCH
400*b5677b36Schristosoptions.
401*b5677b36SchristosIt returns the length of the first successful reply which is stored in
402*b5677b36Schristos.Ft answer
403*b5677b36Schristosor -1 on error.
404*b5677b36Schristos.Pp
405*b5677b36SchristosThe remaining routines are lower-level routines used by
406*b5677b36Schristos.Fn res_nquery
407*b5677b36Schristos/
408*b5677b36Schristos.Fn res_query .
409*b5677b36SchristosThe
410*b5677b36Schristos.Fn res_nmkquery
411*b5677b36Schristos/
412*b5677b36Schristos.Fn res_mkquery
413*b5677b36Schristosfunctions
414*b5677b36Schristosconstructs a standard query message and places it in
415*b5677b36Schristos.Fa buf .
416*b5677b36SchristosIt returns the size of the query, or \-1 if the query is
417*b5677b36Schristoslarger than
418*b5677b36Schristos.Fa buflen .
419*b5677b36SchristosThe query type
420*b5677b36Schristos.Fa op
421*b5677b36Schristosis usually
422*b5677b36Schristos.Dv QUERY ,
423*b5677b36Schristosbut can be any of the query types defined in
424*b5677b36Schristos.Pa <arpa/nameser.h> .
425*b5677b36SchristosThe domain name for the query is given by
426*b5677b36Schristos.Fa dname .
427*b5677b36Schristos.Fa Newrr
428*b5677b36Schristosis currently unused but is intended for making update messages.
429*b5677b36Schristos.Pp
430*b5677b36SchristosThe
431*b5677b36Schristos.Fn res_nsend
432*b5677b36Schristos/
433*b5677b36Schristos.Fn res_send
434*b5677b36Schristos/
435*b5677b36Schristos.Fn res_nsendsigned
436*b5677b36Schristosroutines
437*b5677b36Schristossends a pre-formatted query and returns an answer.
438*b5677b36SchristosIt will call
439*b5677b36Schristos.Fn res_ninit
440*b5677b36Schristos/
441*b5677b36Schristos.Fn res_init
442*b5677b36Schristosif
443*b5677b36Schristos.Dv RES_INIT
444*b5677b36Schristosis not set, send the query to the local name server, and
445*b5677b36Schristoshandle timeouts and retries.  Additionally,
446*b5677b36Schristos.Fn res_nsendsigned
447*b5677b36Schristoswill use TSIG signatures to add authentication to the query and verify the
448*b5677b36Schristosresponse.  In this case, only one nameserver will be contacted.
449*b5677b36SchristosThe length of the reply message is returned, or \-1 if there were errors.
450*b5677b36Schristos.Pp
451*b5677b36Schristos.Fn res_nquery
452*b5677b36Schristos/
453*b5677b36Schristos.Fn res_query ,
454*b5677b36Schristos.Fn res_nsearch
455*b5677b36Schristos/
456*b5677b36Schristos.Fn res_search
457*b5677b36Schristosand
458*b5677b36Schristos.Fn res_nsend
459*b5677b36Schristos/
460*b5677b36Schristos.Fn res_send
461*b5677b36Schristosreturn a length that may be bigger than
462*b5677b36Schristos.Fa anslen .
463*b5677b36SchristosIn that case the query should be retried with a bigger buffer.
464*b5677b36SchristosNOTE the answer to the second query may be larger still so supplying
465*b5677b36Schristosa buffer that bigger that the answer returned by the previous
466*b5677b36Schristosquery is recommended.
467*b5677b36Schristos.Pp
468*b5677b36Schristos.Fa answer
469*b5677b36SchristosMUST be big enough to receive a maximum UDP response from the server or
470*b5677b36Schristosparts of the answer will be silently discarded.
471*b5677b36SchristosThe default maximum UDP response size is 512 bytes.
472*b5677b36Schristos.Pp
473*b5677b36SchristosThe function
474*b5677b36Schristos.Fn res_ourserver_p
475*b5677b36Schristosreturns true when
476*b5677b36Schristos.Fa inp
477*b5677b36Schristosis one of the servers in
478*b5677b36Schristos.Fa statp->nsaddr_list
479*b5677b36Schristos/
480*b5677b36Schristos.Fa _res.nsaddr_list .
481*b5677b36Schristos.Pp
482*b5677b36SchristosThe functions
483*b5677b36Schristos.Fn fp_nquery
484*b5677b36Schristos/
485*b5677b36Schristos.Fn p_query
486*b5677b36Schristosprint out the query and any answer in
487*b5677b36Schristos.Fa msg
488*b5677b36Schristoson
489*b5677b36Schristos.Fa fp .
490*b5677b36Schristos.Fn p_query
491*b5677b36Schristosis equivalent to
492*b5677b36Schristos.Fn fp_nquery
493*b5677b36Schristoswith
494*b5677b36Schristos.Fa msglen
495*b5677b36Schristosset to 512.
496*b5677b36Schristos.Pp
497*b5677b36SchristosThe function
498*b5677b36Schristos.Fn fp_resstat
499*b5677b36Schristosprints out the active flag bits in
500*b5677b36Schristos.Fa statp->options
501*b5677b36Schristospreceeded by the text ";; res options:" on
502*b5677b36Schristos.Fa file .
503*b5677b36Schristos.Pp
504*b5677b36SchristosThe functions
505*b5677b36Schristos.Fn res_hostalias
506*b5677b36Schristos/
507*b5677b36Schristos.Fn hostalias
508*b5677b36Schristoslookup up name in the file referred to by the
509*b5677b36Schristos.Ev HOSTALIASES
510*b5677b36Schristosfiles return a fully qualified hostname if found or NULL if
511*b5677b36Schristosnot found or an error occurred.
512*b5677b36Schristos.Fn res_hostalias
513*b5677b36Schristosuses
514*b5677b36Schristos.Fa buf
515*b5677b36Schristosto store the result in,
516*b5677b36Schristos.Fn hostalias
517*b5677b36Schristosuses a static buffer.
518*b5677b36Schristos.Pp
519*b5677b36SchristosThe functions
520*b5677b36Schristos.Fn res_getservers
521*b5677b36Schristosand
522*b5677b36Schristos.Fn res_setservers
523*b5677b36Schristosare used to get and set the list of server to be queried.
524*b5677b36Schristos.Pp
525*b5677b36SchristosThe functions
526*b5677b36Schristos.Fn res_nupdate
527*b5677b36Schristos/
528*b5677b36Schristos.Fn res_update
529*b5677b36Schristostake a list of ns_updrec
530*b5677b36Schristos.Fa rrecp_in .
531*b5677b36SchristosIdentifies the containing zone for each record and groups the records
532*b5677b36Schristosaccording to containing zone maintaining in zone order then sends and update
533*b5677b36Schristosrequest to the servers for these zones.  The number of zones updated is
534*b5677b36Schristosreturned or -1 on error.  Note that
535*b5677b36Schristos.Fn res_nupdate
536*b5677b36Schristoswill perform TSIG authenticated dynamic update operations if the key is not
537*b5677b36SchristosNULL.
538*b5677b36Schristos.Pp
539*b5677b36SchristosThe function
540*b5677b36Schristos.Fn res_findzonecut
541*b5677b36Schristosdiscovers the closest enclosing zone cut for a specified domain name,
542*b5677b36Schristosand finds the IP addresses of the zone's master servers.
543*b5677b36Schristos.Pp
544*b5677b36SchristosThe functions
545*b5677b36Schristos.Fn res_nmkupdate
546*b5677b36Schristos/
547*b5677b36Schristos.Fn res_mkupdate
548*b5677b36Schristostake a linked list of ns_updrec
549*b5677b36Schristos.Fa rrecp_in
550*b5677b36Schristosand construct a UPDATE message in
551*b5677b36Schristos.Fa buf .
552*b5677b36Schristos.Fn res_nmkupdate
553*b5677b36Schristos/
554*b5677b36Schristos.Fn res_mkupdate
555*b5677b36Schristosreturn the length of the constructed message on no error or one of the
556*b5677b36Schristosfollowing error values.
557*b5677b36Schristos.Bl -inset -width "-5"
558*b5677b36Schristos.It -1
559*b5677b36SchristosAn error occurred parsing
560*b5677b36Schristos.Fa rrecp_in .
561*b5677b36Schristos.It -2
562*b5677b36SchristosThe buffer
563*b5677b36Schristos.Fa buf
564*b5677b36Schristoswas too small.
565*b5677b36Schristos.It -3
566*b5677b36SchristosThe first record was not a zone section or there was a section order problem.
567*b5677b36SchristosThe section order is S_ZONE, S_PREREQ and S_UPDATE.
568*b5677b36Schristos.It -4
569*b5677b36SchristosA number overflow occurred.
570*b5677b36Schristos.It -5
571*b5677b36SchristosUnknown operation or no records.
572*b5677b36Schristos.El
573*b5677b36Schristos.Pp
574*b5677b36SchristosThe functions
575*b5677b36Schristos.Fn res_nclose
576*b5677b36Schristos/
577*b5677b36Schristos.Fn res_close
578*b5677b36Schristosclose any open files referenced through
579*b5677b36Schristos.Fa statp
580*b5677b36Schristos/
581*b5677b36Schristos.Fa _res .
582*b5677b36Schristos.Pp
583*b5677b36SchristosThe function
584*b5677b36Schristos.Fn res_ndestroy
585*b5677b36Schristoscalls
586*b5677b36Schristos.Fn res_nclose
587*b5677b36Schristosthen frees any memory allocated by
588*b5677b36Schristos.Fn res_ninit .
589*b5677b36Schristos.Pp
590*b5677b36SchristosThe
591*b5677b36Schristos.Fn dn_comp
592*b5677b36Schristosfunction
593*b5677b36Schristoscompresses the domain name
594*b5677b36Schristos.Fa exp_dn
595*b5677b36Schristosand stores it in
596*b5677b36Schristos.Fa comp_dn .
597*b5677b36SchristosThe size of the compressed name is returned or \-1 if there were errors.
598*b5677b36SchristosThe size of the array pointed to by
599*b5677b36Schristos.Fa comp_dn
600*b5677b36Schristosis given by
601*b5677b36Schristos.Fa length .
602*b5677b36SchristosThe compression uses
603*b5677b36Schristosan array of pointers
604*b5677b36Schristos.Fa dnptrs
605*b5677b36Schristosto previously-compressed names in the current message.
606*b5677b36SchristosThe first pointer points to
607*b5677b36Schristosto the beginning of the message and the list ends with
608*b5677b36Schristos.Dv NULL .
609*b5677b36SchristosThe limit to the array is specified by
610*b5677b36Schristos.Fa lastdnptr .
611*b5677b36SchristosA side effect of
612*b5677b36Schristos.Fn dn_comp
613*b5677b36Schristosis to update the list of pointers for labels inserted into the message
614*b5677b36Schristosas the name is compressed.  If
615*b5677b36Schristos.Fa dnptr
616*b5677b36Schristosis
617*b5677b36Schristos.Dv NULL ,
618*b5677b36Schristosnames are not compressed.  If
619*b5677b36Schristos.Fa lastdnptr
620*b5677b36Schristosis
621*b5677b36Schristos.Dv NULL ,
622*b5677b36Schristosthe list of labels is not updated.
623*b5677b36Schristos.Pp
624*b5677b36SchristosThe
625*b5677b36Schristos.Fn dn_expand
626*b5677b36Schristosentry
627*b5677b36Schristosexpands the compressed domain name
628*b5677b36Schristos.Fa comp_dn
629*b5677b36Schristosto a full domain name.
630*b5677b36SchristosThe compressed name is contained in a query or reply message;
631*b5677b36Schristos.Fa msg
632*b5677b36Schristosis a pointer to the beginning of the message.
633*b5677b36Schristos.Fa eomorig
634*b5677b36Schristosis a pointer to the first location after the message.
635*b5677b36SchristosThe uncompressed name is placed in the buffer indicated by
636*b5677b36Schristos.Fa exp_dn
637*b5677b36Schristoswhich is of size
638*b5677b36Schristos.Fa length .
639*b5677b36SchristosThe size of compressed name is returned or \-1 if there was an error.
640*b5677b36Schristos.Pp
641*b5677b36SchristosThe variables
642*b5677b36Schristos.Ft statp->res_h_errno
643*b5677b36Schristos/
644*b5677b36Schristos.Ft _res.res_h_errno
645*b5677b36Schristosand external variable
646*b5677b36Schristos.Ft h_errno
647*b5677b36Schristosis set whenever an error occurs during resolver operation.  The following
648*b5677b36Schristosdefinitions are given in
649*b5677b36Schristos.Pa <netdb.h> :
650*b5677b36Schristos.Bd -literal
651*b5677b36Schristos#define NETDB_INTERNAL -1  /* see errno */
652*b5677b36Schristos#define NETDB_SUCCESS  0   /* no problem */
653*b5677b36Schristos#define HOST_NOT_FOUND 1   /* Authoritative Answer Host not found */
654*b5677b36Schristos#define TRY_AGAIN      2   /* Non-Authoritative not found, or SERVFAIL */
655*b5677b36Schristos#define NO_RECOVERY    3   /* Non-Recoverable: FORMERR, REFUSED, NOTIMP */
656*b5677b36Schristos#define NO_DATA        4   /* Valid name, no data for requested type */
657*b5677b36Schristos.Ed
658*b5677b36Schristos.Pp
659*b5677b36SchristosThe
660*b5677b36Schristos.Fn herror
661*b5677b36Schristosfunction writes a message to the diagnostic output consisting of the string
662*b5677b36Schristosparameter
663*b5677b36Schristos.Fa s ,
664*b5677b36Schristosthe constant string ": ", and a message corresponding to the value of
665*b5677b36Schristos.Ft h_errno .
666*b5677b36Schristos.Pp
667*b5677b36SchristosThe
668*b5677b36Schristos.Fn hstrerror
669*b5677b36Schristosfunction returns a string which is the message text corresponding to the
670*b5677b36Schristosvalue of the
671*b5677b36Schristos.Fa err
672*b5677b36Schristosparameter.
673*b5677b36Schristos.Sh FILES
674*b5677b36Schristos.Bl -tag -width "/etc/resolv.conf    "
675*b5677b36Schristos.It Pa /etc/resolv.conf
676*b5677b36SchristosSee
677*b5677b36Schristos.Xr resolver 5 .
678*b5677b36Schristos.El
679*b5677b36Schristos.Sh SEE ALSO
680*b5677b36Schristos.Xr gethostbyname 3 ,
681*b5677b36Schristos.Xr hostname 7 ,
682*b5677b36Schristos.Xr resolver 5 ;
683*b5677b36SchristosRFC1032, RFC1033, RFC1034, RFC1035, RFC974;
684*b5677b36SchristosSMM:11,
685*b5677b36Schristos.Dq Name Server Operations Guide for BIND
686