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 4725bb73e0SAlexey Zelkin.Sh LIBRARY 4825bb73e0SAlexey Zelkin.Lb libc 49bc7413d0SPeter Wemm.Sh SYNOPSIS 50bc7413d0SPeter Wemm.Fd #include <sys/types.h> 51bc7413d0SPeter Wemm.Fd #include <netinet/in.h> 52bc7413d0SPeter Wemm.Fd #include <arpa/nameser.h> 53bc7413d0SPeter Wemm.Fd #include <resolv.h> 541eda21cbSBruce Evans.Ft int 55bc7413d0SPeter Wemm.Fo res_query 56c293d821SPeter Wemm.Fa "const char *dname" 57bc7413d0SPeter Wemm.Fa "int class" 58bc7413d0SPeter Wemm.Fa "int type" 59bc7413d0SPeter Wemm.Fa "u_char *answer" 60bc7413d0SPeter Wemm.Fa "int anslen" 61bc7413d0SPeter Wemm.Fc 621eda21cbSBruce Evans.Ft int 63bc7413d0SPeter Wemm.Fo res_search 64c293d821SPeter Wemm.Fa "const char *dname" 65bc7413d0SPeter Wemm.Fa "int class" 66bc7413d0SPeter Wemm.Fa "int type" 67bc7413d0SPeter Wemm.Fa "u_char *answer" 68bc7413d0SPeter Wemm.Fa "int anslen" 69bc7413d0SPeter Wemm.Fc 701eda21cbSBruce Evans.Ft int 71bc7413d0SPeter Wemm.Fo res_mkquery 72bc7413d0SPeter Wemm.Fa "int op" 73c293d821SPeter Wemm.Fa "const char *dname" 74bc7413d0SPeter Wemm.Fa "int class" 75bc7413d0SPeter Wemm.Fa "int type" 761eda21cbSBruce Evans.Fa "const u_char *data" 77bc7413d0SPeter Wemm.Fa "int datalen" 781eda21cbSBruce Evans.Fa "const u_char *newrr_in" 791eda21cbSBruce Evans.Fa "u_char *buf" 80bc7413d0SPeter Wemm.Fa "int buflen" 81bc7413d0SPeter Wemm.Fc 821eda21cbSBruce Evans.Ft int 83bc7413d0SPeter Wemm.Fo res_send 8490afb6a5SBruce Evans.Fa "const u_char *msg" 85bc7413d0SPeter Wemm.Fa "int msglen" 8690afb6a5SBruce Evans.Fa "u_char *answer" 87bc7413d0SPeter Wemm.Fa "int anslen" 88bc7413d0SPeter Wemm.Fc 891eda21cbSBruce Evans.Ft int 90bc7413d0SPeter Wemm.Fn res_init 91bc7413d0SPeter Wemm.Fo dn_comp 92c293d821SPeter Wemm.Fa "const char *exp_dn" 9390afb6a5SBruce Evans.Fa "u_char *comp_dn" 94bc7413d0SPeter Wemm.Fa "int length" 9590afb6a5SBruce Evans.Fa "u_char **dnptrs" 9690afb6a5SBruce Evans.Fa "u_char **lastdnptr" 97bc7413d0SPeter Wemm.Fc 981eda21cbSBruce Evans.Ft int 99bc7413d0SPeter Wemm.Fo dn_expand 100c293d821SPeter Wemm.Fa "const u_char *msg" 101c293d821SPeter Wemm.Fa "const u_char *eomorig" 102c293d821SPeter Wemm.Fa "const u_char *comp_dn" 1031eda21cbSBruce Evans.Fa "char *exp_dn" 104bc7413d0SPeter Wemm.Fa "int length" 105bc7413d0SPeter Wemm.Fc 106bc7413d0SPeter Wemm.Sh DESCRIPTION 107fdf4c7afSPeter WemmThese routines are used for making, sending and interpreting 108fdf4c7afSPeter Wemmquery and reply messages with Internet domain name servers. 109bc7413d0SPeter Wemm.Pp 110fdf4c7afSPeter WemmGlobal configuration and state information that is used by the 111fdf4c7afSPeter Wemmresolver routines is kept in the structure 112bc7413d0SPeter Wemm.Em _res . 113fdf4c7afSPeter WemmMost of the values have reasonable defaults and can be ignored. 114fdf4c7afSPeter WemmOptions 115fdf4c7afSPeter Wemmstored in 116bc7413d0SPeter Wemm.Em _res.options 117fdf4c7afSPeter Wemmare defined in 118bc7413d0SPeter Wemm.Pa resolv.h 119fdf4c7afSPeter Wemmand are as follows. 120fdf4c7afSPeter WemmOptions are stored as a simple bit mask containing the bitwise ``or'' 121fdf4c7afSPeter Wemmof the options enabled. 122bc7413d0SPeter Wemm.Bl -tag -width RES_DEFNAMES 123bc7413d0SPeter Wemm.It Dv RES_INIT 124fdf4c7afSPeter WemmTrue if the initial name server address and default domain name are 125fdf4c7afSPeter Wemminitialized (i.e., 126bc7413d0SPeter Wemm.Fn res_init 127fdf4c7afSPeter Wemmhas been called). 128bc7413d0SPeter Wemm.It Dv RES_DEBUG 129fdf4c7afSPeter WemmPrint debugging messages. 130bc7413d0SPeter Wemm.It Dv RES_AAONLY 131fdf4c7afSPeter WemmAccept authoritative answers only. 132fdf4c7afSPeter WemmWith this option, 133bc7413d0SPeter Wemm.Fn res_send 134fdf4c7afSPeter Wemmshould continue until it finds an authoritative answer or finds an error. 135fdf4c7afSPeter WemmCurrently this is not implemented. 136bc7413d0SPeter Wemm.It Dv RES_USEVC 137bc7413d0SPeter WemmUse 138bc7413d0SPeter Wemm.Tn TCP 139bc7413d0SPeter Wemmconnections for queries instead of 140bc7413d0SPeter Wemm.Tn UDP 141bc7413d0SPeter Wemmdatagrams. 142bc7413d0SPeter Wemm.It Dv RES_STAYOPEN 143bc7413d0SPeter WemmUsed with 144bc7413d0SPeter Wemm.Dv RES_USEVC 145bc7413d0SPeter Wemmto keep the 146bc7413d0SPeter Wemm.Tn TCP 147bc7413d0SPeter Wemmconnection open between 148fdf4c7afSPeter Wemmqueries. 149fdf4c7afSPeter WemmThis is useful only in programs that regularly do many queries. 150bc7413d0SPeter Wemm.Tn UDP 151bc7413d0SPeter Wemmshould be the normal mode used. 152bc7413d0SPeter Wemm.It Dv RES_IGNTC 153bc7413d0SPeter WemmUnused currently (ignore truncation errors, i.e., don't retry with 154bc7413d0SPeter Wemm.Tn TCP ) . 155bc7413d0SPeter Wemm.It Dv RES_RECURSE 156fdf4c7afSPeter WemmSet the recursion-desired bit in queries. 157fdf4c7afSPeter WemmThis is the default. 158bc7413d0SPeter Wemm.Pf ( Fn res_send 159fdf4c7afSPeter Wemmdoes not do iterative queries and expects the name server 160fdf4c7afSPeter Wemmto handle recursion.) 161bc7413d0SPeter Wemm.It Dv RES_DEFNAMES 162fdf4c7afSPeter WemmIf set, 163bc7413d0SPeter Wemm.Fn res_search 164fdf4c7afSPeter Wemmwill append the default domain name to single-component names 165fdf4c7afSPeter Wemm(those that do not contain a dot). 166fdf4c7afSPeter WemmThis option is enabled by default. 167bc7413d0SPeter Wemm.It Dv RES_DNSRCH 168fdf4c7afSPeter WemmIf this option is set, 169bc7413d0SPeter Wemm.Fn res_search 170fdf4c7afSPeter Wemmwill search for host names in the current domain and in parent domains; see 171bc7413d0SPeter Wemm.Xr hostname 7 . 172fdf4c7afSPeter WemmThis is used by the standard host lookup routine 173bc7413d0SPeter Wemm.Xr gethostbyname 3 . 174fdf4c7afSPeter WemmThis option is enabled by default. 175c293d821SPeter Wemm.It Dv RES_NOALIASES 176c293d821SPeter WemmThis option turns off the user level aliasing feature controlled by the 177c293d821SPeter Wemm.Dq Ev HOSTALIASES 178c293d821SPeter Wemmenvironment variable. Network daemons should set this option. 179bc7413d0SPeter Wemm.El 180bc7413d0SPeter Wemm.Pp 181fdf4c7afSPeter WemmThe 182bc7413d0SPeter Wemm.Fn res_init 183fdf4c7afSPeter Wemmroutine 184fdf4c7afSPeter Wemmreads the configuration file (if any; see 185bc7413d0SPeter Wemm.Xr resolver 5 ) 186fdf4c7afSPeter Wemmto get the default domain name, 187fdf4c7afSPeter Wemmsearch list and 188fdf4c7afSPeter Wemmthe Internet address of the local name server(s). 189fdf4c7afSPeter WemmIf no server is configured, the host running 190fdf4c7afSPeter Wemmthe resolver is tried. 191fdf4c7afSPeter WemmThe current domain name is defined by the hostname 192fdf4c7afSPeter Wemmif not specified in the configuration file; 193bc7413d0SPeter Wemmit can be overridden by the environment variable 194bc7413d0SPeter Wemm.Ev LOCALDOMAIN . 195c293d821SPeter WemmThis environment variable may contain several blank-separated 196c293d821SPeter Wemmtokens if you wish to override the 197c293d821SPeter Wemm.Em "search list" 198c293d821SPeter Wemmon a per-process basis. This is similar to the 199c293d821SPeter Wemm.Em search 200c293d821SPeter Wemmcommand in the configuration file. 201c293d821SPeter WemmAnother environment variable ( 202c293d821SPeter Wemm.Dq Ev RES_OPTIONS 203c293d821SPeter Wemmcan be set to 204c293d821SPeter Wemmoverride certain internal resolver options which are otherwise 205c293d821SPeter Wemmset by changing fields in the 206c293d821SPeter Wemm.Em _res 207c293d821SPeter Wemmstructure or are inherited from the configuration file's 208c293d821SPeter Wemm.Em options 209c293d821SPeter Wemmcommand. The syntax of the 210c293d821SPeter Wemm.Dq Ev RES_OPTIONS 211c293d821SPeter Wemmenvironment variable is explained in 212c293d821SPeter Wemm.Xr resolver 5 . 213fdf4c7afSPeter WemmInitialization normally occurs on the first call 214bc7413d0SPeter Wemmto one of the following routines. 215bc7413d0SPeter Wemm.Pp 216fdf4c7afSPeter WemmThe 217bc7413d0SPeter Wemm.Fn res_query 218fdf4c7afSPeter Wemmfunction provides an interface to the server query mechanism. 219fdf4c7afSPeter WemmIt constructs a query, sends it to the local server, 220fdf4c7afSPeter Wemmawaits a response, and makes preliminary checks on the reply. 221fdf4c7afSPeter WemmThe query requests information of the specified 222bc7413d0SPeter Wemm.Fa type 223fdf4c7afSPeter Wemmand 224bc7413d0SPeter Wemm.Fa class 225fdf4c7afSPeter Wemmfor the specified fully-qualified domain name 226bc7413d0SPeter Wemm.Fa dname . 227fdf4c7afSPeter WemmThe reply message is left in the 228bc7413d0SPeter Wemm.Fa answer 229fdf4c7afSPeter Wemmbuffer with length 230bc7413d0SPeter Wemm.Fa anslen 231fdf4c7afSPeter Wemmsupplied by the caller. 232bc7413d0SPeter Wemm.Pp 233fdf4c7afSPeter WemmThe 234bc7413d0SPeter Wemm.Fn res_search 235fdf4c7afSPeter Wemmroutine makes a query and awaits a response like 236bc7413d0SPeter Wemm.Fn res_query , 237fdf4c7afSPeter Wemmbut in addition, it implements the default and search rules 238bc7413d0SPeter Wemmcontrolled by the 239bc7413d0SPeter Wemm.Dv RES_DEFNAMES 240bc7413d0SPeter Wemmand 241bc7413d0SPeter Wemm.Dv RES_DNSRCH 242bc7413d0SPeter Wemmoptions. 243fdf4c7afSPeter WemmIt returns the first successful reply. 244bc7413d0SPeter Wemm.Pp 245fdf4c7afSPeter WemmThe remaining routines are lower-level routines used by 246bc7413d0SPeter Wemm.Fn res_query . 247fdf4c7afSPeter WemmThe 248bc7413d0SPeter Wemm.Fn res_mkquery 249fdf4c7afSPeter Wemmfunction 250fdf4c7afSPeter Wemmconstructs a standard query message and places it in 251bc7413d0SPeter Wemm.Fa buf . 252fdf4c7afSPeter WemmIt returns the size of the query, or \-1 if the query is 253fdf4c7afSPeter Wemmlarger than 254bc7413d0SPeter Wemm.Fa buflen . 255fdf4c7afSPeter WemmThe query type 256bc7413d0SPeter Wemm.Fa op 257bc7413d0SPeter Wemmis usually 258bc7413d0SPeter Wemm.Dv QUERY , 259bc7413d0SPeter Wemmbut can be any of the query types defined in 260bc7413d0SPeter Wemm.Aq Pa arpa/nameser.h . 261fdf4c7afSPeter WemmThe domain name for the query is given by 262bc7413d0SPeter Wemm.Fa dname . 263bc7413d0SPeter Wemm.Fa Newrr 264fdf4c7afSPeter Wemmis currently unused but is intended for making update messages. 265bc7413d0SPeter Wemm.Pp 266fdf4c7afSPeter WemmThe 267bc7413d0SPeter Wemm.Fn res_send 268fdf4c7afSPeter Wemmroutine 269fdf4c7afSPeter Wemmsends a pre-formatted query and returns an answer. 270fdf4c7afSPeter WemmIt will call 271bc7413d0SPeter Wemm.Fn res_init 272bc7413d0SPeter Wemmif 273bc7413d0SPeter Wemm.Dv RES_INIT 274bc7413d0SPeter Wemmis not set, send the query to the local name server, and 275fdf4c7afSPeter Wemmhandle timeouts and retries. 276fdf4c7afSPeter WemmThe length of the reply message is returned, or 277fdf4c7afSPeter Wemm\-1 if there were errors. 278bc7413d0SPeter Wemm.Pp 279fdf4c7afSPeter WemmThe 280bc7413d0SPeter Wemm.Fn dn_comp 281fdf4c7afSPeter Wemmfunction 282fdf4c7afSPeter Wemmcompresses the domain name 283bc7413d0SPeter Wemm.Fa exp_dn 284fdf4c7afSPeter Wemmand stores it in 285bc7413d0SPeter Wemm.Fa comp_dn . 286fdf4c7afSPeter WemmThe size of the compressed name is returned or \-1 if there were errors. 287fdf4c7afSPeter WemmThe size of the array pointed to by 288bc7413d0SPeter Wemm.Fa comp_dn 289fdf4c7afSPeter Wemmis given by 290bc7413d0SPeter Wemm.Fa length . 291fdf4c7afSPeter WemmThe compression uses 292fdf4c7afSPeter Wemman array of pointers 293bc7413d0SPeter Wemm.Fa dnptrs 294fdf4c7afSPeter Wemmto previously-compressed names in the current message. 295fdf4c7afSPeter WemmThe first pointer points to 29643d1df33SAlexander Langerthe beginning of the message and the list ends with 297bc7413d0SPeter Wemm.Dv NULL . 298fdf4c7afSPeter WemmThe limit to the array is specified by 299bc7413d0SPeter Wemm.Fa lastdnptr . 300fdf4c7afSPeter WemmA side effect of 301bc7413d0SPeter Wemm.Fn dn_comp 302fdf4c7afSPeter Wemmis to update the list of pointers for 303fdf4c7afSPeter Wemmlabels inserted into the message 304fdf4c7afSPeter Wemmas the name is compressed. 305fdf4c7afSPeter WemmIf 306bc7413d0SPeter Wemm.Em dnptr 307bc7413d0SPeter Wemmis 308bc7413d0SPeter Wemm.Dv NULL, names are not compressed. 309fdf4c7afSPeter WemmIf 310bc7413d0SPeter Wemm.Fa lastdnptr 311bc7413d0SPeter Wemmis 312bc7413d0SPeter Wemm.Dv NULL , 313bc7413d0SPeter Wemmthe list of labels is not updated. 314bc7413d0SPeter Wemm.Pp 315fdf4c7afSPeter WemmThe 316bc7413d0SPeter Wemm.Fn dn_expand 317fdf4c7afSPeter Wemmentry 318fdf4c7afSPeter Wemmexpands the compressed domain name 319bc7413d0SPeter Wemm.Fa comp_dn 320fdf4c7afSPeter Wemmto a full domain name 321fdf4c7afSPeter WemmThe compressed name is contained in a query or reply message; 322bc7413d0SPeter Wemm.Fa msg 323fdf4c7afSPeter Wemmis a pointer to the beginning of the message. 324fdf4c7afSPeter WemmThe uncompressed name is placed in the buffer indicated by 325bc7413d0SPeter Wemm.Fa exp_dn 326fdf4c7afSPeter Wemmwhich is of size 327bc7413d0SPeter Wemm.Fa length . 328fdf4c7afSPeter WemmThe size of compressed name is returned or \-1 if there was an error. 329bc7413d0SPeter Wemm.Sh FILES 330bc7413d0SPeter Wemm.Bl -tag -width Pa 331bc7413d0SPeter Wemm/etc/resolv.conf 332bc7413d0SPeter WemmThe configuration file 333bc7413d0SPeter Wemmsee 334bc7413d0SPeter Wemm.Xr resolver 5 . 335bc7413d0SPeter Wemm.El 336bc7413d0SPeter Wemm.Sh SEE ALSO 337bc7413d0SPeter Wemm.Xr gethostbyname 3 , 338bc7413d0SPeter Wemm.Xr resolver 5 , 339bc7413d0SPeter Wemm.Xr hostname 7 , 34075141cc9SWolfram Schneider.Xr named 8 341bc7413d0SPeter Wemm.Pp 342bc7413d0SPeter Wemm.%T RFC1032 , 343bc7413d0SPeter Wemm.%T RFC1033 , 344bc7413d0SPeter Wemm.%T RFC1034 , 345bc7413d0SPeter Wemm.%T RFC1035 , 346bc7413d0SPeter Wemm.%T RFC974 347bc7413d0SPeter Wemm.Rs 348bc7413d0SPeter Wemm.%T "Name Server Operations Guide for BIND" 349bc7413d0SPeter Wemm.Re 350bc7413d0SPeter Wemm.Sh HISTORY 351fdf4c7afSPeter WemmThe 352bc7413d0SPeter Wemm.Nm 353bc7413d0SPeter Wemmfunction appeared in 354bc7413d0SPeter Wemm.Bx 4.3 . 355