xref: /freebsd/lib/libc/net/resolver.3 (revision 7f3dea244c40159a41ab22da77a434d7c5b5e85a)
1bc7413d0SPeter Wemm.\" Copyright (c) 1985, 1991, 1993
2bc7413d0SPeter Wemm.\"	The Regents of the University of California.  All rights reserved.
3fdf4c7afSPeter Wemm.\"
4bc7413d0SPeter Wemm.\" Redistribution and use in source and binary forms, with or without
5bc7413d0SPeter Wemm.\" modification, are permitted provided that the following conditions
6bc7413d0SPeter Wemm.\" are met:
7bc7413d0SPeter Wemm.\" 1. Redistributions of source code must retain the above copyright
8bc7413d0SPeter Wemm.\"    notice, this list of conditions and the following disclaimer.
9bc7413d0SPeter Wemm.\" 2. Redistributions in binary form must reproduce the above copyright
10bc7413d0SPeter Wemm.\"    notice, this list of conditions and the following disclaimer in the
11bc7413d0SPeter Wemm.\"    documentation and/or other materials provided with the distribution.
12bc7413d0SPeter Wemm.\" 3. All advertising materials mentioning features or use of this software
13bc7413d0SPeter Wemm.\"    must display the following acknowledgement:
14bc7413d0SPeter Wemm.\"	This product includes software developed by the University of
15bc7413d0SPeter Wemm.\"	California, Berkeley and its contributors.
16bc7413d0SPeter Wemm.\" 4. Neither the name of the University nor the names of its contributors
17bc7413d0SPeter Wemm.\"    may be used to endorse or promote products derived from this software
18bc7413d0SPeter Wemm.\"    without specific prior written permission.
19fdf4c7afSPeter Wemm.\"
20bc7413d0SPeter Wemm.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21bc7413d0SPeter Wemm.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22bc7413d0SPeter Wemm.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23bc7413d0SPeter Wemm.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24bc7413d0SPeter Wemm.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25bc7413d0SPeter Wemm.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26bc7413d0SPeter Wemm.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27bc7413d0SPeter Wemm.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28bc7413d0SPeter Wemm.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29bc7413d0SPeter Wemm.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30bc7413d0SPeter Wemm.\" SUCH DAMAGE.
31fdf4c7afSPeter Wemm.\"
32bc7413d0SPeter Wemm.\"     @(#)resolver.3	8.1 (Berkeley) 6/4/93
337f3dea24SPeter Wemm.\" $FreeBSD$
34bc7413d0SPeter Wemm.\"
35bc7413d0SPeter Wemm.Dd June 4, 1993
36bc7413d0SPeter Wemm.Dt RESOLVER 3
37bc7413d0SPeter Wemm.Os BSD 4.3
38bc7413d0SPeter Wemm.Sh NAME
39bc7413d0SPeter Wemm.Nm res_query ,
40bc7413d0SPeter Wemm.Nm res_search ,
41bc7413d0SPeter Wemm.Nm res_mkquery ,
42bc7413d0SPeter Wemm.Nm res_send ,
43bc7413d0SPeter Wemm.Nm res_init ,
44bc7413d0SPeter Wemm.Nm dn_comp ,
45bc7413d0SPeter Wemm.Nm dn_expand
46bc7413d0SPeter Wemm.Nd resolver routines
47bc7413d0SPeter Wemm.Sh SYNOPSIS
48bc7413d0SPeter Wemm.Fd #include <sys/types.h>
49bc7413d0SPeter Wemm.Fd #include <netinet/in.h>
50bc7413d0SPeter Wemm.Fd #include <arpa/nameser.h>
51bc7413d0SPeter Wemm.Fd #include <resolv.h>
521eda21cbSBruce Evans.Ft int
53bc7413d0SPeter Wemm.Fo res_query
54c293d821SPeter Wemm.Fa "const char *dname"
55bc7413d0SPeter Wemm.Fa "int class"
56bc7413d0SPeter Wemm.Fa "int type"
57bc7413d0SPeter Wemm.Fa "u_char *answer"
58bc7413d0SPeter Wemm.Fa "int anslen"
59bc7413d0SPeter Wemm.Fc
601eda21cbSBruce Evans.Ft int
61bc7413d0SPeter Wemm.Fo res_search
62c293d821SPeter Wemm.Fa "const char *dname"
63bc7413d0SPeter Wemm.Fa "int class"
64bc7413d0SPeter Wemm.Fa "int type"
65bc7413d0SPeter Wemm.Fa "u_char *answer"
66bc7413d0SPeter Wemm.Fa "int anslen"
67bc7413d0SPeter Wemm.Fc
681eda21cbSBruce Evans.Ft int
69bc7413d0SPeter Wemm.Fo res_mkquery
70bc7413d0SPeter Wemm.Fa "int op"
71c293d821SPeter Wemm.Fa "const char *dname"
72bc7413d0SPeter Wemm.Fa "int class"
73bc7413d0SPeter Wemm.Fa "int type"
741eda21cbSBruce Evans.Fa "const u_char *data"
75bc7413d0SPeter Wemm.Fa "int datalen"
761eda21cbSBruce Evans.Fa "const u_char *newrr_in"
771eda21cbSBruce Evans.Fa "u_char *buf"
78bc7413d0SPeter Wemm.Fa "int buflen"
79bc7413d0SPeter Wemm.Fc
801eda21cbSBruce Evans.Ft int
81bc7413d0SPeter Wemm.Fo res_send
8290afb6a5SBruce Evans.Fa "const u_char *msg"
83bc7413d0SPeter Wemm.Fa "int msglen"
8490afb6a5SBruce Evans.Fa "u_char *answer"
85bc7413d0SPeter Wemm.Fa "int anslen"
86bc7413d0SPeter Wemm.Fc
871eda21cbSBruce Evans.Ft int
88bc7413d0SPeter Wemm.Fn res_init
89bc7413d0SPeter Wemm.Fo dn_comp
90c293d821SPeter Wemm.Fa "const char *exp_dn"
9190afb6a5SBruce Evans.Fa "u_char *comp_dn"
92bc7413d0SPeter Wemm.Fa "int length"
9390afb6a5SBruce Evans.Fa "u_char **dnptrs"
9490afb6a5SBruce Evans.Fa "u_char **lastdnptr"
95bc7413d0SPeter Wemm.Fc
961eda21cbSBruce Evans.Ft int
97bc7413d0SPeter Wemm.Fo dn_expand
98c293d821SPeter Wemm.Fa "const u_char *msg"
99c293d821SPeter Wemm.Fa "const u_char *eomorig"
100c293d821SPeter Wemm.Fa "const u_char *comp_dn"
1011eda21cbSBruce Evans.Fa "char *exp_dn"
102bc7413d0SPeter Wemm.Fa "int length"
103bc7413d0SPeter Wemm.Fc
104bc7413d0SPeter Wemm.Sh DESCRIPTION
105fdf4c7afSPeter WemmThese routines are used for making, sending and interpreting
106fdf4c7afSPeter Wemmquery and reply messages with Internet domain name servers.
107bc7413d0SPeter Wemm.Pp
108fdf4c7afSPeter WemmGlobal configuration and state information that is used by the
109fdf4c7afSPeter Wemmresolver routines is kept in the structure
110bc7413d0SPeter Wemm.Em _res .
111fdf4c7afSPeter WemmMost of the values have reasonable defaults and can be ignored.
112fdf4c7afSPeter WemmOptions
113fdf4c7afSPeter Wemmstored in
114bc7413d0SPeter Wemm.Em _res.options
115fdf4c7afSPeter Wemmare defined in
116bc7413d0SPeter Wemm.Pa resolv.h
117fdf4c7afSPeter Wemmand are as follows.
118fdf4c7afSPeter WemmOptions are stored as a simple bit mask containing the bitwise ``or''
119fdf4c7afSPeter Wemmof the options enabled.
120bc7413d0SPeter Wemm.Bl -tag -width RES_DEFNAMES
121bc7413d0SPeter Wemm.It Dv RES_INIT
122fdf4c7afSPeter WemmTrue if the initial name server address and default domain name are
123fdf4c7afSPeter Wemminitialized (i.e.,
124bc7413d0SPeter Wemm.Fn res_init
125fdf4c7afSPeter Wemmhas been called).
126bc7413d0SPeter Wemm.It Dv RES_DEBUG
127fdf4c7afSPeter WemmPrint debugging messages.
128bc7413d0SPeter Wemm.It Dv RES_AAONLY
129fdf4c7afSPeter WemmAccept authoritative answers only.
130fdf4c7afSPeter WemmWith this option,
131bc7413d0SPeter Wemm.Fn res_send
132fdf4c7afSPeter Wemmshould continue until it finds an authoritative answer or finds an error.
133fdf4c7afSPeter WemmCurrently this is not implemented.
134bc7413d0SPeter Wemm.It Dv RES_USEVC
135bc7413d0SPeter WemmUse
136bc7413d0SPeter Wemm.Tn TCP
137bc7413d0SPeter Wemmconnections for queries instead of
138bc7413d0SPeter Wemm.Tn UDP
139bc7413d0SPeter Wemmdatagrams.
140bc7413d0SPeter Wemm.It Dv RES_STAYOPEN
141bc7413d0SPeter WemmUsed with
142bc7413d0SPeter Wemm.Dv RES_USEVC
143bc7413d0SPeter Wemmto keep the
144bc7413d0SPeter Wemm.Tn TCP
145bc7413d0SPeter Wemmconnection open between
146fdf4c7afSPeter Wemmqueries.
147fdf4c7afSPeter WemmThis is useful only in programs that regularly do many queries.
148bc7413d0SPeter Wemm.Tn UDP
149bc7413d0SPeter Wemmshould be the normal mode used.
150bc7413d0SPeter Wemm.It Dv RES_IGNTC
151bc7413d0SPeter WemmUnused currently (ignore truncation errors, i.e., don't retry with
152bc7413d0SPeter Wemm.Tn TCP ) .
153bc7413d0SPeter Wemm.It Dv RES_RECURSE
154fdf4c7afSPeter WemmSet the recursion-desired bit in queries.
155fdf4c7afSPeter WemmThis is the default.
156bc7413d0SPeter Wemm.Pf ( Fn res_send
157fdf4c7afSPeter Wemmdoes not do iterative queries and expects the name server
158fdf4c7afSPeter Wemmto handle recursion.)
159bc7413d0SPeter Wemm.It Dv RES_DEFNAMES
160fdf4c7afSPeter WemmIf set,
161bc7413d0SPeter Wemm.Fn res_search
162fdf4c7afSPeter Wemmwill append the default domain name to single-component names
163fdf4c7afSPeter Wemm(those that do not contain a dot).
164fdf4c7afSPeter WemmThis option is enabled by default.
165bc7413d0SPeter Wemm.It Dv RES_DNSRCH
166fdf4c7afSPeter WemmIf this option is set,
167bc7413d0SPeter Wemm.Fn res_search
168fdf4c7afSPeter Wemmwill search for host names in the current domain and in parent domains; see
169bc7413d0SPeter Wemm.Xr hostname 7 .
170fdf4c7afSPeter WemmThis is used by the standard host lookup routine
171bc7413d0SPeter Wemm.Xr gethostbyname 3 .
172fdf4c7afSPeter WemmThis option is enabled by default.
173c293d821SPeter Wemm.It Dv RES_NOALIASES
174c293d821SPeter WemmThis option turns off the user level aliasing feature controlled by the
175c293d821SPeter Wemm.Dq Ev HOSTALIASES
176c293d821SPeter Wemmenvironment variable.  Network daemons should set this option.
177bc7413d0SPeter Wemm.El
178bc7413d0SPeter Wemm.Pp
179fdf4c7afSPeter WemmThe
180bc7413d0SPeter Wemm.Fn res_init
181fdf4c7afSPeter Wemmroutine
182fdf4c7afSPeter Wemmreads the configuration file (if any; see
183bc7413d0SPeter Wemm.Xr resolver 5 )
184fdf4c7afSPeter Wemmto get the default domain name,
185fdf4c7afSPeter Wemmsearch list and
186fdf4c7afSPeter Wemmthe Internet address of the local name server(s).
187fdf4c7afSPeter WemmIf no server is configured, the host running
188fdf4c7afSPeter Wemmthe resolver is tried.
189fdf4c7afSPeter WemmThe current domain name is defined by the hostname
190fdf4c7afSPeter Wemmif not specified in the configuration file;
191bc7413d0SPeter Wemmit can be overridden by the environment variable
192bc7413d0SPeter Wemm.Ev LOCALDOMAIN .
193c293d821SPeter WemmThis environment variable may contain several blank-separated
194c293d821SPeter Wemmtokens if you wish to override the
195c293d821SPeter Wemm.Em "search list"
196c293d821SPeter Wemmon a per-process basis.  This is similar to the
197c293d821SPeter Wemm.Em search
198c293d821SPeter Wemmcommand in the configuration file.
199c293d821SPeter WemmAnother environment variable (
200c293d821SPeter Wemm.Dq Ev RES_OPTIONS
201c293d821SPeter Wemmcan be set to
202c293d821SPeter Wemmoverride certain internal resolver options which are otherwise
203c293d821SPeter Wemmset by changing fields in the
204c293d821SPeter Wemm.Em _res
205c293d821SPeter Wemmstructure or are inherited from the configuration file's
206c293d821SPeter Wemm.Em options
207c293d821SPeter Wemmcommand.  The syntax of the
208c293d821SPeter Wemm.Dq Ev RES_OPTIONS
209c293d821SPeter Wemmenvironment variable is explained in
210c293d821SPeter Wemm.Xr resolver 5 .
211fdf4c7afSPeter WemmInitialization normally occurs on the first call
212bc7413d0SPeter Wemmto one of the following routines.
213bc7413d0SPeter Wemm.Pp
214fdf4c7afSPeter WemmThe
215bc7413d0SPeter Wemm.Fn res_query
216fdf4c7afSPeter Wemmfunction provides an interface to the server query mechanism.
217fdf4c7afSPeter WemmIt constructs a query, sends it to the local server,
218fdf4c7afSPeter Wemmawaits a response, and makes preliminary checks on the reply.
219fdf4c7afSPeter WemmThe query requests information of the specified
220bc7413d0SPeter Wemm.Fa type
221fdf4c7afSPeter Wemmand
222bc7413d0SPeter Wemm.Fa class
223fdf4c7afSPeter Wemmfor the specified fully-qualified domain name
224bc7413d0SPeter Wemm.Fa dname .
225fdf4c7afSPeter WemmThe reply message is left in the
226bc7413d0SPeter Wemm.Fa answer
227fdf4c7afSPeter Wemmbuffer with length
228bc7413d0SPeter Wemm.Fa anslen
229fdf4c7afSPeter Wemmsupplied by the caller.
230bc7413d0SPeter Wemm.Pp
231fdf4c7afSPeter WemmThe
232bc7413d0SPeter Wemm.Fn res_search
233fdf4c7afSPeter Wemmroutine makes a query and awaits a response like
234bc7413d0SPeter Wemm.Fn res_query ,
235fdf4c7afSPeter Wemmbut in addition, it implements the default and search rules
236bc7413d0SPeter Wemmcontrolled by the
237bc7413d0SPeter Wemm.Dv RES_DEFNAMES
238bc7413d0SPeter Wemmand
239bc7413d0SPeter Wemm.Dv RES_DNSRCH
240bc7413d0SPeter Wemmoptions.
241fdf4c7afSPeter WemmIt returns the first successful reply.
242bc7413d0SPeter Wemm.Pp
243fdf4c7afSPeter WemmThe remaining routines are lower-level routines used by
244bc7413d0SPeter Wemm.Fn res_query .
245fdf4c7afSPeter WemmThe
246bc7413d0SPeter Wemm.Fn res_mkquery
247fdf4c7afSPeter Wemmfunction
248fdf4c7afSPeter Wemmconstructs a standard query message and places it in
249bc7413d0SPeter Wemm.Fa buf .
250fdf4c7afSPeter WemmIt returns the size of the query, or \-1 if the query is
251fdf4c7afSPeter Wemmlarger than
252bc7413d0SPeter Wemm.Fa buflen .
253fdf4c7afSPeter WemmThe query type
254bc7413d0SPeter Wemm.Fa op
255bc7413d0SPeter Wemmis usually
256bc7413d0SPeter Wemm.Dv QUERY ,
257bc7413d0SPeter Wemmbut can be any of the query types defined in
258bc7413d0SPeter Wemm.Aq Pa arpa/nameser.h .
259fdf4c7afSPeter WemmThe domain name for the query is given by
260bc7413d0SPeter Wemm.Fa dname .
261bc7413d0SPeter Wemm.Fa Newrr
262fdf4c7afSPeter Wemmis currently unused but is intended for making update messages.
263bc7413d0SPeter Wemm.Pp
264fdf4c7afSPeter WemmThe
265bc7413d0SPeter Wemm.Fn res_send
266fdf4c7afSPeter Wemmroutine
267fdf4c7afSPeter Wemmsends a pre-formatted query and returns an answer.
268fdf4c7afSPeter WemmIt will call
269bc7413d0SPeter Wemm.Fn res_init
270bc7413d0SPeter Wemmif
271bc7413d0SPeter Wemm.Dv RES_INIT
272bc7413d0SPeter Wemmis not set, send the query to the local name server, and
273fdf4c7afSPeter Wemmhandle timeouts and retries.
274fdf4c7afSPeter WemmThe length of the reply message is returned, or
275fdf4c7afSPeter Wemm\-1 if there were errors.
276bc7413d0SPeter Wemm.Pp
277fdf4c7afSPeter WemmThe
278bc7413d0SPeter Wemm.Fn dn_comp
279fdf4c7afSPeter Wemmfunction
280fdf4c7afSPeter Wemmcompresses the domain name
281bc7413d0SPeter Wemm.Fa exp_dn
282fdf4c7afSPeter Wemmand stores it in
283bc7413d0SPeter Wemm.Fa comp_dn .
284fdf4c7afSPeter WemmThe size of the compressed name is returned or \-1 if there were errors.
285fdf4c7afSPeter WemmThe size of the array pointed to by
286bc7413d0SPeter Wemm.Fa comp_dn
287fdf4c7afSPeter Wemmis given by
288bc7413d0SPeter Wemm.Fa length .
289fdf4c7afSPeter WemmThe compression uses
290fdf4c7afSPeter Wemman array of pointers
291bc7413d0SPeter Wemm.Fa dnptrs
292fdf4c7afSPeter Wemmto previously-compressed names in the current message.
293fdf4c7afSPeter WemmThe first pointer points to
29443d1df33SAlexander Langerthe beginning of the message and the list ends with
295bc7413d0SPeter Wemm.Dv NULL .
296fdf4c7afSPeter WemmThe limit to the array is specified by
297bc7413d0SPeter Wemm.Fa lastdnptr .
298fdf4c7afSPeter WemmA side effect of
299bc7413d0SPeter Wemm.Fn dn_comp
300fdf4c7afSPeter Wemmis to update the list of pointers for
301fdf4c7afSPeter Wemmlabels inserted into the message
302fdf4c7afSPeter Wemmas the name is compressed.
303fdf4c7afSPeter WemmIf
304bc7413d0SPeter Wemm.Em dnptr
305bc7413d0SPeter Wemmis
306bc7413d0SPeter Wemm.Dv NULL, names are not compressed.
307fdf4c7afSPeter WemmIf
308bc7413d0SPeter Wemm.Fa lastdnptr
309bc7413d0SPeter Wemmis
310bc7413d0SPeter Wemm.Dv NULL ,
311bc7413d0SPeter Wemmthe list of labels is not updated.
312bc7413d0SPeter Wemm.Pp
313fdf4c7afSPeter WemmThe
314bc7413d0SPeter Wemm.Fn dn_expand
315fdf4c7afSPeter Wemmentry
316fdf4c7afSPeter Wemmexpands the compressed domain name
317bc7413d0SPeter Wemm.Fa comp_dn
318fdf4c7afSPeter Wemmto a full domain name
319fdf4c7afSPeter WemmThe compressed name is contained in a query or reply message;
320bc7413d0SPeter Wemm.Fa msg
321fdf4c7afSPeter Wemmis a pointer to the beginning of the message.
322fdf4c7afSPeter WemmThe uncompressed name is placed in the buffer indicated by
323bc7413d0SPeter Wemm.Fa exp_dn
324fdf4c7afSPeter Wemmwhich is of size
325bc7413d0SPeter Wemm.Fa length .
326fdf4c7afSPeter WemmThe size of compressed name is returned or \-1 if there was an error.
327bc7413d0SPeter Wemm.Sh FILES
328bc7413d0SPeter Wemm.Bl -tag -width Pa
329bc7413d0SPeter Wemm/etc/resolv.conf
330bc7413d0SPeter WemmThe configuration file
331bc7413d0SPeter Wemmsee
332bc7413d0SPeter Wemm.Xr resolver 5 .
333bc7413d0SPeter Wemm.El
334bc7413d0SPeter Wemm.Sh SEE ALSO
335bc7413d0SPeter Wemm.Xr gethostbyname 3 ,
336bc7413d0SPeter Wemm.Xr resolver 5 ,
337bc7413d0SPeter Wemm.Xr hostname 7 ,
33875141cc9SWolfram Schneider.Xr named 8
339bc7413d0SPeter Wemm.Pp
340bc7413d0SPeter Wemm.%T RFC1032 ,
341bc7413d0SPeter Wemm.%T RFC1033 ,
342bc7413d0SPeter Wemm.%T RFC1034 ,
343bc7413d0SPeter Wemm.%T RFC1035 ,
344bc7413d0SPeter Wemm.%T RFC974
345bc7413d0SPeter Wemm.Rs
346bc7413d0SPeter Wemm.%T "Name Server Operations Guide for BIND"
347bc7413d0SPeter Wemm.Re
348bc7413d0SPeter Wemm.Sh HISTORY
349fdf4c7afSPeter WemmThe
350bc7413d0SPeter Wemm.Nm
351bc7413d0SPeter Wemmfunction appeared in
352bc7413d0SPeter Wemm.Bx 4.3 .
353