xref: /titanic_52/usr/src/man/man3resolv/resolver.3resolv (revision ed22c7109fc5dd9e1b7a5d0333bdc7ad2718e2ab)
te
Portions Copyright 1989 AT&T Portions Copyright (c) 1985, 1995 Regents of the University of California.
Copyright (C) 2006, Sun Microsystems, Inc. All Rights Reserved
RESOLVER 3RESOLV "Dec 26, 2006"
NAME
resolver, res_ninit, fp_resstat, res_hostalias, res_nquery, res_nsearch, res_nquerydomain, res_nmkquery, res_nsend, res_nclose, res_nsendsigned, dn_comp, dn_expand, hstrerror, res_init, res_query, res_search, res_mkquery, res_send, herror, res_getservers, res_setservers, res_ndestroy - resolver routines
SYNOPSIS

BIND 8.2.2 Interfaces

cc [ flag ... ] file ... -lresolv  -lsocket   -lnsl  [ library ... ]
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <netdb.h>

int res_ninit(res_state statp);

void res_ndestroy(res_state statp);

void fp_resstat(const res_state statp, FILE *fp);

const char *res_hostalias(const res_state statp, const char *name,
 char * name, char *buf, size_tbuflen);

int res_nquery(res_state statp, const char *dname, int class, int type,
 u_char *answer, int datalen, int anslen);

int res_nsearch(res_state statp, const char *dname, int class, int type,
 u_char *answer, int anslen);

int res_nquerydomain(res_state statp, const char *name,
 const char *domain, int class, int type,
 u_char *answer, int anslen);

int res_nmkquery(res_state statp, int op, const char *dname, int class,
 int type, u_char *answer, int datalen,
 int anslen);

int res_nsend(res_state statp, const u_char *msg, int msglen,
 u_char *answer, int anslen);

void res_nclose(res_state statp);

int res_snendsigned(res_state statp, const u_char *msg,
 int msglen, ns_tsig_key *key, u_char *answer, int anslen);

int dn_comp(const char *exp_dn, u_char *comp_dn, int length,
 u_char **dnptrs, **lastdnptr);

int dn_expand(const u_char *msg, *eomorig, *comp_dn, char *exp_dn,
 int length);

const char *hstrerror(int err);

void res_setservers(res_state statp, const union res_sockaddr_union *set,
 int cnt);

int res_getservers(res_state statp, union res_sockaddr_union *set,
 int cnt);

Deprecated Interfaces

cc [ flag ... ] file ... -lresolv  -lsocket   -lnsl  [ library ... ]
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <netdb.h>

int res_init(void)

int res_query(const char *dname, int class,
 int type, u_char *answer,
 int anslen);

int res_search(const char *dname, int class,
 int type, u_char *answer, int anslen);

int res_mkquery(int op, const char *dname, int class,
 int type, const char *data,int datalen,
 struct rrec *newrr, u_char *buf, int buflen);

int res_send(const u_char *msg, int msglen, u_char *answer,
 int anslen);

void herror(const char *s);
DESCRIPTION

These routines are used for making, sending, and interpreting 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 res_ndestroy() function should be called to free memory allocated by res_ninit() after the last use of statp.

The functions res_init(), res_query(), res_search(), res_mkquery(), res_send(), 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 reasonable defaults on the first call to res_ninit() or res_init() and can be ignored. Options stored in statp->options or _res.options are defined in <resolv.h>. They are stored as a simple bit mask containing the bitwise OR of the options enabled. RES_INIT

True if the initial name server address and default domain name are initialized, that is, res_init() or res_ninit() has been called.

RES_DEBUG

Print debugging messages.

RES_AAONLY

Accept authoritative answers only. With this option, res_send() will continue until it finds an authoritative answer or finds an error. Currently this option is not implemented.

RES_USEVC

Use TCP connections for queries instead of UDP datagrams.

RES_STAYOPEN

Use with RES_USEVC to keep the TCP connection open between queries. This is a useful option for programs that regularly do many queries. The normal mode used should be UDP.

RES_IGNTC

Ignore truncation errors; that is, do not retry with TCP.

RES_RECURSE

Set the recursion-desired bit in queries. This is the default. res_send() and res_nsend() do not do iterative queries and expect the name server to handle recursion.

RES_DEFNAMES

If set, res_search() and res_nsearch() append the default domain name to single-component names, that is, names that do not contain a dot. This option is enabled by default.

RES_DNSRCH

If this option is set, res_search() and res_nsearch() 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.

RES_NOALIASES

This option turns off the user level aliasing feature controlled by the HOSTALIASES environment variable. Network daemons should set this option.

