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