1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\" Modified 1993-07-25 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified 2004-10-31 by aeb
30 .TH RESOLVER 3 2012-04-23 "GNU" "Linux Programmer's Manual"
32 res_init, res_query, res_search, res_querydomain, res_mkquery, res_send,
33 dn_comp, dn_expand \- resolver routines
36 .B #include <netinet/in.h>
37 .B #include <arpa/nameser.h>
38 .B #include <resolv.h>
39 .B extern struct state _res;
41 .B int res_init(void);
43 .BI "int res_query(const char *" dname ", int " class ", int " type ,
45 .BI "unsigned char *" answer ", int " anslen );
48 .BI "int res_search(const char *" dname ", int " class ", int " type ,
50 .BI "unsigned char *" answer ", int " anslen );
53 .BI "int res_querydomain(const char *" name ", const char *" domain ,
55 .BI "int " class ", int " type ", unsigned char *" answer ,
59 .BI "int res_mkquery(int " op ", const char *" dname ", int " class ,
61 .BI "int " type ", char *" data ", int " datalen ", struct rrec *" newrr ,
62 .BI "char *" buf ", int " buflen );
65 .BI "int res_send(const char *" msg ", int " msglen ", char *" answer ,
70 .BI "int dn_comp(unsigned char *" exp_dn ", unsigned char *" comp_dn ,
72 .BI "int " length ", unsigned char **" dnptrs ", unsigned char **" lastdnptr );
75 .BI "int dn_expand(unsigned char *" msg ", unsigned char *" eomorig ,
77 .BI "unsigned char *" comp_dn ", char *" exp_dn ,
82 Link with \fI\-lresolv\fP.
84 These functions make queries to and interpret the responses from Internet
89 function reads the configuration files (see
90 resolv.conf(5)) to get the default domain name, search order and name
92 If no server is given, the local host is tried.
93 If no domain is given, that associated with the local host is used.
94 It can be overridden with the environment variable
97 is normally executed by the first call to one of the
102 function queries the name server for the
103 fully qualified domain name \fIname\fP of specified \fItype\fP and
105 The reply is left in the buffer \fIanswer\fP of length
106 \fIanslen\fP supplied by the caller.
110 function makes a query and waits for the response
113 but in addition implements the default and search
119 \fI_res\fP options below).
122 .BR res_querydomain ()
123 function makes a query using
125 on the concatenation of \fIname\fP and \fIdomain\fP.
127 The following functions are lower-level routines used by
132 function constructs a query message in \fIbuf\fP
133 of length \fIbuflen\fP for the domain name \fIdname\fP.
137 but can be any of the types defined in
138 \fI<arpa/nameser.h>\fP.
139 \fInewrr\fP is currently unused.
143 function sends a preformatted query given in
144 \fImsg\fP of length \fImsglen\fP and returns the answer in \fIanswer\fP
145 which is of length \fIanslen\fP.
149 has not already been called.
153 function compresses the domain name \fIexp_dn\fP
154 and stores it in the buffer \fIcomp_dn\fP of length \fIlength\fP.
155 The compression uses an array of pointers \fIdnptrs\fP to previously
156 compressed names in the current message.
157 The first pointer points
158 to the beginning of the message and the list ends with NULL.
159 The limit of the array is specified by \fIlastdnptr\fP.
160 If \fIdnptr\fP is NULL, domain names are not compressed.
161 If \fIlastdnptr\fP is NULL, the list
162 of labels is not updated.
166 function expands the compressed domain name
167 \fIcomp_dn\fP to a full domain name, which is placed in the buffer
168 \fIexp_dn\fP of size \fIlength\fP.
169 The compressed name is contained
170 in a query or reply message, and \fImsg\fP points to the beginning of
173 The resolver routines use global configuration and state information
174 contained in the structure \fI_res\fP, which is defined in
176 The only field that is normally manipulated by the
177 user is \fI_res.options\fP.
178 This field can contain the bitwise "OR"
179 of the following options:
187 Print debugging messages.
190 Accept authoritative answers only.
193 it finds an authoritative answer or returns an error. [Not currently
197 Use TCP connections for queries rather than UDP datagrams.
200 Query primary domain name server only.
203 Ignore truncation errors.
204 Don't retry with TCP. [Not currently
208 Set the recursion desired bit in queries.
209 Recursion is carried out
210 by the domain name server, not by
212 [Enabled by default].
217 will append the default domain name to
218 single component names, i.e., those that do not contain a dot.
219 [Enabled by default].
224 to keep the TCP connection open between queries.
229 will search for hostnames in the current
230 domain and in parent domains.
231 This option is used by
232 .BR gethostbyname (3).
233 [Enabled by default].
235 This list is not complete. You can find some other flags described in
240 function returns 0 on success, or \-1 if an error
246 .BR res_querydomain (),
250 functions return the length
251 of the response, or \-1 if an error occurs.
257 functions return the length
258 of the compressed name, or \-1 if an error occurs.
261 /etc/resolv.conf resolver configuration file
262 /etc/host.conf resolver configuration file
267 .BR gethostbyname (3),