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