3 .\" Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
5 .\" Permission to use, copy, modify, and/or distribute this software for any
6 .\" purpose with or without fee is hereby granted, provided that the above
7 .\" copyright notice and this permission notice appear in all copies.
9 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 .\" PERFORMANCE OF THIS SOFTWARE.
17 .\" Id: resolver.3,v 1.3 2009/01/22 23:49:23 tbox Exp
20 .Dt RESOLVER @LIB_NETWORK_EXT_U@
30 .Nm res_nquerydomain ,
59 .Fd #include <sys/types.h>
60 .Fd #include <netinet/in.h>
61 .Fd #include <arpa/nameser.h>
62 .Fd #include <resolv.h>
63 .Fd #include <res_update.h>
64 .Vt typedef struct __res_state *res_state ;
67 .Fn res_ninit "res_state statp"
69 .Fn res_ourserver_p "const res_state statp" "const struct sockaddr_in *addr"
71 .Fn fp_resstat "const res_state statp" "FILE *fp"
73 .Fn res_hostalias "const res_state statp" "const char *name" "char *buf" "size_t buflen"
75 .Fn res_pquery "const res_state statp" "const u_char *msg" "int msglen" "FILE *fp"
77 .Fn res_nquery "res_state statp" "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
79 .Fn res_nsearch "res_state statp" "const char *dname" "int class" "int type" "u_char * answer" "int anslen"
81 .Fn res_nquerydomain "res_state statp" "const char *name" "const char *domain" "int class" "int type" "u_char *answer" "int anslen"
86 .Fa "const char *dname"
89 .Fa "const u_char *data"
91 .Fa "const u_char *newrr"
96 .Fn res_nsend "res_state statp" "const u_char *msg" "int msglen" "u_char *answer" "int anslen"
98 .Fn res_nupdate "res_state statp" "ns_updrec *rrecp_in"
100 .Fn res_nmkupdate "res_state statp" "ns_updrec *rrecp_in" "u_char *buf" "int buflen"
102 .Fn res_nclose "res_state statp"
104 .Fn res_nsendsigned "res_state statp" "const u_char *msg" "int msglen" "ns_tsig_key *key" "u_char *answer" "int anslen"
106 .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"
108 .Fn res_getservers "res_state statp" "union res_sockaddr_union *set" "int cnt"
110 .Fn res_setservers "res_state statp" "const union res_sockaddr_union *set" "int cnt"
112 .Fn res_ndestroy "res_state statp"
114 .Fn dn_comp "const char *exp_dn" "u_char *comp_dn" "int length" "u_char **dnptrs" "u_char **lastdnptr"
116 .Fn dn_expand "const u_char *msg" "const u_char *eomorig" "const u_char *comp_dn" "char *exp_dn" "int length"
118 .Fn hstrerror "int err"
120 .Fd #include <sys/types.h>
121 .Fd #include <netinet/in.h>
122 .Fd #include <arpa/nameser.h>
123 .Fd #include <resolv.h>
124 .Fd #include <res_update.h>
128 .Fn res_isourserver "const struct sockaddr_in *addr"
130 .Fn fp_nquery "const u_char *msg" "int msglen" "FILE *fp"
132 .Fn p_query "const u_char *msg" "FILE *fp"
134 .Fn hostalias "const char *name"
136 .Fn res_query "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
138 .Fn res_search "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
140 .Fn res_querydomain "const char *name" "const char *domain" "int class" "int type" "u_char *answer" "int anslen"
144 .Fa "const char *dname"
147 .Fa "const char *data"
149 .Fa "struct rrec *newrr"
154 .Fn res_send "const u_char *msg" "int msglen" "u_char *answer" "int anslen"
156 .Fn res_update "ns_updrec *rrecp_in"
160 .Fn herror "const char *s"
162 These routines are used for making, sending and interpreting
163 query and reply messages with Internet domain name servers.
165 State information is kept in
167 and is used to control the behavior of these functions.
169 should be set to all zeros prior to the first call to any of these functions.
173 .Fn res_isourserver ,
179 .Fn res_querydomain ,
186 are deprecated and are supplied for compatability with old source
188 They use global configuration and state information that is
189 kept in the structure
191 rather than that referenced through
194 Most of the values in
198 are initialized on the first call to
202 to reasonable defaults and can be ignored.
211 Options are stored as a simple bit mask containing the bitwise
213 of the options enabled.
214 .Bl -tag -width "RES_DEB"
216 True if the initial name server address and default domain name are
223 Print debugging messages.
225 Accept authoritative answers only.
226 Should continue until it finds an authoritative answer or finds an error.
227 Currently this is not implemented.
229 Use TCP connections for queries instead of UDP datagrams.
233 to keep the TCP connection open between queries.
234 This is useful only in programs that regularly do many queries.
235 UDP should be the normal mode used.
237 Ignore truncation errors, i.e., don't retry with TCP.
239 Set the recursion-desired bit in queries.
245 does not do iterative queries and expects the name server
246 to handle recursion.)
252 will append the default domain name to single-component names
253 (those that do not contain a dot).
254 This option is enabled by default.
256 If this option is set,
260 will search for host names in the current domain and in parent domains; see
261 .Xr hostname @DESC_EXT@ .
262 This is used by the standard host lookup routine
263 .Xr gethostbyname @LIB_NETWORK_EXT@ .
264 This option is enabled by default.
266 This option turns off the user level aliasing feature controlled by
269 environment variable.
270 Network daemons should set this option.
273 .Xr gethostbyname @LIB_NETWORK_EXT@
274 to look for AAAA records before looking for A records if none are found.
276 This options causes the
280 to rotate the list of nameservers in
281 .Fa statp->nsaddr_list
283 .Fa _res.nsaddr_list .
287 to leave the message unchanged after TSIG verification; otherwise the TSIG
288 record would be removed and the header updated.
289 .It Dv RES_NOTLDQUERY
292 to not attempt to resolve a unqualified name as if it were a top level
294 This option can cause problems if the site has "localhost" as a TLD rather
295 than having localhost on one or more elements of the search list.
296 This option has no effect if neither
308 reads the configuration file (if any; see
309 .Xr resolver @FORMAT_EXT@ )
310 to get the default domain name, search list and
311 the Internet address of the local name server(s).
312 If no server is configured, the host running the resolver is tried.
313 The current domain name is defined by the hostname
314 if not specified in the configuration file;
315 it can be overridden by the environment variable
317 This environment variable may contain several blank-separated
318 tokens if you wish to override the
320 on a per-process basis. This is similar to the
322 command in the configuration file.
323 Another environment variable
324 .Pq Dq Ev RES_OPTIONS
325 can be set to override certain internal resolver options which are otherwise
326 set by changing fields in the
330 structure or are inherited from the configuration file's
332 command. The syntax of the
334 environment variable is explained in
335 .Xr resolver @FORMAT_EXT@ .
336 Initialization normally occurs on the first call
337 to one of the other resolver routines.
339 The memory referred to by
341 must be set to all zeros prior to the first call to
344 should be call to free memory allocated by
352 functions provides interfaces to the server query mechanism.
353 They constructs a query, sends it to the local server,
354 awaits a response, and makes preliminary checks on the reply.
355 The query requests information of the specified
359 for the specified fully-qualified domain name
361 The reply message is left in the
365 supplied by the caller.
369 return -1 on error or the length of the answer.
375 routines make a query and awaits a response like
379 but in addition, it implements the default and search rules
385 It returns the length of the first successful reply which is stored in
389 The remaining routines are lower-level routines used by
398 constructs a standard query message and places it in
400 It returns the size of the query, or \-1 if the query is
407 but can be any of the query types defined in
408 .Pa <arpa/nameser.h> .
409 The domain name for the query is given by
412 is currently unused but is intended for making update messages.
421 sends a pre-formatted query and returns an answer.
428 is not set, send the query to the local name server, and
429 handle timeouts and retries. Additionally,
431 will use TSIG signatures to add authentication to the query and verify the
432 response. In this case, only one nameserver will be contacted.
433 The length of the reply message is returned, or \-1 if there were errors.
445 return a length that may be bigger than
447 In that case the query should be retried with a bigger buffer.
448 NOTE the answer to the second query may be larger still so supplying
449 a buffer that bigger that the answer returned by the previous
450 query is recommended.
453 MUST be big enough to receive a maximum UDP response from the server or
454 parts of the answer will be silently discarded.
455 The default maximum UDP response size is 512 bytes.
461 is one of the servers in
462 .Fa statp->nsaddr_list
464 .Fa _res.nsaddr_list .
470 print out the query and any answer in
483 prints out the active flag bits in
485 preceeded by the text ";; res options:" on
492 lookup up name in the file referred to by the
494 files return a fully qualified hostname if found or NULL if
495 not found or an error occurred.
499 to store the result in,
501 uses a static buffer.
507 are used to get and set the list of server to be queried.
513 take a list of ns_updrec
515 Identifies the containing zone for each record and groups the records
516 according to containing zone maintaining in zone order then sends and update
517 request to the servers for these zones. The number of zones updated is
518 returned or -1 on error. Note that
520 will perform TSIG authenticated dynamic update operations if the key is not
525 discovers the closest enclosing zone cut for a specified domain name,
526 and finds the IP addresses of the zone's master servers.
532 take a linked list of ns_updrec
534 and construct a UPDATE message in
539 return the length of the constructed message on no error or one of the
540 following error values.
541 .Bl -inset -width "-5"
543 An error occurred parsing
550 The first record was not a zone section or there was a section order problem.
551 The section order is S_ZONE, S_PREREQ and S_UPDATE.
553 A number overflow occurred.
555 Unknown operation or no records.
562 close any open files referenced through
571 then frees any memory allocated by
577 compresses the domain name
581 The size of the compressed name is returned or \-1 if there were errors.
582 The size of the array pointed to by
589 to previously-compressed names in the current message.
590 The first pointer points to
591 to the beginning of the message and the list ends with
593 The limit to the array is specified by
597 is to update the list of pointers for labels inserted into the message
598 as the name is compressed. If
602 names are not compressed. If
606 the list of labels is not updated.
611 expands the compressed domain name
613 to a full domain name.
614 The compressed name is contained in a query or reply message;
616 is a pointer to the beginning of the message.
618 is a pointer to the first location after the message.
619 The uncompressed name is placed in the buffer indicated by
623 The size of compressed name is returned or \-1 if there was an error.
626 .Ft statp->res_h_errno
629 and external variable
631 is set whenever an error occurs during resolver operation. The following
632 definitions are given in
635 #define NETDB_INTERNAL -1 /* see errno */
636 #define NETDB_SUCCESS 0 /* no problem */
637 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
638 #define TRY_AGAIN 2 /* Non-Authoritative not found, or SERVFAIL */
639 #define NO_RECOVERY 3 /* Non-Recoverable: FORMERR, REFUSED, NOTIMP */
640 #define NO_DATA 4 /* Valid name, no data for requested type */
645 function writes a message to the diagnostic output consisting of the string
648 the constant string ": ", and a message corresponding to the value of
653 function returns a string which is the message text corresponding to the
658 .Bl -tag -width "/etc/resolv.conf "
659 .It Pa /etc/resolv.conf
661 .Xr resolver @FORMAT_EXT@ .
664 .Xr gethostbyname @LIB_NETWORK_EXT@ ,
665 .Xr hostname @DESC_EXT@ ,
666 .Xr resolver @FORMAT_EXT@ ;
667 RFC1032, RFC1033, RFC1034, RFC1035, RFC974;
669 .Dq Name Server Operations Guide for BIND