svcadm(1M)을 검색하려면 섹션에서 1M 을 선택하고, 맨 페이지 이름에 svcadm을 입력하고 검색을 누른다.
resolver(3resolv)
Resolver Library Functions resolver(3RESOLV)
NAME
resolver, res_state, 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_set‐
servers, res_ndestroy - resolver interface
SYNOPSIS
BIND 8.2.2 Interfaces
cc [ flag ... ] file ... -lresolv [ library ... ]
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#include <netdb.h>
typedef struct __res_state *res_state;
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 *buf, size_t buflen);
int res_nquery(res_state statp, const char *dname, int class, int type,
uchar_t *answer, int anslen);
int res_nsearch(res_state statp, const char *dname, int class, int type,
uchar_t *answer, int anslen);
int res_nquerydomain(res_state statp, const char *name,
const char *domain, int class, int type, uchar_t *answer,
int anslen);
int res_nmkquery(res_state statp, int op, const char *dname, int class,
int type, const uchar_t *data, int datalen,
const uchar_t *newrr_in, uchar_t *buf, int buflen);
int res_nsend(res_state statp, const uchar_t *msg, int msglen,
uchar_t *answer, int anslen);
void res_nclose(res_state statp);
int res_nsendsigned(res_state statp, const uchar_t *msg,
int msglen, ns_tsig_key *key, uchar_t *answer, int anslen);
int dn_comp(const char *exp_dn, uchar_t *comp_dn, int length,
uchar_t **dnptrs, uchar_t **lastdnptr);
int dn_expand(const uchar_t *msg, const uchar_t *eomorig,
const uchar_t *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 [ 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,
uchar_t *answer, int anslen);
int res_search(const char *dname, int class, int type,
uchar_t *answer, int anslen);
int res_mkquery(int op, const char *dname, int class,
int type, const uchar_t *data, int datalen,
const uchar_t *newrr, uchar_t *buf, int buflen);
int res_send(const uchar_t *msg, int msglen, uchar_t *answer,
int anslen);
void herror(const char *s);
DESCRIPTION
These routines are used for making, sending, and interpreting query and
reply messages with Domain Name System (DNS) servers.
Most applications will not call these routines directly, but instead
use the higher level, name-service-independent routines getaddrinfo(3C)
and getnameinfo(3C).
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 backward
compatibility. 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 bit‐
wise 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 authorita‐
tive answer or finds an error. Currently this option
is not implemented.
RES_USEVC Use TCP connections for queries instead of UDP data‐
grams.
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 itera‐
tive 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(3C).
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 name‐
servers 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 mes‐
sage 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 SMF configuration to
get the default domain name, search list and the Internet address of
the local name server(s). See resolv.conf(5). If no server is config‐
ured, res_init() or res_ninit() will try to obtain name resolution ser‐
vices from the host on which it is running. The current domain name is
defined by domainname(8), or by the hostname if it is not specified in
the SMF configuration. 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 property in the SMF
configuration. 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 from the SMF configuration options property. See
resolv.conf(5) 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 recom‐
mended 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 dis‐
carded. 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_DEF‐
NAMES and RES_DNSRCH options. They return the length of the first suc‐
cessful reply which is stored in answer. On error, they return −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 recom‐
mended 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 dis‐
carded. 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 recom‐
mended 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 dis‐
carded. 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 com‐
pressed. 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 com‐
pressed 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 con‐
sisting of the string parameters, the constant string ":", and a mes‐
sage 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.
EXAMPLES
Example 1 Basic API Usage
The following example shows basic usage of the resolver's API.
#include <resolv.h>
#include <string.h>
int main(int argc, char **argv)
{
int len;
struct __res_state statp;
union msg {
uchar_t buf[NS_MAXMSG];
HEADER h;
} resbuf;
/* Initialize resolver */
memset(&statp, 0, sizeof(statp));
if (res_ninit(&statp) < 0) {
fprintf(stderr, "Can't initialize statp.\n");
return (1);
}
/*
* Turning on DEBUG mode keeps this example simple,
* without need to output anything.
*/
statp.options |= RES_DEBUG;
/* Search for A type records */
len = res_nsearch(&statp, "example.com", C_IN, T_A,
resbuf.buf, NS_MAXMSG);
if (len < 0) {
fprintf(stderr, "Error occurred during search.\n");
return (1);
}
if (len > NS_MAXMSG) {
fprintf(stderr, "The buffer is too small.\n");
return (1);
}
/* ... Process the received answer ... */
/* Cleanup */
res_ndestroy(&statp);
return (0);
}
ATTRIBUTES
See attributes(7) for descriptions of the following attributes:
tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE TYPEAT‐
TRIBUTE VALUE _ Availabilitysystem/library _ Interface StabilityCommit‐
ted _ MT-LevelT{ Unsafe for deprecated interfaces; MT-Safe for all oth‐
ers. T}
SEE ALSO
gethostbyname(3C), libresolv(3LIB), resolv.conf(5), attributes(7),
domainname(8)
Lottor, M. RFC 1033, Domain Administrators Operations Guide. Network
Working Group. November 1987. https://tools.ietf.org/html/rfc1033
Mockapetris, Paul. RFC 1034, Domain Names - Concepts and Facilities.
Network Working Group. November 1987.
https://tools.ietf.org/html/rfc1034
Mockapetris, Paul. RFC 1035, Domain Names - Implementation and Specifi‐
cation. Network Working Group. November 1987.
https://tools.ietf.org/html/rfc1035
Partridge, Craig. RFC 974, Mail Routing and the Domain System. Network
Working Group. January 1986. https://tools.ietf.org/html/rfc974
Stahl, M. RFC 1032, Domain Administrators Guide. Network Working Group.
November 1987. https://tools.ietf.org/html/rfc1032
Vixie, Paul, Dunlap, Kevin J., Karels, Michael J. Name Server Opera‐
tions 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.
Oracle Solaris 11.4 11 May 2021 resolver(3RESOLV)