1 .\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 .\" Permission to use, copy, modify, and distribute this software for any
4 .\" purpose with or without fee is hereby granted, provided that the above
5 .\" copyright notice and this permission notice appear in all copies.
7 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
8 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
10 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 .\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 .\" Copyright (c) 1985, 1995 The Regents of the University of California.
16 .\" All rights reserved.
18 .\" Redistribution and use in source and binary forms are permitted provided
19 .\" that: (1) source distributions retain this entire copyright notice and
20 .\" comment, and (2) distributions including binaries display the following
21 .\" acknowledgement: ``This product includes software developed by the
22 .\" University of California, Berkeley and its contributors'' in the
23 .\" documentation or other materials provided with the distribution and in
24 .\" all advertising materials mentioning features or use of this software.
25 .\" Neither the name of the University nor the names of its contributors may
26 .\" be used to endorse or promote products derived from this software without
27 .\" specific prior written permission.
28 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
29 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
30 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32 .\" @(#)resolver.3 6.5 (Berkeley) 6/23/90
33 .\" Id: resolver.man3,v 1.2 2009/01/21 00:12:34 each Exp
46 .Nm res_nquerydomain ,
75 .Fd #include <sys/types.h>
76 .Fd #include <netinet/in.h>
77 .Fd #include <arpa/nameser.h>
78 .Fd #include <resolv.h>
79 .Fd #include <res_update.h>
80 .Vt typedef struct __res_state *res_state ;
83 .Fn res_ninit "res_state statp"
85 .Fn res_ourserver_p "const res_state statp" "const struct sockaddr_in *addr"
87 .Fn fp_resstat "const res_state statp" "FILE *fp"
89 .Fn res_hostalias "const res_state statp" "const char *name" "char *buf" "size_t buflen"
91 .Fn res_pquery "const res_state statp" "const u_char *msg" "int msglen" "FILE *fp"
93 .Fn res_nquery "res_state statp" "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
95 .Fn res_nsearch "res_state statp" "const char *dname" "int class" "int type" "u_char * answer" "int anslen"
97 .Fn res_nquerydomain "res_state statp" "const char *name" "const char *domain" "int class" "int type" "u_char *answer" "int anslen"
100 .Fa "res_state statp"
102 .Fa "const char *dname"
105 .Fa "const u_char *data"
107 .Fa "const u_char *newrr"
112 .Fn res_nsend "res_state statp" "const u_char *msg" "int msglen" "u_char *answer" "int anslen"
114 .Fn res_nupdate "res_state statp" "ns_updrec *rrecp_in"
116 .Fn res_nmkupdate "res_state statp" "ns_updrec *rrecp_in" "u_char *buf" "int buflen"
118 .Fn res_nclose "res_state statp"
120 .Fn res_nsendsigned "res_state statp" "const u_char *msg" "int msglen" "ns_tsig_key *key" "u_char *answer" "int anslen"
122 .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"
124 .Fn res_getservers "res_state statp" "union res_sockaddr_union *set" "int cnt"
126 .Fn res_setservers "res_state statp" "const union res_sockaddr_union *set" "int cnt"
128 .Fn res_ndestroy "res_state statp"
130 .Fn dn_comp "const char *exp_dn" "u_char *comp_dn" "int length" "u_char **dnptrs" "u_char **lastdnptr"
132 .Fn dn_expand "const u_char *msg" "const u_char *eomorig" "const u_char *comp_dn" "char *exp_dn" "int length"
134 .Fn hstrerror "int err"
136 .Fd #include <sys/types.h>
137 .Fd #include <netinet/in.h>
138 .Fd #include <arpa/nameser.h>
139 .Fd #include <resolv.h>
140 .Fd #include <res_update.h>
144 .Fn res_isourserver "const struct sockaddr_in *addr"
146 .Fn fp_nquery "const u_char *msg" "int msglen" "FILE *fp"
148 .Fn p_query "const u_char *msg" "FILE *fp"
150 .Fn hostalias "const char *name"
152 .Fn res_query "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
154 .Fn res_search "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
156 .Fn res_querydomain "const char *name" "const char *domain" "int class" "int type" "u_char *answer" "int anslen"
160 .Fa "const char *dname"
163 .Fa "const char *data"
165 .Fa "struct rrec *newrr"
170 .Fn res_send "const u_char *msg" "int msglen" "u_char *answer" "int anslen"
172 .Fn res_update "ns_updrec *rrecp_in"
176 .Fn herror "const char *s"
178 These routines are used for making, sending and interpreting
179 query and reply messages with Internet domain name servers.
181 State information is kept in
183 and is used to control the behavior of these functions.
185 should be set to all zeros prior to the first call to any of these functions.
189 .Fn res_isourserver ,
195 .Fn res_querydomain ,
202 are deprecated and are supplied for compatability with old source
204 They use global configuration and state information that is
205 kept in the structure
207 rather than that referenced through
210 Most of the values in
214 are initialized on the first call to
218 to reasonable defaults and can be ignored.
227 Options are stored as a simple bit mask containing the bitwise
229 of the options enabled.
230 .Bl -tag -width "RES_DEB"
232 True if the initial name server address and default domain name are
239 Print debugging messages.
241 Accept authoritative answers only.
242 Should continue until it finds an authoritative answer or finds an error.
243 Currently this is not implemented.
245 Use TCP connections for queries instead of UDP datagrams.
249 to keep the TCP connection open between queries.
250 This is useful only in programs that regularly do many queries.
251 UDP should be the normal mode used.
253 Ignore truncation errors, i.e., don't retry with TCP.
255 Set the recursion-desired bit in queries.
261 does not do iterative queries and expects the name server
262 to handle recursion.)
268 will append the default domain name to single-component names
269 (those that do not contain a dot).
270 This option is enabled by default.
272 If this option is set,
276 will search for host names in the current domain and in parent domains; see
278 This is used by the standard host lookup routine
279 .Xr gethostbyname 3 .
280 This option is enabled by default.
282 This option turns off the user level aliasing feature controlled by
285 environment variable.
286 Network daemons should set this option.
290 to look for AAAA records before looking for A records if none are found.
292 This options causes the
296 to rotate the list of nameservers in
297 .Fa statp->nsaddr_list
299 .Fa _res.nsaddr_list .
303 to leave the message unchanged after TSIG verification; otherwise the TSIG
304 record would be removed and the header updated.
305 .It Dv RES_NOTLDQUERY
308 to not attempt to resolve a unqualified name as if it were a top level
310 This option can cause problems if the site has "localhost" as a TLD rather
311 than having localhost on one or more elements of the search list.
312 This option has no effect if neither
324 reads the configuration file (if any; see
326 to get the default domain name, search list and
327 the Internet address of the local name server(s).
328 If no server is configured, the host running the resolver is tried.
329 The current domain name is defined by the hostname
330 if not specified in the configuration file;
331 it can be overridden by the environment variable
333 This environment variable may contain several blank-separated
334 tokens if you wish to override the
336 on a per-process basis. This is similar to the
338 command in the configuration file.
339 Another environment variable
340 .Pq Dq Ev RES_OPTIONS
341 can be set to override certain internal resolver options which are otherwise
342 set by changing fields in the
346 structure or are inherited from the configuration file's
348 command. The syntax of the
350 environment variable is explained in
352 Initialization normally occurs on the first call
353 to one of the other resolver routines.
355 The memory referred to by
357 must be set to all zeros prior to the first call to
360 should be call to free memory allocated by
368 functions provides interfaces to the server query mechanism.
369 They constructs a query, sends it to the local server,
370 awaits a response, and makes preliminary checks on the reply.
371 The query requests information of the specified
375 for the specified fully-qualified domain name
377 The reply message is left in the
381 supplied by the caller.
385 return -1 on error or the length of the answer.
391 routines make a query and awaits a response like
395 but in addition, it implements the default and search rules
401 It returns the length of the first successful reply which is stored in
405 The remaining routines are lower-level routines used by
414 constructs a standard query message and places it in
416 It returns the size of the query, or \-1 if the query is
423 but can be any of the query types defined in
424 .Pa <arpa/nameser.h> .
425 The domain name for the query is given by
428 is currently unused but is intended for making update messages.
437 sends a pre-formatted query and returns an answer.
444 is not set, send the query to the local name server, and
445 handle timeouts and retries. Additionally,
447 will use TSIG signatures to add authentication to the query and verify the
448 response. In this case, only one nameserver will be contacted.
449 The length of the reply message is returned, or \-1 if there were errors.
461 return a length that may be bigger than
463 In that case the query should be retried with a bigger buffer.
464 NOTE the answer to the second query may be larger still so supplying
465 a buffer that bigger that the answer returned by the previous
466 query is recommended.
469 MUST be big enough to receive a maximum UDP response from the server or
470 parts of the answer will be silently discarded.
471 The default maximum UDP response size is 512 bytes.
477 is one of the servers in
478 .Fa statp->nsaddr_list
480 .Fa _res.nsaddr_list .
486 print out the query and any answer in
499 prints out the active flag bits in
501 preceeded by the text ";; res options:" on
508 lookup up name in the file referred to by the
510 files return a fully qualified hostname if found or NULL if
511 not found or an error occurred.
515 to store the result in,
517 uses a static buffer.
523 are used to get and set the list of server to be queried.
529 take a list of ns_updrec
531 Identifies the containing zone for each record and groups the records
532 according to containing zone maintaining in zone order then sends and update
533 request to the servers for these zones. The number of zones updated is
534 returned or -1 on error. Note that
536 will perform TSIG authenticated dynamic update operations if the key is not
541 discovers the closest enclosing zone cut for a specified domain name,
542 and finds the IP addresses of the zone's master servers.
548 take a linked list of ns_updrec
550 and construct a UPDATE message in
555 return the length of the constructed message on no error or one of the
556 following error values.
557 .Bl -inset -width "-5"
559 An error occurred parsing
566 The first record was not a zone section or there was a section order problem.
567 The section order is S_ZONE, S_PREREQ and S_UPDATE.
569 A number overflow occurred.
571 Unknown operation or no records.
578 close any open files referenced through
587 then frees any memory allocated by
593 compresses the domain name
597 The size of the compressed name is returned or \-1 if there were errors.
598 The size of the array pointed to by
605 to previously-compressed names in the current message.
606 The first pointer points to
607 to the beginning of the message and the list ends with
609 The limit to the array is specified by
613 is to update the list of pointers for labels inserted into the message
614 as the name is compressed. If
618 names are not compressed. If
622 the list of labels is not updated.
627 expands the compressed domain name
629 to a full domain name.
630 The compressed name is contained in a query or reply message;
632 is a pointer to the beginning of the message.
634 is a pointer to the first location after the message.
635 The uncompressed name is placed in the buffer indicated by
639 The size of compressed name is returned or \-1 if there was an error.
642 .Ft statp->res_h_errno
645 and external variable
647 is set whenever an error occurs during resolver operation. The following
648 definitions are given in
651 #define NETDB_INTERNAL -1 /* see errno */
652 #define NETDB_SUCCESS 0 /* no problem */
653 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
654 #define TRY_AGAIN 2 /* Non-Authoritative not found, or SERVFAIL */
655 #define NO_RECOVERY 3 /* Non-Recoverable: FORMERR, REFUSED, NOTIMP */
656 #define NO_DATA 4 /* Valid name, no data for requested type */
661 function writes a message to the diagnostic output consisting of the string
664 the constant string ": ", and a message corresponding to the value of
669 function returns a string which is the message text corresponding to the
674 .Bl -tag -width "/etc/resolv.conf "
675 .It Pa /etc/resolv.conf
680 .Xr gethostbyname 3 ,
683 RFC1032, RFC1033, RFC1034, RFC1035, RFC974;
685 .Dq Name Server Operations Guide for BIND