Unleashed v1.4
[unleashed.git] / share / man / man3resolv / resolver.3resolv
blobc591391dd5fa2cf90420b653dd5ece1aabafa16c
1 '\" te
2 .\"  Portions Copyright 1989 AT&T Portions Copyright (c) 1985, 1995 Regents of the University of California.
3 .\" Copyright (C) 2006, Sun Microsystems, Inc. All Rights Reserved
4 .TH RESOLVER 3RESOLV "April 9, 2016"
5 .SH NAME
6 resolver, res_ninit, fp_resstat, res_hostalias, res_nquery, res_nsearch,
7 res_nquerydomain, res_nmkquery, res_nsend, res_nclose, res_nsendsigned,
8 dn_comp, dn_expand, hstrerror, res_init, res_query, res_search, res_mkquery,
9 res_send, herror, res_getservers, res_setservers, res_ndestroy \- resolver
10 routines
11 .SH SYNOPSIS
12 .LP
13 .nf
14 BIND 8.2.2 Interfaces
15 .fi
17 .LP
18 .nf
19 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lresolv\fR [ \fIlibrary\fR ... ]
20 #include <sys/types.h>
21 #include <netinet/in.h>
22 #include <arpa/nameser.h>
23 #include <resolv.h>
24 #include <netdb.h>
26 \fBint\fR \fBres_ninit\fR(\fBres_state\fR \fIstatp\fR);
27 .fi
29 .LP
30 .nf
31 \fBvoid\fR \fBres_ndestroy\fR(\fBres_state\fR \fIstatp\fR);
32 .fi
34 .LP
35 .nf
36 \fBvoid\fR \fBfp_resstat\fR(\fBconst res_state\fR \fIstatp\fR, \fBFILE *\fR\fIfp\fR);
37 .fi
39 .LP
40 .nf
41 \fBconst char *\fR\fBres_hostalias\fR(\fBconst res_state\fR \fIstatp\fR, \fBconst char *\fR\fIname\fR,
42      \fBchar *\fR \fIname\fR, \fBchar *\fR\fIbuf\fR, \fBsize_t\fR\fIbuflen\fR);
43 .fi
45 .LP
46 .nf
47 \fBint\fR \fBres_nquery\fR(\fBres_state\fR \fIstatp\fR, \fBconst char *\fR\fIdname\fR, \fBint\fR \fIclass\fR, \fBint\fR \fItype\fR,
48      \fBu_char *\fR\fIanswer\fR, \fBint\fR \fIdatalen\fR, \fBint\fR \fIanslen\fR);
49 .fi
51 .LP
52 .nf
53 \fBint\fR \fBres_nsearch\fR(\fBres_state\fR \fIstatp\fR, \fBconst char *\fR\fIdname\fR, \fBint\fR \fIclass\fR, \fBint\fR \fItype\fR,
54      \fBu_char *\fR\fIanswer\fR, \fBint\fR \fIanslen\fR);
55 .fi
57 .LP
58 .nf
59 \fBint\fR \fBres_nquerydomain\fR(\fBres_state\fR \fIstatp\fR, \fBconst char *\fR\fIname\fR,
60      \fBconst char *\fR\fIdomain\fR, \fBint\fR \fIclass\fR, \fBint\fR \fItype\fR,
61      \fBu_char *\fR\fIanswer\fR, \fBint\fR \fIanslen\fR);
62 .fi
64 .LP
65 .nf
66 \fBint\fR \fBres_nmkquery\fR(\fBres_state\fR \fIstatp\fR, \fBint\fR \fIop\fR, \fBconst char *\fR\fIdname\fR, \fBint\fR \fIclass\fR,
67      \fBint\fR \fItype\fR, \fBu_char *\fR\fIanswer\fR, \fBint\fR \fIdatalen\fR,
68      \fBint\fR \fIanslen\fR);
69 .fi
71 .LP
72 .nf
73 \fBint\fR \fBres_nsend\fR(\fBres_state\fR \fIstatp\fR, \fBconst u_char *\fR\fImsg\fR, \fBint\fR \fImsglen\fR,
74      \fBu_char *\fR\fIanswer\fR, \fBint\fR \fIanslen\fR);
75 .fi
77 .LP
78 .nf
79 \fBvoid\fR \fBres_nclose\fR(\fBres_state\fR \fIstatp\fR);
80 .fi
82 .LP
83 .nf
84 \fBint\fR \fBres_snendsigned\fR(\fBres_state\fR \fIstatp\fR, \fBconst u_char *\fR\fImsg\fR,
85      \fBint\fR \fImsglen\fR, \fBns_tsig_key *\fR\fIkey\fR, \fBu_char *\fR\fIanswer\fR, \fBint\fR \fIanslen\fR);
86 .fi
88 .LP
89 .nf
90 \fBint\fR \fBdn_comp\fR(\fBconst char *\fR\fIexp_dn\fR, \fBu_char *\fR\fIcomp_dn\fR, \fBint\fR \fIlength\fR,
91      \fBu_char **\fR\fIdnptrs\fR, \fB**\fR\fIlastdnptr\fR);
92 .fi
94 .LP
95 .nf
96 \fBint\fR \fBdn_expand\fR(\fBconst u_char *\fR\fImsg\fR, \fB*\fR\fIeomorig\fR, \fB*\fR\fIcomp_dn\fR, \fBchar *\fR\fIexp_dn\fR,
97      \fBint\fR \fIlength\fR);
98 .fi
102 \fBconst char *\fR\fBhstrerror\fR(\fBint\fR \fIerr\fR);
107 \fBvoid\fR \fBres_setservers\fR(\fBres_state\fR \fIstatp\fR, \fBconst union res_sockaddr_union *\fR\fIset\fR,
108      \fBint\fR \fIcnt\fR);
113 \fBint\fR \fBres_getservers\fR(\fBres_state\fR \fIstatp\fR, \fBunion res_sockaddr_union *\fR\fIset\fR,
114      \fBint\fR \fIcnt\fR);
119 Deprecated Interfaces
124 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lresolv\fR [ \fIlibrary\fR ... ]
125 #include <sys/types.h>
126 #include <netinet/in.h>
127 #include <arpa/nameser.h>
128 #include <resolv.h>
129 #include <netdb.h>
131 \fBint\fR \fBres_init\fR(void)
136 \fBint\fR \fBres_query\fR(\fBconst char *\fR\fIdname\fR, \fBint\fR \fIclass\fR,
137      \fBint\fR \fItype\fR, \fBu_char *\fR\fIanswer\fR,
138      \fBint\fR \fIanslen\fR);
143 \fBint\fR \fBres_search\fR(\fBconst char *\fR\fIdname\fR, \fBint\fR \fIclass\fR,
144      \fBint\fR \fItype\fR, \fBu_char *\fR\fIanswer\fR, \fBint\fR \fIanslen\fR);
149 \fBint\fR \fBres_mkquery\fR(\fBint\fR \fIop\fR, \fBconst char *\fR\fIdname\fR, \fBint\fR \fIclass\fR,
150      \fBint\fR \fItype\fR, \fBconst char *\fR\fIdata\fR,\fBint\fR \fIdatalen\fR,
151      \fBstruct rrec *\fR\fInewrr\fR, \fBu_char *\fR\fIbuf\fR, \fBint\fR \fIbuflen\fR);
156 \fBint\fR \fBres_send\fR(\fBconst u_char *\fR\fImsg\fR, \fBint\fR \fImsglen\fR, \fBu_char *\fR\fIanswer\fR,
157      \fBint\fR \fIanslen\fR);
162 \fBvoid\fR \fBherror\fR(\fBconst char *\fR\fIs\fR);
165 .SH DESCRIPTION
167 These routines are used for making, sending, and interpreting query and reply
168 messages with Internet domain name servers.
171 State information is kept in \fIstatp\fR and is used to control the behavior of
172 these functions. Set \fIstatp\fR to all zeros prior to making the first call to
173 any of these functions.
176 The \fBres_ndestroy()\fR function should be called to free memory allocated by
177 \fBres_ninit()\fR after the last use of \fIstatp\fR.
180 The functions \fBres_init()\fR, \fBres_query()\fR, \fBres_search()\fR,
181 \fBres_mkquery()\fR, \fBres_send()\fR, and \fBherror()\fR are deprecated. They
182 are supplied for backwards compatibility. They use global configuration and
183 state information that is kept in the structure \fB_res\fR rather than state
184 information referenced through \fIstatp\fR.
187 Most of the values in \fIstatp\fR and \fB_res\fR are initialized to reasonable
188 defaults on the first call to \fBres_ninit()\fR or \fBres_init()\fR and can be
189 ignored. Options stored in \fBstatp->options\fR or \fB_res.options\fR are
190 defined in <\fBresolv.h\fR>. They are stored as a simple bit mask containing
191 the bitwise \fBOR\fR of the options enabled.
193 .ne 2
195 \fB\fBRES_INIT\fR\fR
197 .RS 17n
198 True if the initial name server address and default domain name are
199 initialized, that is, \fBres_init()\fR or \fBres_ninit()\fR has been called.
203 .ne 2
205 \fB\fBRES_DEBUG\fR\fR
207 .RS 17n
208 Print debugging messages.
212 .ne 2
214 \fB\fBRES_AAONLY\fR\fR
216 .RS 17n
217 Accept authoritative answers only. With this option, \fBres_send()\fR will
218 continue until it finds an authoritative answer or finds an error. Currently
219 this option is not implemented.
223 .ne 2
225 \fB\fBRES_USEVC\fR\fR
227 .RS 17n
228 Use \fBTCP\fR connections for queries instead of \fBUDP\fR datagrams.
232 .ne 2
234 \fB\fBRES_STAYOPEN\fR\fR
236 .RS 17n
237 Use with \fBRES_USEVC\fR to keep the \fBTCP\fR connection open between queries.
238 This is a useful option for programs that regularly do many queries. The normal
239 mode used should be \fBUDP\fR.
243 .ne 2
245 \fB\fBRES_IGNTC\fR\fR
247 .RS 17n
248 Ignore truncation errors; that is, do not retry with \fBTCP\fR.
252 .ne 2
254 \fB\fBRES_RECURSE\fR\fR
256 .RS 17n
257 Set the recursion-desired bit in queries. This is the default. \fBres_send()\fR
258 and \fBres_nsend()\fR do not do iterative queries and expect the name server to
259 handle recursion.
263 .ne 2
265 \fB\fBRES_DEFNAMES\fR\fR
267 .RS 17n
268 If set, \fBres_search()\fR and \fBres_nsearch()\fR append the default domain
269 name to single-component names, that is, names that do not contain a dot. This
270 option is enabled by default.
274 .ne 2
276 \fB\fBRES_DNSRCH\fR\fR
278 .RS 17n
279 If this option is set, \fBres_search()\fR and \fBres_nsearch()\fR search for
280 host names in the current domain and in parent domains. See \fBhostname\fR(1).
281 This option is used by the standard host lookup routine
282 \fBgethostbyname\fR(3NSL). This option is enabled by default.
286 .ne 2
288 \fB\fBRES_NOALIASES\fR\fR
290 .RS 17n
291 This option turns off the user level aliasing feature controlled by the
292 \fBHOSTALIASES\fR environment variable. Network daemons should set this option.
296 .ne 2
298 \fB\fBRES_BLAST\fR\fR
300 .RS 17n
301 If the \fBRES_BLAST\fR option is defined, \fBresolver()\fR queries will be sent
302 to all servers. If the \fBRES_BLAST\fR option is not defined, but
303 \fBRES_ROTATE\fR is , the list of nameservers are rotated according to a
304 round-robin scheme. \fBRES_BLAST\fR overrides \fBRES_ROTATE\fR.
308 .ne 2
310 \fB\fBRES_ROTATE\fR\fR
312 .RS 17n
313 This option causes \fBres_nsend()\fR and \fBres_send()\fR to rotate the list of
314 nameservers in \fBstatp->nsaddr_list\fR or \fB_res.nsaddr_list\fR.
318 .ne 2
320 \fB\fBRES_KEEPTSIG\fR\fR
322 .RS 17n
323 This option causes \fBres_nsendsigned()\fR to leave the message unchanged after
324 \fBTSIG\fR verification. Otherwise the \fBTSIG\fR record would be removed and
325 the header would be updated.
328 .SS "\fBres_ninit()\fR, \fBres_init()\fR"
330 The \fBres_ninit()\fR and \fBres_init()\fR routines read the configuration
331 file, if any is present, to get the default domain name, search list and the
332 Internet address of the local name server(s). See \fBresolv.conf\fR(4). If no
333 server is configured, \fBres_init()\fR or \fBres_ninit()\fR will try to obtain
334 name resolution services from the host on which it is running. The current
335 domain name is defined by \fBdomainname\fR(8), or by the hostname if it is not
336 specified in the configuration file. Use the environment variable
337 \fBLOCALDOMAIN\fR to override the domain name. This environment variable may
338 contain several blank-separated tokens if you wish to override the search list
339 on a per-process basis. This is similar to the search command in the
340 configuration file. You can set the \fBRES_OPTIONS\fR environment variable to
341 override certain internal resolver options. You can otherwise set them by
342 changing fields in the \fBstatp\fR /\fB_res\fR structure. Alternatively, they
343 are inherited from the configuration file's \fBoptions\fR command. See
344 \fBresolv.conf\fR(4) for information regarding the syntax of the
345 \fBRES_OPTIONS\fR environment variable. Initialization normally occurs on the
346 first call to one of the other resolver routines.
347 .SS "\fBres_nquery()\fR, \fBres_query()\fR"
349 The \fBres_nquery()\fR and \fBres_query()\fR functions provide interfaces to
350 the server query mechanism. They construct a query, send it to the local
351 server, await a response, and make preliminary checks on the reply. The query
352 requests information of the specified \fItype\fR and \fIclass\fR for the
353 specified fully-qualified domain name \fIdname\fR. The reply message is left in
354 the \fIanswer\fR buffer with length \fIanslen\fR supplied by the caller.
355 \fBres_nquery()\fR and \fBres_query()\fR return the length of the \fIanswer\fR,
356 or -1 upon error.
359 The \fBres_nquery()\fR and \fBres_query()\fR routines return a length that may
360 be bigger than \fIanslen\fR. In that case, retry the query with a larger
361 \fIbuf\fR. The \fIanswer\fR to the second query may be larger still], so it is
362 recommended that you supply a \fIbuf\fR larger than the \fIanswer\fR returned
363 by the previous query. \fIanswer\fR must be large enough to receive a maximum
364 \fBUDP\fR response from the server or parts of the \fIanswer\fR will be
365 silently discarded. The default maximum \fBUDP\fR response size is 512 bytes.
366 .SS "\fBres_nsearch()\fR, \fBres_search()\fR"
368 The \fBres_nsearch()\fR and \fBres_search()\fR routines make a query and await
369 a response, just like like \fBres_nquery()\fR and \fBres_query()\fR. In
370 addition, they implement the default and search rules controlled by the
371 \fBRES_DEFNAMES\fR and \fBRES_DNSRCH\fR options. They return the length of the
372 first successful reply which is stored in \fIanswer\fR. On error, they reurn
376 The \fBres_nsearch()\fR and \fBres_search()\fR routines return a length that
377 may be bigger than \fIanslen\fR. In that case, retry the query with a larger
378 \fIbuf\fR. The \fIanswer\fR to the second query may be larger still], so it is
379 recommended that you supply a \fIbuf\fR larger than the \fIanswer\fR returned
380 by the previous query. \fIanswer\fR must be large enough to receive a maximum
381 \fBUDP\fR response from the server or parts of the \fIanswer\fR will be
382 silently discarded. The default maximum \fBUDP\fR response size is 512 bytes.
383 .SS "\fBres_nquerydomain()\fR"
385 The \fBres_nquerydomain()\fR function calls \fBres_query()\fR on the
386 concatenation of \fIname\fR and \fIdomain\fR, removing a trailing dot from
387 \fIname\fR if \fIdomain\fR is \fINULL\fR.
388 .SS "\fBres_nmkquery()\fR, \fBres_mkquery()\fR"
390 These routines are used by \fBres_nquery()\fR and \fBres_query()\fR. The
391 \fBres_nmkquery()\fR and \fBres_mkquery()\fR functions construct a standard
392 query message and place it in \fIbuf\fR. The routine returns the \fIsize\fR of
393 the query, or -1 if the query is larger than \fIbuflen\fR. The query type
394 \fIop\fR is usually \fBQUERY\fR, but can be any of the query types defined in
395 <\fBarpa/nameser.h\fR>. The domain name for the query is given by \fIdname\fR.
396 \fInewrr\fR is currently unused but is intended for making update messages.
397 .SS "\fBres_nsend()\fR, \fBres_send()\fR, \fBres_nsendsigned()\fR"
399 The \fBres_nsend()\fR, \fBres_send()\fR, and \fBres_nsendsigned()\fR routines
400 send a pre-formatted query that returns an \fIanswer\fR. The routine calls
401 \fBres_ninit()\fR or \fBres_init()\fR. If \fBRES_INIT\fR is not set, the
402 routine sends the query to the local name server and handles timeouts and
403 retries. Additionally, the \fBres_nsendsigned()\fR uses \fBTSIG\fR signatures
404 to add authentication to the query and verify the response. In this case, only
405 one name server will be contacted. The routines return the length of the reply
406 message, or -1 if there are errors.
409 The \fBres_nsend()\fR and \fBres_send()\fR routines return a length that may be
410 bigger than \fIanslen\fR. In that case, retry the query with a larger
411 \fIbuf\fR. The \fIanswer\fR to the second query may be larger still], so it is
412 recommended that you supply a \fIbuf\fR larger than the \fIanswer\fR returned
413 by the previous query. \fIanswer\fR must be large enough to receive a maximum
414 \fBUDP\fR response from the server or parts of the \fIanswer\fR will be
415 silently discarded. The default maximum \fBUDP\fR response size is 512 bytes.
416 .SS "\fBfp_resstat()\fR"
418 The function \fBfp_resstat()\fR prints out the active flag bits in
419 \fIstatp\fR->\fBoptions\fR preceded by the text "\fB;; res options:\fR" on
420 \fIfile\fR.
421 .SS "\fBres_hostalias()\fR"
423 The function \fBres_hostalias()\fR looks up \fIname\fR in the file referred to
424 by the \fBHOSTALIASES\fR environment variable and returns the fully qualified
425 host name. If \fIname\fR is not found or an error occurs, \fBNULL\fR is
426 returned. \fBres_hostalias()\fR stores the result in \fIbuf\fR.
427 .SS "\fBres_nclose()\fR"
429 The \fBres_nclose()\fR function closes any open files referenced through
430 \fIstatp\fR.
431 .SS "\fBres_ndestroy()\fR"
433 The \fBres_ndestroy()\fR function calls \fBres_nclose()\fR, then frees any
434 memory allocated by \fBres_ninit()\fR referenced through \fIstatp\fR.
435 .SS "\fBdn_comp()\fR"
437 The \fBdn_comp()\fR function compresses the domain name \fIexp_dn\fR and stores
438 it in \fIcomp_dn\fR. The \fBdn_comp()\fR function returns the size of the
439 compressed name, or \fB\(mi1\fR if there were errors. \fIlength\fR is the size
440 of the array pointed to by \fIcomp_dn\fR.
443 The \fIdnptrs\fR parameter is a pointer to the head of the list of pointers to
444 previously compressed names in the current message. The first pointer must
445 point to the beginning of the message. The list ends with \fINULL\fR. The limit
446 to the array is specified by \fIlastdnptr\fR.
449 A side effect of calling \fBdn_comp()\fR is to update the list of pointers for
450 labels inserted into the message by \fBdn_comp()\fR as the name is compressed.
451 If \fIdnptrs\fR is \fINULL\fR, names are not compressed. If \fIlastdnptr\fR is
452 \fINULL\fR, \fBdn_comp()\fR does not update the list of labels.
453 .SS "\fBdn_expand()\fR"
455 The \fBdn_expand()\fR function expands the compressed domain name \fIcomp_dn\fR
456 to a full domain name. The compressed name is contained in a query or reply
457 message. \fImsg\fR is a pointer to the beginning of that message. The
458 uncompressed name is placed in the buffer indicated by \fIexp_dn\fR, which is
459 of size \fIlength\fR. The \fBdn_expand()\fR function returns the size of the
460 compressed name, or \fB\(mi1\fR if there was an error.
461 .SS "\fBhstrerror()\fR, \fBherror()\fR"
463 The variables \fIstatp->res_h_errno\fR and \fI_res.res_h_errno\fR and external
464 variable \fIh_errno\fR are set whenever an error occurs during a resolver
465 operation. The following definitions are given in <\fBnetdb.h\fR>:
467 .in +2
469 #define NETDB_INTERNAL -1 /* see errno */
470 #define NETDB_SUCCESS  0  /* no problem */
471 #define HOST_NOT_FOUND 1  /* Authoritative Answer Host not found */
472 #define TRY_AGAIN      2  /* Non-Authoritative not found, or SERVFAIL */
473 #define NO_RECOVERY    3  /* Non-Recoverable: FORMERR, REFUSED, NOTIMP*/
474 #define NO_DATA        4  /* Valid name, no data for requested type */
476 .in -2
481 The \fBherror()\fR function writes a message to the diagnostic output
482 consisting of the string parameters, the constant string "\fB:\fR", and a
483 message corresponding to the value of \fIh_errno\fR.
486 The \fBhstrerror()\fR function returns a string, which is the message text that
487 corresponds to the value of the \fIerr\fR parameter.
488 .SS "\fBres_setservers()\fR, \fBres_getservers()\fR"
490 The functions \fBres_getservers()\fR and \fBres_setservers()\fR are used to get
491 and set the list of servers to be queried.
492 .SH FILES
493 .ne 2
495 \fB\fB/etc/resolv.conf\fR\fR
497 .RS 20n
498 resolver configuration file
501 .SH ATTRIBUTES
503 See \fBattributes\fR(5) for descriptions of the following attributes:
508 box;
509 c | c
510 l | l .
511 ATTRIBUTE TYPE  ATTRIBUTE VALUE
512 Interface Stability     Committed
514 MT-Level        T{
515 Unsafe for deprecated interfaces; MT-Safe for all others.
519 .SH SEE ALSO
521 \fBdomainname\fR(8), \fBgethostbyname\fR(3NSL), \fBlibresolv\fR(3LIB),
522 \fBresolv.conf\fR(4), \fBattributes\fR(5)
525 Lottor, M. \fIRFC 1033, Domain Administrators Operations Guide\fR. Network
526 Working Group. November 1987.
529 Mockapetris, Paul. \fIRFC 1034, Domain Names - Concepts and Facilities\fR.
530 Network Working Group. November 1987.
533 Mockapetris, Paul. \fIRFC 1035, Domain Names - Implementation and
534 Specification\fR. Network Working Group. November 1987.
537 Partridge, Craig. \fIRFC 974, Mail Routing and the Domain System\fR. Network
538 Working Group. January 1986.
541 Stahl, M. \fIRFC 1032, Domain Administrators Guide\fR. Network Working Group.
542 November 1987.
545 Vixie, Paul, Dunlap, Kevin J., Karels, Michael J. \fIName Server Operations
546 Guide for BIND\fR. Internet Software Consortium, 1996.
547 .SH NOTES
549 When the caller supplies a work buffer, for example the \fIanswer\fR buffer
550 argument to \fBres_nsend()\fR or \fBres_send()\fR, the buffer should be aligned
551 on an eight byte boundary. Otherwise, an error such as a \fBSIGBUS\fR may
552 result.