Resolver Library Functions resolver(3RESOLV)
NAME
resolver, resninit, fpresstat, reshostalias, resnquery,
resnsearch, resnquerydomain, resnmkquery, resnsend,
resnclose, resnsendsigned, dncomp, dnexpand, hstrerror,
resinit, resquery, ressearch, resmkquery, ressend, her-
ror, resgetservers, ressetservers, resndestroy - resolver
routines
SYNOPSIS
BIND 8.2.2 Interfaces
cc [ flag ... ] file ... -lresolv -lsocket -lnsl [ library ... ]
#include
#include
#include
#include
#include
int resninit(resstate statp);
void resndestroy(resstate statp);
void fpresstat(const resstate statp, FILE *fp);
const char *reshostalias(const resstate statp, const char *name,
char * name, char *buf, sizetbuflen);
int resnquery(resstate statp, const char *dname, int class, int type,
uchar *answer, int datalen, int anslen);
int resnsearch(resstate statp, const char *dname, int class, int type,
uchar *answer, int anslen);
int resnquerydomain(resstate statp, const char *name,
const char *domain, int class, int type,
uchar *answer, int anslen);
int resnmkquery(resstate statp, int op, const char *dname, int class,
int type, uchar *answer, int datalen,
int anslen);
int resnsend(resstate statp, const uchar *msg, int msglen,
uchar *answer, int anslen);
SunOS 5.11 Last change: 26 Dec 2006 1
Resolver Library Functions resolver(3RESOLV)
void resnclose(resstate statp);
int ressnendsigned(resstate statp, const uchar *msg,
int msglen, nstsigkey *key, uchar *answer, int anslen);
int dncomp(const char *expdn, uchar *compdn, int length,
uchar **dnptrs, **lastdnptr);
int dnexpand(const uchar *msg, *eomorig, *compdn, char *expdn,
int length);
const char *hstrerror(int err);
void ressetservers(resstate statp, const union ressockaddrunion *set,
int cnt);
int resgetservers(resstate statp, union ressockaddrunion *set,
int cnt);
Deprecated Interfaces
cc [ flag ... ] file ... -lresolv -lsocket -lnsl [ library ... ]
#include
#include
#include
#include
#include
int resinit(void)
int resquery(const char *dname, int class,
int type, uchar *answer,
int anslen);
int ressearch(const char *dname, int class,
int type, uchar *answer, int anslen);
int resmkquery(int op, const char *dname, int class,
int type, const char *data,int datalen,
struct rrec *newrr, uchar *buf, int buflen);
SunOS 5.11 Last change: 26 Dec 2006 2
Resolver Library Functions resolver(3RESOLV)
int ressend(const uchar *msg, int msglen, uchar *answer,
int anslen);
void herror(const char *s);
DESCRIPTION
These routines are used for making, sending, and interpret-
ing query and reply messages with Internet domain name
servers.
State information is kept in statp and is used to control
the behavior of these functions. Set statp to all zeros
prior to making the first call to any of these functions.
The resndestroy() function should be called to free memory
allocated by resninit() after the last use of statp.
The functions resinit(), resquery(), ressearch(),
resmkquery(), ressend(), and herror() are deprecated. They
are supplied for backwards compatability. They use global
configuration and state information that is kept in the
structure res rather than state information referenced
through statp.
Most of the values in statp and res are initialized to rea-
sonable defaults on the first call to resninit() or
resinit() and can be ignored. Options stored in statp-
>options or res.options are defined in . They are
stored as a simple bit mask containing the bitwise OR of the
options enabled.
RESINIT True if the initial name server address and
default domain name are initialized, that
is, resinit() or resninit() has been
called.
RESDEBUG Print debugging messages.
RESAONLY Accept authoritative answers only. With
this option, ressend() will continue until
it finds an authoritative answer or finds
an error. Currently this option is not
implemented.
SunOS 5.11 Last change: 26 Dec 2006 3
Resolver Library Functions resolver(3RESOLV)
RESUSEVC Use TCP connections for queries instead of
UDP datagrams.
RESTAYOPEN Use with RESUSEVC to keep the TCP connec-
tion open between queries. This is a useful
option for programs that regularly do many
queries. The normal mode used should be
UDP.
RESIGNTC Ignore truncation errors; that is, do not
retry with TCP.
RESRECURSE Set the recursion-desired bit in queries.
This is the default. ressend() and
resnsend() do not do iterative queries and
expect the name server to handle recursion.
RESDEFNAMES If set, ressearch() and resnsearch()
append the default domain name to single-
component names, that is, names that do not
contain a dot. This option is enabled by
default.
RESDNSRCH If this option is set, ressearch() and
resnsearch() search for host names in the
current domain and in parent domains. See
hostname(1). This option is used by the
standard host lookup routine
gethostbyname(3NSL). This option is enabled
by default.
RESNOALIASES This option turns off the user level alias-
ing feature controlled by the HOSTALIASES
environment variable. Network daemons
should set this option.
RESBLAST If the RESBLAST option is defined,
resolver() queries will be sent to all
servers. If the RESBLAST option is not
defined, but RESROTATE is , the list of
nameservers are rotated according to a
round-robin scheme. RESBLAST overrides
RESROTATE.
SunOS 5.11 Last change: 26 Dec 2006 4
Resolver Library Functions resolver(3RESOLV)
RESROTATE This option causes resnsend() and
ressend() to rotate the list of
nameservers in statp->nsaddrlist or
res.nsaddrlist.
RESKEPTSIG This option causes resnsendsigned() to
leave the message unchanged after TSIG
verification. Otherwise the TSIG record
would be removed and the header would be
updated.
resninit, resinit
The resninit() and resinit() routines read the configura-
tion file, if any is present, to get the default domain
name, search list and the Internet address of the local name
server(s). See resolv.conf(4). If no server is configured,
resinit() or resninit() will try to obtain name resolution
services from the host on which it is running. The current
domain name is defined by domainname(1M), or by the hostname
if it is not specified in the configuration file. Use the
environment variable LOCALDOMAIN to override the domain
name. This environment variable may contain several blank-
separated tokens if you wish to override the search list on
a per-process basis. This is similar to the search command
in the configuration file. You can set the RESOPTIONS
environment variable to override certain internal resolver
options. You can otherwise set them by changing fields in
the statp /res structure. Alternatively, they are inherited
from the configuration file's options command. See
resolv.conf(4) for information regarding the syntax of the
RESOPTIONS environment variable. Initialization normally
occurs on the first call to one of the other resolver rou-
tines.
resnquery, resquery
The resnquery() and resquery() functions provide inter-
faces to the server query mechanism. They construct a query,
send it to the local server, await a response, and make
preliminary checks on the reply. The query requests informa-
tion of the specified type and class for the specified
fully-qualified domain name dname. The reply message is left
in the answer buffer with length anslen supplied by the
caller. resnquery() and resquery() return the length of
the answer, or -1 upon error.
The resnquery() and resquery() routines return a length
that may be bigger than anslen. In that case, retry the
query with a larger buf. The answer to the second query may
be larger still], so it is recommended that you supply a buf
SunOS 5.11 Last change: 26 Dec 2006 5
Resolver Library Functions resolver(3RESOLV)
larger than the answer returned by the previous query.
answer must be large enough to receive a maximum UDP
response from the server or parts of the answer will be
silently discarded. The default maximum UDP response size is
512 bytes.
resnsearch, ressearch
The resnsearch() and ressearch() routines make a query and
await a response, just like like resnquery() and
resquery(). In addition, they implement the default and
search rules controlled by the RESDEFNAMES and RESDNSRCH
options. They return the length of the first successful
reply which is stored in answer. On error, they reurn -1.
The resnsearch() and ressearch() routines return a length
that may be bigger than anslen. In that case, retry the
query with a larger buf. The answer to the second query may
be larger still], so it is recommended that you supply a buf
larger than the answer returned by the previous query.
answer must be large enough to receive a maximum UDP
response from the server or parts of the answer will be
silently discarded. The default maximum UDP response size is
512 bytes.
resnmkquery, resmkquery
These routines are used by resnquery() and resquery(). The
resnmkquery() and resmkquery() functions construct a stan-
dard query message and place it in buf. The routine returns
the size of the query, or -1 if the query is larger than
buflen. The query type op is usually QUERY, but can be any
of the query types defined in . The domain
name for the query is given by dname. newrr is currently
unused but is intended for making update messages.
resnsend, ressend, resnsendsigned
The resnsend(), ressend(), and resnsendsigned() routines
send a pre-formatted query that returns an answer. The rou-
tine calls resninit() or resinit(). If RESINIT is not
set, the routine sends the query to the local name server
and handles timeouts and retries. Additionally, the
resnsendsigned() uses TSIG signatures to add authentication
to the query and verify the response. In this case, only one
name server will be contacted. The routines return the
length of the reply message, or -1 if there are errors.
The resnsend() and ressend() routines return a length that
may be bigger than anslen. In that case, retry the query
with a larger buf. The answer to the second query may be
larger still], so it is recommended that you supply a buf
larger than the answer returned by the previous query.
SunOS 5.11 Last change: 26 Dec 2006 6
Resolver Library Functions resolver(3RESOLV)
answer must be large enough to receive a maximum UDP
response from the server or parts of the answer will be
silently discarded. The default maximum UDP response size is
512 bytes.
fpresstat
The function fpresstat() prints out the active flag bits in
statp->options preceded by the text ";; res options:" on
file.
reshostalias
The function reshostalias() looks up name in the file
referred to by the HOSTALIASES environment variable and
returns the fully qualified host name. If name is not found
or an error occurs, NUL is returned. reshostalias() stores
the result in buf.
resnclose
The resnclose() function closes any open files referenced
through statp.
resndestroy
The resndestroy() function calls resnclose(), then frees
any memory allocated by resninit() referenced through
statp.
dncomp
The dncomp() function compresses the domain name expdn and
stores it in compdn. The dncomp() function returns the
size of the compressed name, or -1 if there were errors.
length is the size of the array pointed to by compdn.
The dnptrs parameter is a pointer to the head of the list of
pointers to previously compressed names in the current mes-
sage. The first pointer must point to the beginning of the
message. The list ends with NUL. The limit to the array is
specified by lastdnptr.
A side effect of calling dncomp() is to update the list of
pointers for labels inserted into the message by dncomp()
as the name is compressed. If dnptrs is NUL, names are not
compressed. If lastdnptr is NUL, dncomp() does not update
the list of labels.
dnexpand
The dnexpand() function expands the compressed domain name
compdn to a full domain name. The compressed name is con-
tained in a query or reply message. msg is a pointer to the
beginning of that message. The uncompressed name is placed
in the buffer indicated by expdn, which is of size length.
SunOS 5.11 Last change: 26 Dec 2006 7
Resolver Library Functions resolver(3RESOLV)
The dnexpand() function returns the size of the compressed
name, or -1 if there was an error.
hstrerror, herror
The variables statp->resherrno and res.resherrno and
external variable herrno are set whenever an error occurs
during a resolver operation. The following definitions are
given in :
#define NETDBINTERNAL -1 /* see errno */
#define NETDBSUCES 0 /* no problem */
#define HOSTNOTFOUND 1 /* Authoritative Answer Host not found */
#define TRYAGAIN 2 /* Non-Authoritative not found, or SERVFAIL */
#define NORECOVERY 3 /* Non-Recoverable: FORMER, REFUSED, NOTIMP*/
#define NODATA 4 /* Valid name, no data for requested type */
The herror() function writes a message to the diagnostic
output consisting of the string parameters, the constant
string ":", and a message corresponding to the value of
herrno.
The hstrerror() function returns a string, which is the mes-
sage text that corresponds to the value of the err parame-
ter.
ressetservers, resgetservers
The functions resgetservers() and ressetservers() are used
to get and set the list of servers to be queried.
FILES
/etc/resolv.conf resolver configuration file
ATRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
SunOS 5.11 Last change: 26 Dec 2006 8
Resolver Library Functions resolver(3RESOLV)
ATRIBUTE TYPE ATRIBUTE VALUE
Availability SUNWcsl (32-bit)
SUNWcslx (64-bit)
Interface Stability Evolving
MT-Level Unsafe for Deprecated
Interfaces; MT-Safe for all
others.
SEE ALSO
domainname(1M), gethostbyname(3NSL), libresolv(3LIB),
resolv.conf(4), attributes(5)
Lottor, M. RFC 1033, Domain Administrators Operations Guide.
Network Working Group. November 1987.
Mockapetris, Paul. RFC 1034, Domain Names - Concepts and
Facilities. Network Working Group. November 1987.
Mockapetris, Paul. RFC 1035, Domain Names - Implementation
and Specification. Network Working Group. November 1987.
Partridge, Craig. RFC 974, Mail Routing and the Domain Sys-
tem. Network Working Group. January 1986.
Stahl, M. RFC 1032, Domain Administrators Guide. Network
Working Group. November 1987.
Vixie, Paul, Dunlap, Kevin J., Karels, Michael J. Name
Server Operations Guide for BIND. Internet Software Consor-
tium, 1996.
NOTES
When the caller supplies a work buffer, for example the
answer buffer argument to resnsend() or ressend(), the
buffer should be aligned on an eight byte boundary. Other-
wise, an error such as a SIGBUS may result.
SunOS 5.11 Last change: 26 Dec 2006 9
|