]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2 | .\" | |
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. | |
6 | .\" | |
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. | |
c13182ef | 11 | .\" |
fea681da MK |
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 | |
18 | .\" professionally. | |
c13182ef | 19 | .\" |
fea681da MK |
20 | .\" Formatted or processed versions of this manual, if unaccompanied by |
21 | .\" the source, must acknowledge the copyright and authors of this work. | |
22 | .\" | |
23 | .\" References consulted: | |
24 | .\" Linux libc source code | |
25 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
26 | .\" 386BSD man pages | |
27 | .\" Modified 1993-07-25 by Rik Faith (faith@cs.unc.edu) | |
28 | .\" Modified 2004-10-31 by aeb | |
29 | .\" | |
69962544 | 30 | .TH RESOLVER 3 2004-10-31 "GNU" "Linux Programmer's Manual" |
fea681da | 31 | .SH NAME |
c13182ef | 32 | res_init, res_query, res_search, res_querydomain, res_mkquery, res_send, |
fea681da MK |
33 | dn_comp, dn_expand \- resolver routines |
34 | .SH SYNOPSIS | |
35 | .nf | |
36 | .B #include <netinet/in.h> | |
37 | .B #include <arpa/nameser.h> | |
38 | .B #include <resolv.h> | |
39 | .B extern struct state _res; | |
40 | .sp | |
41 | .B int res_init(void); | |
42 | .sp | |
43 | .BI "int res_query(const char *" dname ", int " class ", int " type , | |
44 | .RS | |
45 | .BI "unsigned char *" answer ", int " anslen ); | |
46 | .RE | |
47 | .sp | |
48 | .BI "int res_search(const char *" dname ", int " class ", int " type , | |
49 | .RS | |
50 | .BI "unsigned char *" answer ", int " anslen ); | |
51 | .RE | |
52 | .sp | |
53 | .BI "int res_querydomain(const char *" name ", const char *" domain , | |
54 | .RS | |
55 | .BI "int " class ", int " type ", unsigned char *" answer , | |
56 | .BI "int " anslen ); | |
57 | .RE | |
58 | .sp | |
59 | .BI "int res_mkquery(int " op ", const char *" dname ", int " class , | |
60 | .RS | |
61 | .BI "int " type ", char *" data ", int " datalen ", struct rrec *" newrr , | |
62 | .BI "char *" buf ", int " buflen ); | |
63 | .RE | |
64 | .sp | |
c13182ef | 65 | .BI "int res_send(const char *" msg ", int " msglen ", char *" answer , |
fea681da MK |
66 | .RS |
67 | .BI "int " anslen ); | |
68 | .RE | |
69 | .sp | |
70 | .BI "int dn_comp(unsigned char *" exp_dn ", unsigned char *" comp_dn , | |
71 | .RS | |
72 | .BI "int " length ", unsigned char **" dnptrs ", unsigned char *" exp_dn , | |
73 | .BI "unsigned char **" lastdnptr ); | |
74 | .RE | |
75 | .sp | |
76 | .BI "int dn_expand(unsigned char *" msg ", unsigned char *" eomorig , | |
77 | .RS | |
78 | .BI "unsigned char *" comp_dn ", unsigned char *" exp_dn , | |
79 | .BI "int " length ); | |
80 | .RE | |
81 | .fi | |
82 | .sp | |
e9329f6d | 83 | Link with \fI\-lresolv\fP. |
fea681da MK |
84 | .SH DESCRIPTION |
85 | These functions make queries to and interpret the responses from Internet | |
86 | domain name servers. | |
87 | .PP | |
60a90ecd MK |
88 | The |
89 | .BR res_init () | |
90 | function reads the configuration files (see | |
ac1056b5 | 91 | resolv.conf(5)) to get the default domain name, search order and name |
c13182ef MK |
92 | server address(es). |
93 | If no server is given, the local host is tried. | |
fea681da MK |
94 | If no domain is given, that associated with the local host is used. |
95 | It can be overridden with the environment variable LOCALDOMAIN. | |
60a90ecd MK |
96 | .BR res_init () |
97 | is normally executed by the first call to one of the | |
fea681da MK |
98 | other functions. |
99 | .PP | |
60a90ecd MK |
100 | The |
101 | .BR res_query () | |
102 | function queries the name server for the | |
fea681da | 103 | fully-qualified domain name \fIname\fP of specified \fItype\fP and |
c13182ef MK |
104 | \fIclass\fP. |
105 | The reply is left in the buffer \fIanswer\fP of length | |
fea681da MK |
106 | \fIanslen\fP supplied by the caller. |
107 | .PP | |
60a90ecd MK |
108 | The |
109 | .BR res_search () | |
110 | function makes a query and waits for the response | |
111 | like | |
112 | .BR res_query (), | |
113 | but in addition implements the default and search | |
fea681da MK |
114 | rules controlled by RES_DEFNAMES and RES_DNSRCH (see description of |
115 | \fI_res\fP options below). | |
116 | .PP | |
60a90ecd MK |
117 | The |
118 | .BR res_querydomain () | |
119 | function makes a query using | |
120 | .BR res_query () | |
fea681da MK |
121 | on the concatenation of \fIname\fP and \fIdomain\fP. |
122 | .PP | |
60a90ecd MK |
123 | The following functions are lower-level routines used by |
124 | .BR res_query (). | |
fea681da | 125 | .PP |
60a90ecd MK |
126 | The |
127 | .BR res_mkquery () | |
128 | function constructs a query message in \fIbuf\fP | |
c13182ef MK |
129 | of length \fIbuflen\fP for the domain name \fIdname\fP. |
130 | The query type | |
fea681da | 131 | \fIop\fP is usually QUERY, but can be any of the types defined in |
be7fff26 MK |
132 | \fI<arpa/nameser.h>\fP. |
133 | \fInewrr\fP is currently unused. | |
fea681da | 134 | .PP |
60a90ecd MK |
135 | The |
136 | .BR res_send () | |
137 | function sends a pre-formatted query given in | |
fea681da | 138 | \fImsg\fP of length \fImsglen\fP and returns the answer in \fIanswer\fP |
c13182ef | 139 | which is of length \fIanslen\fP. |
60a90ecd MK |
140 | It will call |
141 | .BR res_init (), | |
142 | if it | |
fea681da MK |
143 | has not already been called. |
144 | .PP | |
60a90ecd MK |
145 | The |
146 | .BR dn_comp () | |
147 | function compresses the domain name \fIexp_dn\fP | |
fea681da MK |
148 | and stores it in the buffer \fIcomp_dn\fP of length \fIlength\fP. |
149 | The compression uses an array of pointers \fIdnptrs\fP to previously | |
c13182ef MK |
150 | compressed names in the current message. |
151 | The first pointer points | |
152 | to the beginning of the message and the list ends with NULL. | |
153 | The limit of the array is specified by \fIlastdnptr\fP. | |
154 | If \fIdnptr\fP is NULL, domain names are not compressed. | |
155 | If \fIlastdnptr\fP is NULL, the list | |
fea681da MK |
156 | of labels is not updated. |
157 | .PP | |
63aa9df0 | 158 | The \fPdn_expand\fP() function expands the compressed domain name |
fea681da | 159 | \fIcomp_dn\fP to a full domain name, which is placed in the buffer |
c13182ef MK |
160 | \fIexp_dn\fP of size \fIlength\fP. |
161 | The compressed name is contained | |
fea681da MK |
162 | in a query or reply message, and \fImsg\fP points to the beginning of |
163 | the message. | |
164 | .PP | |
165 | The resolver routines use global configuration and state information | |
c13182ef MK |
166 | contained in the structure \fI_res\fP, which is defined in |
167 | \fI<resolv.h>\fP. | |
168 | The only field that is normally manipulated by the | |
169 | user is \fI_res.options\fP. | |
170 | This field can contain the bitwise ``or'' | |
fea681da | 171 | of the following options: |
fea681da MK |
172 | .TP |
173 | .B RES_INIT | |
60a90ecd MK |
174 | True if |
175 | .BR res_init () | |
176 | has been called. | |
fea681da MK |
177 | .TP |
178 | .B RES_DEBUG | |
179 | Print debugging messages. | |
180 | .TP | |
181 | .B RES_AAONLY | |
988db661 | 182 | Accept authoritative answers only. |
60a90ecd MK |
183 | .BR res_send () |
184 | continues until | |
fea681da MK |
185 | it fins an authoritative answer or returns an error. [Not currently |
186 | implemented]. | |
187 | .TP | |
188 | .B RES_USEVC | |
189 | Use TCP connections for queries rather than UDP datagrams. | |
190 | .TP | |
191 | .B RES_PRIMARY | |
192 | Query primary domain name server only. | |
193 | .TP | |
194 | .B RES_IGNTC | |
c13182ef MK |
195 | Ignore truncation errors. |
196 | Don't retry with TCP. [Not currently | |
fea681da MK |
197 | implemented]. |
198 | .TP | |
199 | .B RES_RECURSE | |
c13182ef MK |
200 | Set the recursion desired bit in queries. |
201 | Recursion is carried out | |
60a90ecd MK |
202 | by the domain name server, not by |
203 | .BR res_send (). | |
c13182ef | 204 | [Enabled by default]. |
fea681da MK |
205 | .TP |
206 | .B RES_DEFNAMES | |
60a90ecd MK |
207 | If set, |
208 | .BR res_search () | |
209 | will append the default domain name to | |
fea681da MK |
210 | single component names, ie. those that do not contain a dot. |
211 | [Enabled by default]. | |
212 | .TP | |
213 | .B RES_STAYOPEN | |
214 | Used with RES_USEVC to keep the TCP connection open between queries. | |
215 | .TP | |
216 | .B RES_DNSRCH | |
60a90ecd MK |
217 | If set, |
218 | .BR res_search () | |
219 | will search for host names in the current | |
c13182ef MK |
220 | domain and in parent domains. |
221 | This option is used by | |
fea681da MK |
222 | .BR gethostbyname (3). |
223 | [Enabled by default]. | |
224 | .SH "RETURN VALUE" | |
60a90ecd MK |
225 | The |
226 | .BR res_init () | |
227 | function returns 0 on success, or \-1 if an error | |
fea681da MK |
228 | occurs. |
229 | .PP | |
60a90ecd MK |
230 | The |
231 | .BR res_query (), | |
232 | .BR res_search (), | |
233 | .BR res_querydomain (), | |
234 | .BR res_mkquery () | |
235 | and | |
236 | .BR res_send () | |
237 | functions return the length | |
fea681da MK |
238 | of the response, or \-1 if an error occurs. |
239 | .PP | |
60a90ecd MK |
240 | The |
241 | .BR dn_comp () | |
242 | and | |
243 | .BR dn_expand () | |
244 | functions return the length | |
fea681da MK |
245 | of the compressed name, or \-1 if an error occurs. |
246 | .SH FILES | |
247 | .nf | |
248 | /etc/resolv.conf resolver configuration file | |
249 | /etc/host.conf resolver configuration file | |
250 | .fi | |
251 | .SH "CONFORMING TO" | |
b14d4aa5 | 252 | 4.3BSD |
fea681da MK |
253 | .SH "SEE ALSO" |
254 | .BR gethostbyname (3), | |
aca92158 | 255 | .BR resolver (5), |
fea681da | 256 | .BR hostname (7), |
b95582c7 MK |
257 | .BR resolv.conf (5), |
258 | .BR named (8) |