1 .\" $NetBSD: resolver.3,v 1.28 2013/11/14 00:13:41 wiz Exp $
2 .\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
4 .\" Permission to use, copy, modify, and distribute this software for any
5 .\" purpose with or without fee is hereby granted, provided that the above
6 .\" copyright notice and this permission notice appear in all copies.
8 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
9 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
11 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14 .\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 .\" Copyright (c) 1985, 1995 The Regents of the University of California.
17 .\" All rights reserved.
19 .\" Redistribution and use in source and binary forms are permitted provided
20 .\" that: (1) source distributions retain this entire copyright notice and
21 .\" comment, and (2) distributions including binaries display the following
22 .\" acknowledgement: ``This product includes software developed by the
23 .\" University of California, Berkeley and its contributors'' in the
24 .\" documentation or other materials provided with the distribution and in
25 .\" all advertising materials mentioning features or use of this software.
26 .\" Neither the name of the University nor the names of its contributors may
27 .\" be used to endorse or promote products derived from this software without
28 .\" specific prior written permission.
29 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
30 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
31 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
33 .\" @(#)resolver.3 6.5 (Berkeley) 6/23/90
34 .\" Id: resolver.man3,v 1.2 2009/01/21 00:12:34 each Exp
47 .Nm res_nquerydomain ,
81 .Vt typedef struct __res_state *res_state ;
84 .Fn res_ninit "res_state statp"
86 .Fn res_ourserver_p "const res_state statp" "const struct sockaddr_in *addr"
88 .Fn fp_resstat "const res_state statp" "FILE *fp"
90 .Fn res_hostalias "const res_state statp" "const char *name" "char *buf" "size_t buflen"
92 .Fn res_pquery "const res_state statp" "const u_char *msg" "int msglen" "FILE *fp"
94 .Fn res_nquery "res_state statp" "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
96 .Fn res_nsearch "res_state statp" "const char *dname" "int class" "int type" "u_char * answer" "int anslen"
98 .Fn res_nquerydomain "res_state statp" "const char *name" "const char *domain" "int class" "int type" "u_char *answer" "int anslen"
101 .Fa "res_state statp"
103 .Fa "const char *dname"
106 .Fa "const u_char *data"
108 .Fa "const u_char *newrr"
113 .Fn res_nsend "res_state statp" "const u_char *msg" "int msglen" "u_char *answer" "int anslen"
115 .Fn res_nupdate "res_state statp" "ns_updrec *rrecp_in"
117 .Fn res_nmkupdate "res_state statp" "ns_updrec *rrecp_in" "u_char *buf" "int buflen"
119 .Fn res_nclose "res_state statp"
121 .Fn res_nsendsigned "res_state statp" "const u_char *msg" "int msglen" "ns_tsig_key *key" "u_char *answer" "int anslen"
123 .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"
125 .Fn res_getservers "res_state statp" "union res_sockaddr_union *set" "int cnt"
127 .Fn res_setservers "res_state statp" "const union res_sockaddr_union *set" "int cnt"
129 .Fn res_ndestroy "res_state statp"
131 .Fn dn_comp "const char *exp_dn" "u_char *comp_dn" "int length" "u_char **dnptrs" "u_char **lastdnptr"
133 .Fn dn_expand "const u_char *msg" "const u_char *eomorig" "const u_char *comp_dn" "char *exp_dn" "int length"
134 .\" .Ft "const char *"
135 .\" .Fn hstrerror "int err"
145 .Fn res_isourserver "const struct sockaddr_in *addr"
147 .Fn fp_nquery "const u_char *msg" "int msglen" "FILE *fp"
149 .Fn p_query "const u_char *msg" "FILE *fp"
151 .Fn hostalias "const char *name"
153 .Fn res_query "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
155 .Fn res_search "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
157 .Fn res_querydomain "const char *name" "const char *domain" "int class" "int type" "u_char *answer" "int anslen"
161 .Fa "const char *dname"
164 .Fa "const char *data"
166 .Fa "struct rrec *newrr"
171 .Fn res_send "const u_char *msg" "int msglen" "u_char *answer" "int anslen"
173 .Fn res_update "ns_updrec *rrecp_in"
177 .\" .Fn herror "const char *s"
179 These routines are used for making, sending and interpreting
180 query and reply messages with Internet domain name servers.
182 State information is kept in
184 and is used to control the behavior of these functions.
186 should be set to all zeros prior to the first call to any of these functions.
190 .Fn res_isourserver ,
196 .Fn res_querydomain ,
203 are deprecated and are supplied for compatability with old source
205 They use global configuration and state information that is
206 kept in the structure
208 rather than that referenced through
211 Most of the values in
215 are initialized on the first call to
219 to reasonable defaults and can be ignored.
228 Options are stored as a simple bit mask containing the bitwise
230 of the options enabled.
231 .Bl -tag -width "RES_USE_INET6"
233 True if the initial name server address and default domain name are
240 Print debugging messages.
242 Accept authoritative answers only.
243 Should continue until it finds an authoritative answer or finds an error.
244 Currently this is not implemented.
246 Use TCP connections for queries instead of UDP datagrams.
250 to keep the TCP connection open between queries.
251 This is useful only in programs that regularly do many queries.
252 UDP should be the normal mode used.
254 Ignore truncation errors, i.e., don't retry with TCP.
256 Set the recursion-desired bit in queries.
262 does not do iterative queries and expects the name server
263 to handle recursion.)
269 will append the default domain name to single-component names
270 (those that do not contain a dot).
271 This option is enabled by default.
273 If this option is set,
277 will search for host names in the current domain and in parent domains; see
279 This is used by the standard host lookup routine
280 .Xr gethostbyname 3 .
281 This option is enabled by default.
283 Enables support for IPv6-only applications.
284 This causes IPv4 addresses to be returned as an IPv4 mapped address.
285 For example, 10.1.1.1 will be returned as ::ffff:10.1.1.1.
286 The option is meaningful with certain kernel configuration only.
288 Enables support for OPT pseudo-RR for EDNS0 extension.
289 With the option, resolver code will attach OPT pseudo-RR into DNS queries,
290 to inform of our receive buffer size.
291 The option will allow DNS servers to take advantage of non-default receive
292 buffer size, and to send larger replies.
293 DNS query packets with EDNS0 extension is not compatible with
294 non-EDNS0 DNS servers.
296 This option turns off the user level aliasing feature controlled by
299 environment variable.
300 Network daemons should set this option.
302 This options causes the
306 to rotate the list of nameservers in
307 .Fa statp->nsaddr_list
309 .Fa _res.nsaddr_list .
313 to leave the message unchanged after TSIG verification; otherwise the TSIG
314 record would be removed and the header updated.
315 .It Dv RES_NOTLDQUERY
318 to not attempt to resolve an unqualified name as if it were a top level
320 This option can cause problems if the site has "localhost" as a TLD rather
321 than having localhost on one or more elements of the search list.
322 This option has no effect if neither
334 reads the configuration file (if any; see
336 to get the default domain name, search list and
337 the Internet address of the local name server(s).
338 If no server is configured, the host running the resolver is tried.
339 The current domain name is defined by the hostname
340 if not specified in the configuration file;
341 it can be overridden by the environment variable
343 This environment variable may contain several blank-separated
344 tokens if you wish to override the
346 on a per-process basis.
347 This is similar to the
349 command in the configuration file.
350 Another environment variable
352 can be set to override certain internal resolver options which are otherwise
353 set by changing fields in the
357 structure or are inherited from the configuration file's
362 environment variable is explained in
364 Initialization normally occurs on the first call
365 to one of the other resolver routines.
369 the initialization code also sets up a
373 watching a file descriptor that points to the resolver file.
374 Every resolver function calls the internal function
376 which checks for a new
380 file, and reloads the file if necessary.
381 This does not work if the file is accessed through a symlink and the symlink
382 changes to point to a different file.
383 To fix the symlink issue one could add a system call per resolver call to
384 get the current time, and reload every so often.
385 This is not done currently, but it is under consideration.
387 The memory referred to by
389 must be set to all zeros prior to the first call to
392 should be call to free memory allocated by
400 functions provides interfaces to the server query mechanism.
401 They constructs a query, sends it to the local server,
402 awaits a response, and makes preliminary checks on the reply.
403 The query requests information of the specified
407 for the specified fully-qualified domain name
409 The reply message is left in the
413 supplied by the caller.
417 return \-1 on error or the length of the answer.
423 routines make a query and awaits a response like
427 but in addition, it implements the default and search rules
433 It returns the length of the first successful reply which is stored in
437 The remaining routines are lower-level routines used by
446 constructs a standard query message and places it in
448 It returns the size of the query, or \-1 if the query is
455 but can be any of the query types defined in
456 .Aq Pa arpa/nameser.h .
457 The domain name for the query is given by
460 is currently unused but is intended for making update messages.
469 sends a pre-formatted query and returns an answer.
476 is not set, send the query to the local name server, and
477 handle timeouts and retries.
480 will use TSIG signatures to add authentication to the query and verify the
482 In this case, only one nameserver will be contacted.
483 The length of the reply message is returned, or \-1 if there were errors.
495 return a length that may be bigger than
497 In that case the query should be retried with a bigger buffer.
498 NOTE the answer to the second query may be larger still so supplying
499 a buffer that bigger that the answer returned by the previous
500 query is recommended.
503 MUST be big enough to receive a maximum UDP response from the server or
504 parts of the answer will be silently discarded.
505 The default maximum UDP response size is 512 bytes.
511 is one of the servers in
512 .Fa statp->nsaddr_list
514 .Fa _res.nsaddr_list .
520 print out the query and any answer in
533 prints out the active flag bits in
535 preceeded by the text ";; res options:" on
542 lookup up name in the file referred to by the
544 files return a fully qualified hostname if found or NULL if
545 not found or an error occurred.
549 to store the result in,
551 uses a static buffer.
557 are used to get and set the list of server to be queried.
563 take a list of ns_updrec
565 Identifies the containing zone for each record and groups the records
566 according to containing zone maintaining in zone order then sends and update
567 request to the servers for these zones.
568 The number of zones updated is returned or \-1 on error.
571 will perform TSIG authenticated dynamic update operations if the key is not
576 discovers the closest enclosing zone cut for a specified domain name,
577 and finds the IP addresses of the zone's master servers.
583 take a linked list of ns_updrec
585 and construct a UPDATE message in
590 return the length of the constructed message on no error or one of the
591 following error values.
592 .Bl -inset -width "-5"
594 An error occurred parsing
601 The first record was not a zone section or there was a section order problem.
602 The section order is S_ZONE, S_PREREQ and S_UPDATE.
604 A number overflow occurred.
606 Unknown operation or no records.
613 close any open files referenced through
622 then frees any memory allocated by
628 compresses the domain name
632 The size of the compressed name is returned or \-1 if there were errors.
633 The size of the array pointed to by
640 to previously-compressed names in the current message.
641 The first pointer points to
642 the beginning of the message and the list ends with
644 The limit to the array is specified by
648 is to update the list of pointers for labels inserted into the message
649 as the name is compressed.
654 names are not compressed.
659 the list of labels is not updated.
663 entry expands the compressed domain name
665 to a full domain name.
666 The compressed name is contained in a query or reply message;
668 is a pointer to the beginning of the message.
670 is a pointer to the first location after the message.
671 The uncompressed name is placed in the buffer indicated by
675 The size of compressed name is returned or \-1 if there was an error.
678 .Ft statp->res_h_errno
681 and external variable
683 is set whenever an error occurs during resolver operation.
685 definitions are given in
688 #define NETDB_INTERNAL -1
690 #define NETDB_SUCCESS 0
692 #define HOST_NOT_FOUND 1
693 /* Authoritative Answer Host not found */
695 /* Non-Authoritative not found, or SERVFAIL */
696 #define NO_RECOVERY 3
697 /* Non-Recoverable: FORMERR, REFUSED, NOTIMP */
699 /* Valid name, no data for requested type */
704 .\" function writes a message to the diagnostic output consisting of the string
707 .\" the constant string ": ", and a message corresponding to the value of
712 .\" function returns a string which is the message text corresponding to the
717 The following functions are only in
719 .Fn res_findzonecut ,
721 .Fn res_nsendsigned ,
724 All the rest are in both
729 .Bl -tag -width "/etc/resolv.conf "
730 .It Pa /etc/resolv.conf
731 The configuration file, see
736 .Xr gethostbyaddr 3 ,
737 .Xr gethostbyname 3 ,
750 .%T "Name Server Operations Guide for BIND"