1 .\" Copyright (c) 1985, 1995 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms are permitted provided
5 .\" that: (1) source distributions retain this entire copyright notice and
6 .\" comment, and (2) distributions including binaries display the following
7 .\" acknowledgement: ``This product includes software developed by the
8 .\" University of California, Berkeley and its contributors'' in the
9 .\" documentation or other materials provided with the distribution and in
10 .\" all advertising materials mentioning features or use of this software.
11 .\" Neither the name of the University nor the names of its contributors may
12 .\" be used to endorse or promote products derived from this software without
13 .\" specific prior written permission.
14 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
15 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
16 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 .\" @(#)resolver.3 6.5 (Berkeley) 6/23/90
19 .\" $Id: resolver.3,v 8.13 2000/12/05 02:37:33 vixie Exp $
32 .Nm res_nquerydomain ,
58 .Fd #include <sys/types.h>
59 .Fd #include <netinet/in.h>
60 .Fd #include <arpa/nameser.h>
61 .Fd #include <resolv.h>
62 .Ft typedef struct __res_state *res_state;
64 .Fn res_ninit "res_state statp"
65 .Fn res_ourserver_p "const res_state statp" "const struct sockaddr_in *addr"
66 .Fn fp_resstat "const res_state statp" "FILE *fp"
67 .Fn res_hostalias "const res_state statp" "const char *name" "char *buf" "size_t buflen"
68 .Fn res_pquery "const res_state statp" "const u_char *msg" "int msglen" "FILE *fp"
69 .Fn res_nquery "res_state statp" "const char *dname" "int class" "int type" "u_char *answer" "int anslen"
70 .Fn res_nsearch "res_state statp" "const char *dname" "int class" "int type" "u_char * answer" "int anslen"
71 .Fn res_nquerydomain "res_state statp" "const char *name" "const char *domain" "int class" "int type" "u_char *answer" "int anslen"
72 .Fn res_nmkquery "res_state statp, int op, const char *dname" "int class" "int type" "const u_char *data" "int datalen" "const u_char *newrr" "u_char *buf" "int buflen"
73 .Fn res_nsend "res_state statp" "const u_char *msg" "int msglen" "u_char *answer" "int anslen"
74 .Fn res_nupdate "res_state statp" "ns_updrec *rrecp_in"
75 .Fn res_nmkupdate "res_state statp" "ns_updrec *rrecp_in" "u_char *buf" "int buflen"
76 .Fn res_nclose "res_state statp"
77 .Fn res_nsendsigned "res_state statp" "const u_char *msg" "int msglen" "ns_tsig_key *key" "u_char *answer" "int anslen"
78 .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"
79 .Fn dn_comp "const char *exp_dn" "u_char *comp_dn" "int length" "u_char **dnptrs, **lastdnptr"
80 .Fn dn_expand "const u_char *msg, *eomorig, *comp_dn" "char *exp_dn" "int length"
81 .Fn hstrerror "int err"
84 .Fd #include <sys/types.h>
85 .Fd #include <netinet/in.h>
86 .Fd #include <arpa/nameser.h>
87 .Fd #include <resolv.h>
89 .Fn res_isourserver "const struct sockaddr_in *addr"
90 .Fn fp_nquery "const u_char *msg" "int msglen" "FILE *fp"
91 .Fn p_query "const u_char *msg" "FILE *fp"
92 .Fn hostalias "const char *name"
93 .Fn res_query "const char *dname" "int class, type" "u_char *answer" "int anslen"
94 .Fn res_search "const char *dname" "int class, type" "u_char *answer" "int anslen"
95 .Fn res_querydomain "const char *name" "const char *domain" "int class" "int type" "u_char *answer" "int anslen"
96 .Fn res_mkquery "int op" "const char *dname, int class, type" "const char *data" "int datalen" "struct rrec *newrr" "u_char *buf" "int buflen"
97 .Fn res_send "const u_char *msg" "int msglen" "u_char *answer" "int anslen"
98 .Fn res_update "ns_updrec *rrecp_in"
100 .Fn herror "const char *s"
102 These routines are used for making, sending and interpreting
103 query and reply messages with Internet domain name servers.
105 State information is kept in
107 and is used to control the behavior of these functions.
109 should be set to all zeros prior to the first call to any of these functions.
113 .Fn res_isourserver ,
119 .Fn res_querydomain ,
126 are deprecated and are supplied for compatability with old source
128 They use global configuration and state information that is
129 kept in the structure
131 rather than that referenced through
134 Most of the values in
138 are initialized on the first call to
142 to reasonable defaults and can be ignored.
151 Options are stored as a simple bit mask containing the bitwise
153 of the options enabled.
154 .Bl -tag -width "RES_DEB"
156 True if the initial name server address and default domain name are
163 Print debugging messages.
165 Accept authoritative answers only.
166 should continue until it finds an authoritative answer or finds an error.
167 Currently this is not implemented.
169 Use TCP connections for queries instead of UDP datagrams.
173 to keep the TCP connection open between queries.
174 This is useful only in programs that regularly do many queries.
175 UDP should be the normal mode used.
177 Ignore truncation errors, i.e., don't retry with TCP.
179 Set the recursion-desired bit in queries.
185 does not do iterative queries and expects the name server
186 to handle recursion.)
192 will append the default domain name to single-component names
193 (those that do not contain a dot).
194 This option is enabled by default.
196 If this option is set,
200 will search for host names in the current domain and in parent domains; see
202 This is used by the standard host lookup routine
203 .Xr gethostbyname 3 .
204 This option is enabled by default.
206 This option turns off the user level aliasing feature controlled by
209 environment variable.
210 Network daemons should set this option.
214 to look for AAAA records before looking for A records if none are found.
216 This options causes the
220 to rotate the list of nameservers in
221 .Fa statp->nsaddr_list
223 .Fa _res.nsaddr_list .
227 to leave the message unchanged after TSIG verification; otherwise the TSIG
228 record would be removed and the header updated.
236 reads the configuration file (if any; see
238 to get the default domain name, search list and
239 the Internet address of the local name server(s).
240 If no server is configured, the host running the resolver is tried.
241 The current domain name is defined by the hostname
242 if not specified in the configuration file;
243 it can be overridden by the environment variable
245 This environment variable may contain several blank-separated
246 tokens if you wish to override the
248 on a per-process basis. This is similar to the
250 command in the configuration file.
251 Another environment variable
252 .Pq Dq Ev RES_OPTIONS
253 can be set to override certain internal resolver options which are otherwise
254 set by changing fields in the
258 structure or are inherited from the configuration file's
260 command. The syntax of the
262 environment variable is explained in
264 Initialization normally occurs on the first call
265 to one of the other resolver routines.
271 functions provides interfaces to the server query mechanism.
272 They constructs a query, sends it to the local server,
273 awaits a response, and makes preliminary checks on the reply.
274 The query requests information of the specified
278 for the specified fully-qualified domain name
280 The reply message is left in the
284 supplied by the caller.
288 return -1 on error or the length of the answer.
294 routines make a query and awaits a response like
298 but in addition, it implements the default and search rules
304 It returns the length of the first successful reply which is stored in
308 The remaining routines are lower-level routines used by
317 constructs a standard query message and places it in
319 It returns the size of the query, or \-1 if the query is
326 but can be any of the query types defined in
327 .Pa <arpa/nameser.h> .
328 The domain name for the query is given by
331 is currently unused but is intended for making update messages.
340 sends a pre-formatted query and returns an answer.
347 is not set, send the query to the local name server, and
348 handle timeouts and retries. Additionally,
350 will use TSIG signatures to add authentication to the query and verify the
351 response. In this case, only one nameserver will be contacted.
352 The length of the reply message is returned, or \-1 if there were errors.
364 return a length that may be bigger than
366 In that case the query should be retried with a bigger buffer.
367 NOTE the answer to the second query may be larger still so supplying
368 a buffer that bigger that the answer returned by the previous
369 query is recommended.
372 MUST be big enough to receive a maximum UDP response from the server or
373 parts of the answer will be silently discarded.
374 The default maximum UDP response size is 512 bytes.
380 is one of the servers in
381 .Fa statp->nsaddr_list
383 .Fa _res.nsaddr_list .
389 print out the query and any answer in
402 prints out the active flag bits in
404 preceeded by the text ";; res options:" on
411 lookup up name in the file referred to by the
412 .Ev HOSTALIASES files return a fully qualified hostname if found or NULL if
413 not found or an error occurred.
417 to store the result in,
419 uses a static buffer.
425 take a list of ns_updrec
427 Identifies the containing zone for each record and groups the records
428 according to containing zone maintaining in zone order then sends and update
429 request to the servers for these zones. The number of zones updated is
430 returned or -1 on error. Note that
432 will perform TSIG authenticated dynamic update operations if the key is not
437 discovers the closest enclosing zone cut for a specified domain name,
438 and finds the IP addresses of the zone's master servers.
444 take a linked list of ns_updrec
446 and construct a UPDATE message in
451 return the length of the constructed message on no error or one of the
452 following error values.
453 .Bl -inset -width "-5"
455 An error occurred parsing
462 The first record was not a zone section or there was a section order problem.
463 The section order is S_ZONE, S_PREREQ and S_UPDATE.
465 A number overflow occurred.
467 Unknown operation or no records.
474 close any open files referenced through
482 compresses the domain name
486 The size of the compressed name is returned or \-1 if there were errors.
487 The size of the array pointed to by
494 to previously-compressed names in the current message.
495 The first pointer points to
496 to the beginning of the message and the list ends with
498 The limit to the array is specified by
502 is to update the list of pointers for labels inserted into the message
503 as the name is compressed. If
507 names are not compressed. If
511 the list of labels is not updated.
516 expands the compressed domain name
518 to a full domain name.
519 The compressed name is contained in a query or reply message;
521 is a pointer to the beginning of the message.
522 The uncompressed name is placed in the buffer indicated by
526 The size of compressed name is returned or \-1 if there was an error.
529 .Ft statp->res_h_errno
532 and external variable
534 is set whenever an error occurs during resolver operation. The following
535 definitions are given in
538 #define NETDB_INTERNAL -1 /* see errno */
539 #define NETDB_SUCCESS 0 /* no problem */
540 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
541 #define TRY_AGAIN 2 /* Non-Authoritative not found, or SERVFAIL */
542 #define NO_RECOVERY 3 /* Non-Recoverable: FORMERR, REFUSED, NOTIMP */
543 #define NO_DATA 4 /* Valid name, no data for requested type */
548 function writes a message to the diagnostic output consisting of the string
551 the constant string ": ", and a message corresponding to the value of
556 function returns a string which is the message text corresponding to the
561 .Bl -tag -width "/etc/resolv.conf "
562 .It Pa /etc/resolv.conf
567 .Xr gethostbyname 3 ,
571 RFC1032, RFC1033, RFC1034, RFC1035, RFC974;
573 .Dq Name Server Operations Guide for Sy BIND