diff options
Diffstat (limited to 'src/lib/libc/net/resolver.3')
-rw-r--r-- | src/lib/libc/net/resolver.3 | 341 |
1 files changed, 341 insertions, 0 deletions
diff --git a/src/lib/libc/net/resolver.3 b/src/lib/libc/net/resolver.3 new file mode 100644 index 0000000000..577420e9f1 --- /dev/null +++ b/src/lib/libc/net/resolver.3 | |||
@@ -0,0 +1,341 @@ | |||
1 | .\" $OpenBSD: resolver.3,v 1.17 2003/08/08 09:26:02 jmc Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1985, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
5 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 3. Neither the name of the University nor the names of its contributors | ||
15 | .\" may be used to endorse or promote products derived from this software | ||
16 | .\" without specific prior written permission. | ||
17 | .\" | ||
18 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
28 | .\" SUCH DAMAGE. | ||
29 | .\" | ||
30 | .Dd June 4, 1993 | ||
31 | .Dt RESOLVER 3 | ||
32 | .Os | ||
33 | .Sh NAME | ||
34 | .Nm res_query , | ||
35 | .Nm res_search , | ||
36 | .Nm res_mkquery , | ||
37 | .Nm res_send , | ||
38 | .Nm res_init , | ||
39 | .Nm dn_comp , | ||
40 | .Nm dn_expand | ||
41 | .Nd resolver routines | ||
42 | .Sh SYNOPSIS | ||
43 | .Fd #include <sys/types.h> | ||
44 | .Fd #include <netinet/in.h> | ||
45 | .Fd #include <arpa/nameser.h> | ||
46 | .Fd #include <resolv.h> | ||
47 | .Ft int | ||
48 | .Fo res_query | ||
49 | .Fa "char *dname" | ||
50 | .Fa "int class" | ||
51 | .Fa "int type" | ||
52 | .Fa "u_char *answer" | ||
53 | .Fa "int anslen" | ||
54 | .Fc | ||
55 | .Ft int | ||
56 | .Fo res_search | ||
57 | .Fa "char *dname" | ||
58 | .Fa "int class" | ||
59 | .Fa "int type" | ||
60 | .Fa "u_char *answer" | ||
61 | .Fa "int anslen" | ||
62 | .Fc | ||
63 | .Ft int | ||
64 | .Fo res_mkquery | ||
65 | .Fa "int op" | ||
66 | .Fa "char *dname" | ||
67 | .Fa "int class" | ||
68 | .Fa "int type" | ||
69 | .Fa "char *data" | ||
70 | .Fa "int datalen" | ||
71 | .Fa "struct rrec *newrr" | ||
72 | .Fa "char *buf" | ||
73 | .Fa "int buflen" | ||
74 | .Fc | ||
75 | .Ft int | ||
76 | .Fo res_send | ||
77 | .Fa "char *msg" | ||
78 | .Fa "int msglen" | ||
79 | .Fa "char *answer" | ||
80 | .Fa "int anslen" | ||
81 | .Fc | ||
82 | .Ft int | ||
83 | .Fn res_init "void" | ||
84 | .Ft int | ||
85 | .Fo dn_comp | ||
86 | .Fa "char *exp_dn" | ||
87 | .Fa "char *comp_dn" | ||
88 | .Fa "int length" | ||
89 | .Fa "char **dnptrs" | ||
90 | .Fa "char **lastdnptr" | ||
91 | .Fc | ||
92 | .Ft int | ||
93 | .Fo dn_expand | ||
94 | .Fa "u_char *msg" | ||
95 | .Fa "u_char *eomorig" | ||
96 | .Fa "u_char *comp_dn" | ||
97 | .Fa "u_char *exp_dn" | ||
98 | .Fa "int length" | ||
99 | .Fc | ||
100 | .Sh DESCRIPTION | ||
101 | These routines are used for making, sending, and interpreting | ||
102 | query and reply messages with Internet domain name servers. | ||
103 | .Pp | ||
104 | Global configuration and state information that is used by the | ||
105 | resolver routines is kept in the structure | ||
106 | .Li _res . | ||
107 | Most of the values have reasonable defaults and can be ignored. | ||
108 | Options stored in | ||
109 | .Li _res.options | ||
110 | are defined in | ||
111 | .Aq Pa resolv.h | ||
112 | and are as follows. | ||
113 | Options are stored as a simple bit mask containing the bitwise | ||
114 | .Tn OR | ||
115 | of the options enabled. | ||
116 | .Bl -tag -width RES_USE_INET6 | ||
117 | .It Dv RES_INIT | ||
118 | True if the initial name server address and default domain name are | ||
119 | initialized (i.e., | ||
120 | .Fn res_init | ||
121 | has been called). | ||
122 | .It Dv RES_DEBUG | ||
123 | Print debugging messages. | ||
124 | .It Dv RES_AAONLY | ||
125 | Accept authoritative answers only. | ||
126 | With this option, | ||
127 | .Fn res_send | ||
128 | should continue until it finds an authoritative answer or finds an error. | ||
129 | Currently this is not implemented. | ||
130 | .It Dv RES_USEVC | ||
131 | Use | ||
132 | .Tn TCP | ||
133 | connections for queries instead of | ||
134 | .Tn UDP | ||
135 | datagrams. | ||
136 | .It Dv RES_STAYOPEN | ||
137 | Used with | ||
138 | .Dv RES_USEVC | ||
139 | to keep the | ||
140 | .Tn TCP | ||
141 | connection open between queries. | ||
142 | This is useful only in programs that regularly do many queries. | ||
143 | .Tn UDP | ||
144 | should be the normal mode used. | ||
145 | .It Dv RES_IGNTC | ||
146 | Unused currently (ignore truncation errors, i.e., don't retry with | ||
147 | .Tn TCP ) . | ||
148 | .It Dv RES_RECURSE | ||
149 | Set the recursion-desired bit in queries. | ||
150 | This is the default. | ||
151 | .Pf ( Fn res_send | ||
152 | does not do iterative queries and expects the name server | ||
153 | to handle recursion.) | ||
154 | .It Dv RES_DEFNAMES | ||
155 | If set, | ||
156 | .Fn res_search | ||
157 | will append the default domain name to single-component names | ||
158 | (those that do not contain a dot). | ||
159 | This option is enabled by default. | ||
160 | .It Dv RES_DNSRCH | ||
161 | If this option is set, | ||
162 | .Fn res_search | ||
163 | will search for host names in the current domain and in parent domains; see | ||
164 | .Xr hostname 7 . | ||
165 | This is used by the standard host lookup routine | ||
166 | .Xr gethostbyname 3 . | ||
167 | This option is enabled by default. | ||
168 | .It Dv RES_USE_INET6 | ||
169 | Enables support for IPv6-only applications. | ||
170 | This causes IPv4 addresses to be returned as an IPv4 mapped address. | ||
171 | For example, 10.1.1.1 will be returned as ::ffff:10.1.1.1. | ||
172 | The option is not meaningful on | ||
173 | .Ox . | ||
174 | .El | ||
175 | .Pp | ||
176 | The | ||
177 | .Fn res_init | ||
178 | routine reads the configuration file (if any; see | ||
179 | .Xr resolv.conf 5 ) | ||
180 | to get the default domain name, search list, and the Internet address | ||
181 | of the local name server(s). | ||
182 | If no server is configured, the host running | ||
183 | the resolver is tried. | ||
184 | The current domain name is defined by the hostname | ||
185 | if not specified in the configuration file; | ||
186 | it can be overridden by the environment variable | ||
187 | .Ev LOCALDOMAIN . | ||
188 | This environment variable may contain several blank-separated | ||
189 | tokens if you wish to override the | ||
190 | .Fa search list | ||
191 | on a per-process basis. | ||
192 | This is similar to the | ||
193 | .Fa search | ||
194 | command in the configuration file. | ||
195 | Another environment variable | ||
196 | .Ev RES_OPTIONS | ||
197 | can be set to override certain internal resolver options which | ||
198 | are otherwise set by changing fields in the | ||
199 | .Fa _res | ||
200 | structure or are inherited from the configuration file's | ||
201 | .Fa options | ||
202 | command. | ||
203 | The syntax of the | ||
204 | .Ev RES_OPTIONS | ||
205 | environment variable is explained in | ||
206 | .Xr resolv.conf 5 . | ||
207 | Initialization normally occurs on the first call | ||
208 | to one of the following routines. | ||
209 | .Pp | ||
210 | The | ||
211 | .Fn res_query | ||
212 | function provides an interface to the server query mechanism. | ||
213 | It constructs a query, sends it to the local server, | ||
214 | awaits a response, and makes preliminary checks on the reply. | ||
215 | The query requests information of the specified | ||
216 | .Fa type | ||
217 | and | ||
218 | .Fa class | ||
219 | for the specified fully qualified domain name | ||
220 | .Fa dname . | ||
221 | The reply message is left in the | ||
222 | .Fa answer | ||
223 | buffer with length | ||
224 | .Fa anslen | ||
225 | supplied by the caller. | ||
226 | .Pp | ||
227 | The | ||
228 | .Fn res_search | ||
229 | routine makes a query and awaits a response like | ||
230 | .Fn res_query , | ||
231 | but in addition, it implements the default and search rules controlled by the | ||
232 | .Dv RES_DEFNAMES | ||
233 | and | ||
234 | .Dv RES_DNSRCH | ||
235 | options. | ||
236 | It returns the first successful reply. | ||
237 | .Pp | ||
238 | The remaining routines are lower-level routines used by | ||
239 | .Fn res_query . | ||
240 | The | ||
241 | .Fn res_mkquery | ||
242 | function constructs a standard query message and places it in | ||
243 | .Fa buf . | ||
244 | It returns the size of the query, or \-1 if the query is larger than | ||
245 | .Fa buflen . | ||
246 | The query type | ||
247 | .Fa op | ||
248 | is usually | ||
249 | .Dv QUERY , | ||
250 | but can be any of the query types defined in | ||
251 | .Aq Pa arpa/nameser.h . | ||
252 | The domain name for the query is given by | ||
253 | .Fa dname . | ||
254 | .Fa newrr | ||
255 | is currently unused but is intended for making update messages. | ||
256 | .Pp | ||
257 | The | ||
258 | .Fn res_send | ||
259 | routine sends a pre-formatted query and returns an answer. | ||
260 | It will call | ||
261 | .Fn res_init | ||
262 | if | ||
263 | .Dv RES_INIT | ||
264 | is not set, send the query to the local name server, and | ||
265 | handle timeouts and retries. | ||
266 | The length of the reply message is returned, or \-1 if there were errors. | ||
267 | .Pp | ||
268 | The | ||
269 | .Fn dn_comp | ||
270 | function compresses the domain name | ||
271 | .Fa exp_dn | ||
272 | and stores it in | ||
273 | .Fa comp_dn . | ||
274 | The size of the compressed name is returned or \-1 if there were errors. | ||
275 | The size of the array pointed to by | ||
276 | .Fa comp_dn | ||
277 | is given by | ||
278 | .Fa length . | ||
279 | The compression uses an array of pointers | ||
280 | .Fa dnptrs | ||
281 | to previously compressed names in the current message. | ||
282 | The first pointer points | ||
283 | to the beginning of the message and the list ends with | ||
284 | .Dv NULL . | ||
285 | The limit to the array is specified by | ||
286 | .Fa lastdnptr . | ||
287 | A side effect of | ||
288 | .Fn dn_comp | ||
289 | is to update the list of pointers for labels inserted into the message | ||
290 | as the name is compressed. | ||
291 | If | ||
292 | .Em dnptr | ||
293 | is | ||
294 | .Dv NULL , | ||
295 | names are not compressed. | ||
296 | If | ||
297 | .Fa lastdnptr | ||
298 | is | ||
299 | .Dv NULL , | ||
300 | the list of labels is not updated. | ||
301 | .Pp | ||
302 | The | ||
303 | .Fn dn_expand | ||
304 | entry expands the compressed domain name | ||
305 | .Fa comp_dn | ||
306 | to a full domain name | ||
307 | The compressed name is contained in a query or reply message; | ||
308 | .Fa msg | ||
309 | is a pointer to the beginning of the message. | ||
310 | The uncompressed name is placed in the buffer indicated by | ||
311 | .Fa exp_dn | ||
312 | which is of size | ||
313 | .Fa length . | ||
314 | The size of compressed name is returned or \-1 if there was an error. | ||
315 | .Sh FILES | ||
316 | .Bl -tag -width Pa | ||
317 | /etc/resolv.conf | ||
318 | configuration file | ||
319 | see | ||
320 | .Xr resolv.conf 5 . | ||
321 | .El | ||
322 | .Sh SEE ALSO | ||
323 | .Xr gethostbyname 3 , | ||
324 | .Xr resolv.conf 5 , | ||
325 | .Xr hostname 7 , | ||
326 | .Xr named 8 | ||
327 | .Pp | ||
328 | .%T RFC 1032 , | ||
329 | .%T RFC 1033 , | ||
330 | .%T RFC 1034 , | ||
331 | .%T RFC 1035 , | ||
332 | .%T RFC 1535 , | ||
333 | .%T RFC 974 | ||
334 | .Rs | ||
335 | .%T "Name Server Operations Guide for BIND" | ||
336 | .Re | ||
337 | .Sh HISTORY | ||
338 | The | ||
339 | .Nm | ||
340 | function appeared in | ||
341 | .Bx 4.3 . | ||