RES_BLAST

If the RES_BLAST option is defined, resolver() queries will be sent to all servers. If the RES_BLAST option is not defined, but RES_ROTATE is , the list of nameservers are rotated according to a round-robin scheme. RES_BLAST overrides RES_ROTATE.

RES_ROTATE

This option causes res_nsend() and res_send() to rotate the list of nameservers in statp->nsaddr_list or _res.nsaddr_list.

RES_KEEPTSIG

This option causes res_nsendsigned() to leave the message unchanged after TSIG verification. Otherwise the TSIG record would be removed and the header would be updated.

"res_ninit(), res_init()"

The res_ninit() and res_init() routines read the configuration 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, res_init() or res_ninit() 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 RES_OPTIONS 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 RES_OPTIONS environment variable. Initialization normally occurs on the first call to one of the other resolver routines.

"res_nquery(), res_query()"

The res_nquery() and res_query() functions provide interfaces 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 information 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. res_nquery() and res_query() return the length of the answer, or -1 upon error.

The res_nquery() and res_query() 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.

"res_nsearch(), res_search()"

The res_nsearch() and res_search() routines make a query and await a response, just like like res_nquery() and res_query(). In addition, they implement the default and search rules controlled by the RES_DEFNAMES and RES_DNSRCH options. They return the length of the first successful reply which is stored in answer. On error, they reurn -1.

The res_nsearch() and res_search() 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.

"res_nquerydomain()"

The res_nquerydomain() function calls res_query() on the concatenation of name and domain, removing a trailing dot from name if domain is NULL.

"res_nmkquery(), res_mkquery()"

These routines are used by res_nquery() and res_query(). The res_nmkquery() and res_mkquery() functions construct a standard 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 <arpa/nameser.h>. The domain name for the query is given by dname. newrr is currently unused but is intended for making update messages.

"res_nsend(), res_send(), res_nsendsigned()"

The res_nsend(), res_send(), and res_nsendsigned() routines send a pre-formatted query that returns an answer. The routine calls res_ninit() or res_init(). If RES_INIT is not set, the routine sends the query to the local name server and handles timeouts and retries. Additionally, the res_nsendsigned() 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 res_nsend() and res_send() 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.

"fp_resstat()"

The function fp_resstat() prints out the active flag bits in statp->options preceded by the text ";; res options:" on file.

"res_hostalias()"

The function res_hostalias() 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, NULL is returned. res_hostalias() stores the result in buf.

"res_nclose()"

The res_nclose() function closes any open files referenced through statp.

"res_ndestroy()"

The res_ndestroy() function calls res_nclose(), then frees any memory allocated by res_ninit() referenced through statp.

"dn_comp()"

The dn_comp() function compresses the domain name exp_dn and stores it in comp_dn. The dn_comp() function returns the size of the compressed name, or -1 if there were errors. length is the size of the array pointed to by comp_dn.

The dnptrs parameter is a pointer to the head of the list of pointers to previously compressed names in the current message. The first pointer must point to the beginning of the message. The list ends with NULL. The limit to the array is specified by lastdnptr.

A side effect of calling dn_comp() is to update the list of pointers for labels inserted into the message by dn_comp() as the name is compressed. If dnptrs is NULL, names are not compressed. If lastdnptr is NULL, dn_comp() does not update the list of labels.

"dn_expand()"

The dn_expand() function expands the compressed domain name comp_dn to a full domain name. The compressed name is contained 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 exp_dn, which is of size length. The dn_expand() function returns the size of the compressed name, or -1 if there was an error.

"hstrerror(), herror()"

The variables statp->res_h_errno and _res.res_h_errno and external variable h_errno are set whenever an error occurs during a resolver operation. The following definitions are given in <netdb.h>:

#define NETDB_INTERNAL -1 /* see errno */
#define NETDB_SUCCESS 0 /* no problem */
#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
#define TRY_AGAIN 2 /* Non-Authoritative not found, or SERVFAIL */
#define NO_RECOVERY 3 /* Non-Recoverable: FORMERR, REFUSED, NOTIMP*/
#define NO_DATA 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 h_errno.

The hstrerror() function returns a string, which is the message text that corresponds to the value of the err parameter.

"res_setservers(), res_getservers()"

The functions res_getservers() and res_setservers() are used to get and set the list of servers to be queried.

FILES
/etc/resolv.conf

resolver configuration file

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability Committed
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 System. 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 Consortium, 1996.

NOTES

When the caller supplies a work buffer, for example the answer buffer argument to res_nsend() or res_send(), the buffer should be aligned on an eight byte boundary. Otherwise, an error such as a SIGBUS may result.