148975Scael.\" Copyright (c) 1985, 1991 The Regents of the University of California. 236740Sbostic.\" All rights reserved. 325102Skjd.\" 448975Scael.\" %sccs.include.redist.roff% 525102Skjd.\" 6*50489Scael.\" @(#)resolver.3 6.8 (Berkeley) 07/23/91 736740Sbostic.\" 848975Scael.Dd 948975Scael.Dt RESOLVER 3 10*50489Scael.Os BSD 4.3 1148975Scael.Sh NAME 1248975Scael.Nm res_query , 1348975Scael.Nm res_search , 1448975Scael.Nm res_mkquery , 1548975Scael.Nm res_send , 1648975Scael.Nm res_init , 1748975Scael.Nm dn_comp , 1848975Scael.Nm dn_expand 1948975Scael.Nd resolver routines 2048975Scael.Sh SYNOPSIS 2148975Scael#include <sys/types.h> 2248975Scael#include <netinet/in.h> 2348975Scael#include <arpa/nameser.h> 2448975Scael#include <resolv.h> 2548975Scael"u_".Fn res_query char\ *dname int\ class int\ type char\ *answer int\ anslen 2648975Scaelu_".Fn res_search char\ *dname int\ class int\ type char\ *answer int\ anslen 2748975Scael.Fn res_mkquery int\ op char\ *dname int\ class int\ type char\ *data int\ datalen struct\ rrec\ *newrr char\ *buf int\ buflen 2848975Scael.Ft buflen 2948975Scael.Fn res_send char\ *msg int\ msglen char\ *answer int\ anslen 3048975Scael.Fn res_init 3148975Scael.Fn dn_comp char\ *exp_dn char\ *comp_dn int\ length dnptrs lastdnptr 3248975Scaelu_.Fn dn_expand char\ *msg char\ *eomorig char\ *comp_dn char\ *exp_dn int\ length 3348975Scael.Sh DESCRIPTION 3439716SkarelsThese routines are used for making, sending and interpreting 3539716Skarelsquery and reply messages with Internet domain name servers. 3648975Scael.Pp 3739716SkarelsGlobal configuration and state information that is used by the 3839716Skarelsresolver routines is kept in the structure 3948975Scael.Em _res . 4032651SkarelsMost of the values have reasonable defaults and can be ignored. 4132651SkarelsOptions 4225102Skjdstored in 4348975Scael.Em _res.options 4425102Skjdare defined in 4548975Scael.Pa resolv.h 4632651Skarelsand are as follows. 4739716SkarelsOptions are stored as a simple bit mask containing the bitwise ``or'' 4832651Skarelsof the options enabled. 4948975Scael.Bl -tag -width indent 50*50489Scael.It Dv RES_INIT 5125102SkjdTrue if the initial name server address and default domain name are 5225102Skjdinitialized (i.e., 5348975Scael.Fn res_init 5425102Skjdhas been called). 55*50489Scael.It Dv RES_DEBUG 5625102SkjdPrint debugging messages. 57*50489Scael.It Dv RES_AAONLY 5825102SkjdAccept authoritative answers only. 5932651SkarelsWith this option, 6048975Scael.Fn res_send 6132651Skarelsshould continue until it finds an authoritative answer or finds an error. 6225102SkjdCurrently this is not implemented. 63*50489Scael.It Dv RES_USEVC 64*50489ScaelUse 65*50489Scael.Tn TCP 66*50489Scaelconnections for queries instead of 6748975Scael.Tn UDP 6848975Scaeldatagrams. 69*50489Scael.It Dv RES_STAYOPEN 70*50489ScaelUsed with RES_USEVC to keep the 71*50489Scael.Tn TCP 72*50489Scaelconnection open between 7326926Skjdqueries. 7426926SkjdThis is useful only in programs that regularly do many queries. 7548975Scael.Tn UDP 7648975Scaelshould be the normal mode used. 77*50489Scael.It Dv RES_IGNTC 78*50489ScaelUnused currently (ignore truncation errors, i.e., don't retry with 79*50489Scael.Tn TCP ) . 80*50489Scael.It Dv RES_RECURSE 8132651SkarelsSet the recursion-desired bit in queries. 8232651SkarelsThis is the default. 8339716Skarels(\c 8448975Scael.Fn res_send 8526926Skjddoes not do iterative queries and expects the name server 8626926Skjdto handle recursion.) 87*50489Scael.It Dv RES_DEFNAMES 8832651SkarelsIf set, 8948975Scael.Fn res_search 9032651Skarelswill append the default domain name to single-component names 9132651Skarels(those that do not contain a dot). 9239716SkarelsThis option is enabled by default. 93*50489Scael.It Dv RES_DNSRCH 9432651SkarelsIf this option is set, 9548975Scael.Fn res_search 9632651Skarelswill search for host names in the current domain and in parent domains; see 9748975Scael.Xr hostname 7 . 9839716SkarelsThis is used by the standard host lookup routine 9948975Scael.Xr gethostbyname 3 . 10039716SkarelsThis option is enabled by default. 10148975Scael.Pp 10239716SkarelsThe 10348975Scael.Fn res_init 10439716Skarelsroutine 10539716Skarelsreads the configuration file (if any; see 10648975Scael.Xr resolver 5 ) 10739716Skarelsto get the default domain name, 10839716Skarelssearch list and 10939716Skarelsthe Internet address of the local name server(s). 11039716SkarelsIf no server is configured, the host running 11139716Skarelsthe resolver is tried. 11239716SkarelsThe current domain name is defined by the hostname 11339716Skarelsif not specified in the configuration file; 114*50489Scaelit can be overridden by the environment variable 115*50489Scael.Ev LOCALDOMAIN . 11639716SkarelsInitialization normally occurs on the first call 11739716Skarelsto one of the following routines. 11848975Scael.Pp 11939716SkarelsThe 12048975Scael.Fn res_query 12139716Skarelsfunction provides an interface to the server query mechanism. 12239716SkarelsIt constructs a query, sends it to the local server, 12339716Skarelsawaits a response, and makes preliminary checks on the reply. 12439716SkarelsThe query requests information of the specified 12548975Scael.Fa type 12639716Skarelsand 12748975Scael.Fa class 12839716Skarelsfor the specified fully-qualified domain name 12948975Scael.Fa dname . 13039716SkarelsThe reply message is left in the 13148975Scael.Fa answer 13239716Skarelsbuffer with length 13348975Scael.Fa anslen 13439716Skarelssupplied by the caller. 13548975Scael.Pp 13639716SkarelsThe 13748975Scael.Fn res_search 13839716Skarelsroutine makes a query and awaits a response like 13948975Scael.Fn res_query , 14039716Skarelsbut in addition, it implements the default and search rules 141*50489Scaelcontrolled by the 142*50489Scael.Dv RES_DEFNAMES 143*50489Scaeland 144*50489Scael.Dv RES_DNSRCH 145*50489Scaeloptions. 14639716SkarelsIt returns the first successful reply. 14748975Scael.Pp 14839716SkarelsThe remaining routines are lower-level routines used by 14948975Scael.Fn res_query . 15039716SkarelsThe 15148975Scael.Fn res_mkquery 15239716Skarelsfunction 15339716Skarelsconstructs a standard query message and places it in 15448975Scael.Fa buf . 15539716SkarelsIt returns the size of the query, or \-1 if the query is 15625102Skjdlarger than 15748975Scael.Fa buflen . 15839716SkarelsThe query type 15948975Scael.Fa op 160*50489Scaelis usually 161*50489Scael.Dv QUERY , 162*50489Scaelbut can be any of the query types defined in 16348975Scael.Ao Pa arpa/nameser.h Ac . 16439716SkarelsThe domain name for the query is given by 16548975Scael.Fa dname . 16648975Scael.Fa Newrr 16725102Skjdis currently unused but is intended for making update messages. 16848975Scael.Pp 16939716SkarelsThe 17048975Scael.Fn res_send 17139716Skarelsroutine 17239716Skarelssends a pre-formatted query and returns an answer. 17325102SkjdIt will call 17448975Scael.Fn res_init 175*50489Scaelif 176*50489Scael.Dv RES_INIT 177*50489Scaelis not set, send the query to the local name server, and 17832651Skarelshandle timeouts and retries. 17939716SkarelsThe length of the reply message is returned, or 18025102Skjd\-1 if there were errors. 18148975Scael.Pp 18239716SkarelsThe 18348975Scael.Fn dn_comp 18439716Skarelsfunction 18528825Skjdcompresses the domain name 18648975Scael.Fa exp_dn 18725102Skjdand stores it in 18848975Scael.Fa comp_dn . 18939716SkarelsThe size of the compressed name is returned or \-1 if there were errors. 19039716SkarelsThe size of the array pointed to by 19148975Scael.Fa comp_dn 19239716Skarelsis given by 19348975Scael.Fa length . 19439716SkarelsThe compression uses 19539716Skarelsan array of pointers 19648975Scael.Fa dnptrs 19739716Skarelsto previously-compressed names in the current message. 19825102SkjdThe first pointer points to 199*50489Scaelto the beginning of the message and the list ends with 200*50489Scael.Dv NULL . 20139716SkarelsThe limit to the array is specified by 20248975Scael.Fa lastdnptr . 20339716SkarelsA side effect of 20448975Scael.Fn dn_comp 20539716Skarelsis to update the list of pointers for 20639716Skarelslabels inserted into the message 20725102Skjdas the name is compressed. 20825102SkjdIf 20948975Scael.Em dnptr 210*50489Scaelis 211*50489Scael.Dv NULL, names are not compressed. 21232651SkarelsIf 21348975Scael.Fa lastdnptr 214*50489Scaelis 215*50489Scael.Dv NULL , 216*50489Scaelthe list of labels is not updated. 21748975Scael.Pp 21839716SkarelsThe 21948975Scael.Fn dn_expand 22039716Skarelsentry 22139716Skarelsexpands the compressed domain name 22248975Scael.Fa comp_dn 22339716Skarelsto a full domain name 22439716SkarelsThe compressed name is contained in a query or reply message; 22548975Scael.Fa msg 22639716Skarelsis a pointer to the beginning of the message. 22739716SkarelsThe uncompressed name is placed in the buffer indicated by 22848975Scael.Fa exp_dn 22939716Skarelswhich is of size 23048975Scael.Fa length . 23139716SkarelsThe size of compressed name is returned or \-1 if there was an error. 23248975Scael.Sh FILES 23348975Scael.Bl -tag -width Pa 23448975Scael/etc/resolv.conf 235*50489ScaelThe configuration file 236*50489Scaelsee 237*50489Scael.Xr resolver 5 . 23848975Scael.El 23948975Scael.Sh SEE ALSO 24048975Scael.Xr gethostbyname 3 , 24148975Scael.Xr named 8 , 24248975Scael.Xr resolver 5 , 24348975Scael.Xr hostname 7 , 24432651Skarels.br 24539716SkarelsRFC1032, RFC1033, RFC1034, RFC1035, RFC974, 24632651Skarels.br 24728825SkjdSMM:11 Name Server Operations Guide for BIND 24848975Scael.Sh HISTORY 24948975ScaelThe 25048975Scael.Nm 25148975Scaelfunction appeared in 25248975Scael.Bx 4.3 . 253