1.\" Copyright (c) 1985, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.roff% 5.\" 6.\" @(#)resolver.3 6.8 (Berkeley) 07/23/91 7.\" 8.Dd 9.Dt RESOLVER 3 10.Os BSD 4.3 11.Sh NAME 12.Nm res_query , 13.Nm res_search , 14.Nm res_mkquery , 15.Nm res_send , 16.Nm res_init , 17.Nm dn_comp , 18.Nm dn_expand 19.Nd resolver routines 20.Sh SYNOPSIS 21#include <sys/types.h> 22#include <netinet/in.h> 23#include <arpa/nameser.h> 24#include <resolv.h> 25"u_".Fn res_query char\ *dname int\ class int\ type char\ *answer int\ anslen 26u_".Fn res_search char\ *dname int\ class int\ type char\ *answer int\ anslen 27.Fn res_mkquery int\ op char\ *dname int\ class int\ type char\ *data int\ datalen struct\ rrec\ *newrr char\ *buf int\ buflen 28.Ft buflen 29.Fn res_send char\ *msg int\ msglen char\ *answer int\ anslen 30.Fn res_init 31.Fn dn_comp char\ *exp_dn char\ *comp_dn int\ length dnptrs lastdnptr 32u_.Fn dn_expand char\ *msg char\ *eomorig char\ *comp_dn char\ *exp_dn int\ length 33.Sh DESCRIPTION 34These routines are used for making, sending and interpreting 35query and reply messages with Internet domain name servers. 36.Pp 37Global configuration and state information that is used by the 38resolver routines is kept in the structure 39.Em _res . 40Most of the values have reasonable defaults and can be ignored. 41Options 42stored in 43.Em _res.options 44are defined in 45.Pa resolv.h 46and are as follows. 47Options are stored as a simple bit mask containing the bitwise ``or'' 48of the options enabled. 49.Bl -tag -width indent 50.It Dv RES_INIT 51True if the initial name server address and default domain name are 52initialized (i.e., 53.Fn res_init 54has been called). 55.It Dv RES_DEBUG 56Print debugging messages. 57.It Dv RES_AAONLY 58Accept authoritative answers only. 59With this option, 60.Fn res_send 61should continue until it finds an authoritative answer or finds an error. 62Currently this is not implemented. 63.It Dv RES_USEVC 64Use 65.Tn TCP 66connections for queries instead of 67.Tn UDP 68datagrams. 69.It Dv RES_STAYOPEN 70Used with RES_USEVC to keep the 71.Tn TCP 72connection open between 73queries. 74This is useful only in programs that regularly do many queries. 75.Tn UDP 76should be the normal mode used. 77.It Dv RES_IGNTC 78Unused currently (ignore truncation errors, i.e., don't retry with 79.Tn TCP ) . 80.It Dv RES_RECURSE 81Set the recursion-desired bit in queries. 82This is the default. 83(\c 84.Fn res_send 85does not do iterative queries and expects the name server 86to handle recursion.) 87.It Dv RES_DEFNAMES 88If set, 89.Fn res_search 90will append the default domain name to single-component names 91(those that do not contain a dot). 92This option is enabled by default. 93.It Dv RES_DNSRCH 94If this option is set, 95.Fn res_search 96will search for host names in the current domain and in parent domains; see 97.Xr hostname 7 . 98This is used by the standard host lookup routine 99.Xr gethostbyname 3 . 100This option is enabled by default. 101.Pp 102The 103.Fn res_init 104routine 105reads the configuration file (if any; see 106.Xr resolver 5 ) 107to get the default domain name, 108search list and 109the Internet address of the local name server(s). 110If no server is configured, the host running 111the resolver is tried. 112The current domain name is defined by the hostname 113if not specified in the configuration file; 114it can be overridden by the environment variable 115.Ev LOCALDOMAIN . 116Initialization normally occurs on the first call 117to one of the following routines. 118.Pp 119The 120.Fn res_query 121function provides an interface to the server query mechanism. 122It constructs a query, sends it to the local server, 123awaits a response, and makes preliminary checks on the reply. 124The query requests information of the specified 125.Fa type 126and 127.Fa class 128for the specified fully-qualified domain name 129.Fa dname . 130The reply message is left in the 131.Fa answer 132buffer with length 133.Fa anslen 134supplied by the caller. 135.Pp 136The 137.Fn res_search 138routine makes a query and awaits a response like 139.Fn res_query , 140but in addition, it implements the default and search rules 141controlled by the 142.Dv RES_DEFNAMES 143and 144.Dv RES_DNSRCH 145options. 146It returns the first successful reply. 147.Pp 148The remaining routines are lower-level routines used by 149.Fn res_query . 150The 151.Fn res_mkquery 152function 153constructs a standard query message and places it in 154.Fa buf . 155It returns the size of the query, or \-1 if the query is 156larger than 157.Fa buflen . 158The query type 159.Fa op 160is usually 161.Dv QUERY , 162but can be any of the query types defined in 163.Ao Pa arpa/nameser.h Ac . 164The domain name for the query is given by 165.Fa dname . 166.Fa Newrr 167is currently unused but is intended for making update messages. 168.Pp 169The 170.Fn res_send 171routine 172sends a pre-formatted query and returns an answer. 173It will call 174.Fn res_init 175if 176.Dv RES_INIT 177is not set, send the query to the local name server, and 178handle timeouts and retries. 179The length of the reply message is returned, or 180\-1 if there were errors. 181.Pp 182The 183.Fn dn_comp 184function 185compresses the domain name 186.Fa exp_dn 187and stores it in 188.Fa comp_dn . 189The size of the compressed name is returned or \-1 if there were errors. 190The size of the array pointed to by 191.Fa comp_dn 192is given by 193.Fa length . 194The compression uses 195an array of pointers 196.Fa dnptrs 197to previously-compressed names in the current message. 198The first pointer points to 199to the beginning of the message and the list ends with 200.Dv NULL . 201The limit to the array is specified by 202.Fa lastdnptr . 203A side effect of 204.Fn dn_comp 205is to update the list of pointers for 206labels inserted into the message 207as the name is compressed. 208If 209.Em dnptr 210is 211.Dv NULL, names are not compressed. 212If 213.Fa lastdnptr 214is 215.Dv NULL , 216the list of labels is not updated. 217.Pp 218The 219.Fn dn_expand 220entry 221expands the compressed domain name 222.Fa comp_dn 223to a full domain name 224The compressed name is contained in a query or reply message; 225.Fa msg 226is a pointer to the beginning of the message. 227The uncompressed name is placed in the buffer indicated by 228.Fa exp_dn 229which is of size 230.Fa length . 231The size of compressed name is returned or \-1 if there was an error. 232.Sh FILES 233.Bl -tag -width Pa 234/etc/resolv.conf 235The configuration file 236see 237.Xr resolver 5 . 238.El 239.Sh SEE ALSO 240.Xr gethostbyname 3 , 241.Xr named 8 , 242.Xr resolver 5 , 243.Xr hostname 7 , 244.br 245RFC1032, RFC1033, RFC1034, RFC1035, RFC974, 246.br 247SMM:11 Name Server Operations Guide for BIND 248.Sh HISTORY 249The 250.Nm 251function appeared in 252.Bx 4.3 . 253