xref: /csrg-svn/lib/libc/net/resolver.3 (revision 61151)
1*61151Sbostic.\" Copyright (c) 1985, 1991, 1993
2*61151Sbostic.\"	The Regents of the University of California.  All rights reserved.
325102Skjd.\"
448975Scael.\" %sccs.include.redist.roff%
525102Skjd.\"
6*61151Sbostic.\"     @(#)resolver.3	8.1 (Berkeley) 06/04/93
736740Sbostic.\"
848975Scael.Dd
948975Scael.Dt RESOLVER 3
1050489Scael.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
2150645Scael.Fd #include <sys/types.h>
2250645Scael.Fd #include <netinet/in.h>
2350645Scael.Fd #include <arpa/nameser.h>
2450645Scael.Fd #include <resolv.h>
2550645Scael.Fo res_query
2650645Scael.Fa "char *dname"
2750645Scael.Fa "int class"
2850645Scael.Fa "int type"
2950645Scael.Fa "u_char *answer"
3050645Scael.Fa "int anslen"
3150645Scael.Fc
3250645Scael.Fo res_search
3350645Scael.Fa "char *dname"
3450645Scael.Fa "int class"
3550645Scael.Fa "int type"
3650645Scael.Fa "u_char *answer"
3750645Scael.Fa "int anslen"
3850645Scael.Fc
3950645Scael.Fo res_mkquery
4050645Scael.Fa "int op"
4150645Scael.Fa "char *dname"
4250645Scael.Fa "int class"
4350645Scael.Fa "int type"
4450645Scael.Fa "char *data"
4550645Scael.Fa "int datalen"
4650645Scael.Fa "struct rrec *newrr"
4750645Scael.Fa "char *buf"
4850645Scael.Fa "int buflen"
4950645Scael.Fc
5050645Scael.Fo res_send
5150645Scael.Fa "char *msg"
5250645Scael.Fa "int msglen"
5350645Scael.Fa "char *answer"
5450645Scael.Fa "int anslen"
5550645Scael.Fc
5648975Scael.Fn res_init
5750645Scael.Fo dn_comp
5850645Scael.Fa "char *exp_dn"
5950645Scael.Fa "char *comp_dn"
6050645Scael.Fa "int length"
6150645Scael.Fa "char **dnptrs"
6250645Scael.Fa "char **lastdnptr"
6350645Scael.Fc
6450645Scael.Fo dn_expand
6550645Scael.Fa "u_char *msg"
6650645Scael.Fa "u_char *eomorig"
6750645Scael.Fa "u_char *comp_dn"
6850645Scael.Fa "u_char *exp_dn"
6950645Scael.Fa "int length"
7050645Scael.Fc
7148975Scael.Sh DESCRIPTION
7239716SkarelsThese routines are used for making, sending and interpreting
7339716Skarelsquery and reply messages with Internet domain name servers.
7448975Scael.Pp
7539716SkarelsGlobal configuration and state information that is used by the
7639716Skarelsresolver routines is kept in the structure
7748975Scael.Em _res .
7832651SkarelsMost of the values have reasonable defaults and can be ignored.
7932651SkarelsOptions
8025102Skjdstored in
8148975Scael.Em _res.options
8225102Skjdare defined in
8348975Scael.Pa resolv.h
8432651Skarelsand are as follows.
8539716SkarelsOptions are stored as a simple bit mask containing the bitwise ``or''
8632651Skarelsof the options enabled.
8750645Scael.Bl -tag -width RES_DEFNAMES
8850489Scael.It Dv RES_INIT
8925102SkjdTrue if the initial name server address and default domain name are
9025102Skjdinitialized (i.e.,
9148975Scael.Fn res_init
9225102Skjdhas been called).
9350489Scael.It Dv RES_DEBUG
9425102SkjdPrint debugging messages.
9550489Scael.It Dv RES_AAONLY
9625102SkjdAccept authoritative answers only.
9732651SkarelsWith this option,
9848975Scael.Fn res_send
9932651Skarelsshould continue until it finds an authoritative answer or finds an error.
10025102SkjdCurrently this is not implemented.
10150489Scael.It Dv RES_USEVC
10250489ScaelUse
10350489Scael.Tn TCP
10450489Scaelconnections for queries instead of
10548975Scael.Tn UDP
10648975Scaeldatagrams.
10750489Scael.It Dv RES_STAYOPEN
10850645ScaelUsed with
10950645Scael.Dv RES_USEVC
11050645Scaelto keep the
11150489Scael.Tn TCP
11250489Scaelconnection open between
11326926Skjdqueries.
11426926SkjdThis is useful only in programs that regularly do many queries.
11548975Scael.Tn UDP
11648975Scaelshould be the normal mode used.
11750489Scael.It Dv RES_IGNTC
11850489ScaelUnused currently (ignore truncation errors, i.e., don't retry with
11950489Scael.Tn TCP ) .
12050489Scael.It Dv RES_RECURSE
12132651SkarelsSet the recursion-desired bit in queries.
12232651SkarelsThis is the default.
12350645Scael.Pf ( Fn res_send
12426926Skjddoes not do iterative queries and expects the name server
12526926Skjdto handle recursion.)
12650489Scael.It Dv RES_DEFNAMES
12732651SkarelsIf set,
12848975Scael.Fn res_search
12932651Skarelswill append the default domain name to single-component names
13032651Skarels(those that do not contain a dot).
13139716SkarelsThis option is enabled by default.
13250489Scael.It Dv RES_DNSRCH
13332651SkarelsIf this option is set,
13448975Scael.Fn res_search
13532651Skarelswill search for host names in the current domain and in parent domains; see
13648975Scael.Xr hostname 7 .
13739716SkarelsThis is used by the standard host lookup routine
13848975Scael.Xr gethostbyname 3 .
13939716SkarelsThis option is enabled by default.
14050645Scael.El
14148975Scael.Pp
14239716SkarelsThe
14348975Scael.Fn res_init
14439716Skarelsroutine
14539716Skarelsreads the configuration file (if any; see
14648975Scael.Xr resolver 5 )
14739716Skarelsto get the default domain name,
14839716Skarelssearch list and
14939716Skarelsthe Internet address of the local name server(s).
15039716SkarelsIf no server is configured, the host running
15139716Skarelsthe resolver is tried.
15239716SkarelsThe current domain name is defined by the hostname
15339716Skarelsif not specified in the configuration file;
15450489Scaelit can be overridden by the environment variable
15550489Scael.Ev LOCALDOMAIN .
15639716SkarelsInitialization normally occurs on the first call
15739716Skarelsto one of the following routines.
15848975Scael.Pp
15939716SkarelsThe
16048975Scael.Fn res_query
16139716Skarelsfunction provides an interface to the server query mechanism.
16239716SkarelsIt constructs a query, sends it to the local server,
16339716Skarelsawaits a response, and makes preliminary checks on the reply.
16439716SkarelsThe query requests information of the specified
16548975Scael.Fa type
16639716Skarelsand
16748975Scael.Fa class
16839716Skarelsfor the specified fully-qualified domain name
16948975Scael.Fa dname .
17039716SkarelsThe reply message is left in the
17148975Scael.Fa answer
17239716Skarelsbuffer with length
17348975Scael.Fa anslen
17439716Skarelssupplied by the caller.
17548975Scael.Pp
17639716SkarelsThe
17748975Scael.Fn res_search
17839716Skarelsroutine makes a query and awaits a response like
17948975Scael.Fn res_query ,
18039716Skarelsbut in addition, it implements the default and search rules
18150489Scaelcontrolled by the
18250489Scael.Dv RES_DEFNAMES
18350489Scaeland
18450489Scael.Dv RES_DNSRCH
18550489Scaeloptions.
18639716SkarelsIt returns the first successful reply.
18748975Scael.Pp
18839716SkarelsThe remaining routines are lower-level routines used by
18948975Scael.Fn res_query .
19039716SkarelsThe
19148975Scael.Fn res_mkquery
19239716Skarelsfunction
19339716Skarelsconstructs a standard query message and places it in
19448975Scael.Fa buf .
19539716SkarelsIt returns the size of the query, or \-1 if the query is
19625102Skjdlarger than
19748975Scael.Fa buflen .
19839716SkarelsThe query type
19948975Scael.Fa op
20050489Scaelis usually
20150489Scael.Dv QUERY ,
20250489Scaelbut can be any of the query types defined in
20350645Scael.Aq Pa arpa/nameser.h .
20439716SkarelsThe domain name for the query is given by
20548975Scael.Fa dname .
20648975Scael.Fa Newrr
20725102Skjdis currently unused but is intended for making update messages.
20848975Scael.Pp
20939716SkarelsThe
21048975Scael.Fn res_send
21139716Skarelsroutine
21239716Skarelssends a pre-formatted query and returns an answer.
21325102SkjdIt will call
21448975Scael.Fn res_init
21550489Scaelif
21650489Scael.Dv RES_INIT
21750489Scaelis not set, send the query to the local name server, and
21832651Skarelshandle timeouts and retries.
21939716SkarelsThe length of the reply message is returned, or
22025102Skjd\-1 if there were errors.
22148975Scael.Pp
22239716SkarelsThe
22348975Scael.Fn dn_comp
22439716Skarelsfunction
22528825Skjdcompresses the domain name
22648975Scael.Fa exp_dn
22725102Skjdand stores it in
22848975Scael.Fa comp_dn .
22939716SkarelsThe size of the compressed name is returned or \-1 if there were errors.
23039716SkarelsThe size of the array pointed to by
23148975Scael.Fa comp_dn
23239716Skarelsis given by
23348975Scael.Fa length .
23439716SkarelsThe compression uses
23539716Skarelsan array of pointers
23648975Scael.Fa dnptrs
23739716Skarelsto previously-compressed names in the current message.
23825102SkjdThe first pointer points to
23950489Scaelto the beginning of the message and the list ends with
24050489Scael.Dv NULL .
24139716SkarelsThe limit to the array is specified by
24248975Scael.Fa lastdnptr .
24339716SkarelsA side effect of
24448975Scael.Fn dn_comp
24539716Skarelsis to update the list of pointers for
24639716Skarelslabels inserted into the message
24725102Skjdas the name is compressed.
24825102SkjdIf
24948975Scael.Em dnptr
25050489Scaelis
25150489Scael.Dv NULL, names are not compressed.
25232651SkarelsIf
25348975Scael.Fa lastdnptr
25450489Scaelis
25550489Scael.Dv NULL ,
25650489Scaelthe list of labels is not updated.
25748975Scael.Pp
25839716SkarelsThe
25948975Scael.Fn dn_expand
26039716Skarelsentry
26139716Skarelsexpands the compressed domain name
26248975Scael.Fa comp_dn
26339716Skarelsto a full domain name
26439716SkarelsThe compressed name is contained in a query or reply message;
26548975Scael.Fa msg
26639716Skarelsis a pointer to the beginning of the message.
26739716SkarelsThe uncompressed name is placed in the buffer indicated by
26848975Scael.Fa exp_dn
26939716Skarelswhich is of size
27048975Scael.Fa length .
27139716SkarelsThe size of compressed name is returned or \-1 if there was an error.
27248975Scael.Sh FILES
27348975Scael.Bl -tag -width Pa
27448975Scael/etc/resolv.conf
27550489ScaelThe configuration file
27650489Scaelsee
27750489Scael.Xr resolver 5 .
27848975Scael.El
27948975Scael.Sh SEE ALSO
28048975Scael.Xr gethostbyname 3 ,
28148975Scael.Xr named 8 ,
28248975Scael.Xr resolver 5 ,
28348975Scael.Xr hostname 7 ,
28450645Scael.Pp
28550645Scael.%T RFC1032 ,
28650645Scael.%T RFC1033 ,
28750645Scael.%T RFC1034 ,
28850645Scael.%T RFC1035 ,
28950645Scael.%T RFC974
29050645Scael.Rs
29150645Scael.%T "Name Server Operations Guide for BIND"
29250645Scael.Re
29348975Scael.Sh HISTORY
29448975ScaelThe
29548975Scael.Nm
29648975Scaelfunction appeared in
29748975Scael.Bx 4.3 .
298