1RESOLVER(3)                Linux Programmer's Manual               RESOLVER(3)
2
3
4

NAME

6       res_init,    res_query,   res_search,   res_querydomain,   res_mkquery,
7       res_send, dn_comp, dn_expand - resolver routines
8

SYNOPSIS

10       #include <netinet/in.h>
11       #include <arpa/nameser.h>
12       #include <resolv.h>
13       extern struct state _res;
14
15       int res_init(void);
16
17       int res_query(const char *dname, int class, int type,
18              unsigned char *answer, int anslen);
19
20       int res_search(const char *dname, int class, int type,
21              unsigned char *answer, int anslen);
22
23       int res_querydomain(const char *name, const char *domain,
24              int class, int type, unsigned char *answer,
25              int anslen);
26
27       int res_mkquery(int op, const char *dname, int class,
28              int type, char *data, int datalen, struct rrec *newrr,
29              char *buf, int buflen);
30
31       int res_send(const char *msg, int msglen, char *answer,
32              int anslen);
33
34       int dn_comp(unsigned char *exp_dn, unsigned char *comp_dn,
35              int length, unsigned char **dnptrs, unsigned char **lastdnptr);
36
37       int dn_expand(unsigned char *msg, unsigned char *eomorig,
38              unsigned char *comp_dn, char *exp_dn,
39              int length);
40
41       Link with -lresolv.
42

DESCRIPTION

44       These functions make queries to and interpret the responses from Inter‐
45       net domain name servers.
46
47       The   res_init()   function   reads   the   configuration   files  (see
48       resolv.conf(5)) to get the default domain name, search order  and  name
49       server  address(es).   If  no server is given, the local host is tried.
50       If no domain is given, that associated with the local host is used.  It
51       can   be   overridden   with   the  environment  variable  LOCALDOMAIN.
52       res_init() is normally executed by the first call to one of  the  other
53       functions.
54
55       The  res_query()  function queries the name server for the fully quali‐
56       fied domain name name of specified type and class.  The reply  is  left
57       in the buffer answer of length anslen supplied by the caller.
58
59       The res_search() function makes a query and waits for the response like
60       res_query(), but in addition implements the default  and  search  rules
61       controlled  by  RES_DEFNAMES  and  RES_DNSRCH  (see description of _res
62       options below).
63
64       The res_querydomain() function makes a query using res_query()  on  the
65       concatenation of name and domain.
66
67       The following functions are lower-level routines used by res_query().
68
69       The  res_mkquery() function constructs a query message in buf of length
70       buflen for the domain name dname.  The query type op is usually  QUERY,
71       but can be any of the types defined in <arpa/nameser.h>.  newrr is cur‐
72       rently unused.
73
74       The res_send() function sends a preformatted  query  given  in  msg  of
75       length  msglen  and  returns  the  answer  in answer which is of length
76       anslen.  It will call res_init(), if it has not already been called.
77
78       The dn_comp() function compresses the domain name exp_dn and stores  it
79       in  the buffer comp_dn of length length.  The compression uses an array
80       of pointers dnptrs to previously compressed names in the  current  mes‐
81       sage.  The first pointer points to the beginning of the message and the
82       list ends with NULL.  The limit of the array is specified by lastdnptr.
83       If  dnptr  is  NULL,  domain names are not compressed.  If lastdnptr is
84       NULL, the list of labels is not updated.
85
86       The dn_expand() function expands the compressed domain name comp_dn  to
87       a  full  domain  name,  which  is  placed  in the buffer exp_dn of size
88       length.  The compressed name is contained in a query or reply  message,
89       and msg points to the beginning of the message.
90
91       The  resolver  routines  use global configuration and state information
92       contained in the structure _res, which is defined in  <resolv.h>.   The
93       only  field  that  is normally manipulated by the user is _res.options.
94       This field can contain the bitwise "OR" of the following options:
95
96       RES_INIT
97              True if res_init() has been called.
98
99       RES_DEBUG
100              Print debugging messages.
101
102       RES_AAONLY
103              Accept authoritative answers only.  res_send()  continues  until
104              it finds an authoritative answer or returns an error.  [Not cur‐
105              rently implemented].
106
107       RES_USEVC
108              Use TCP connections for queries rather than UDP datagrams.
109
110       RES_PRIMARY
111              Query primary domain name server only.
112
113       RES_IGNTC
114              Ignore truncation errors.  Don't retry with TCP.  [Not currently
115              implemented].
116
117       RES_RECURSE
118              Set  the recursion desired bit in queries.  Recursion is carried
119              out by the domain name server, not by res_send().   [Enabled  by
120              default].
121
122       RES_DEFNAMES
123              If set, res_search() will append the default domain name to sin‐
124              gle component names, i.e., those that  do  not  contain  a  dot.
125              [Enabled by default].
126
127       RES_STAYOPEN
128              Used  with  RES_USEVC  to  keep  the TCP connection open between
129              queries.
130
131       RES_DNSRCH
132              If set, res_search() will search for hostnames  in  the  current
133              domain and in parent domains.  This option is used by gethostby‐
134              name(3).  [Enabled by default].
135

RETURN VALUE

137       The res_init() function returns 0 on success, or -1 if an error occurs.
138
139       The res_query(),  res_search(),  res_querydomain(),  res_mkquery()  and
140       res_send()  functions  return  the  length of the response, or -1 if an
141       error occurs.
142
143       The dn_comp() and dn_expand() functions return the length of  the  com‐
144       pressed name, or -1 if an error occurs.
145

FILES

147       /etc/resolv.conf          resolver configuration file
148       /etc/host.conf            resolver configuration file
149

CONFORMING TO

151       4.3BSD.
152

SEE ALSO

154       gethostbyname(3), resolv.conf(5), resolver(5), hostname(7), named(8)
155

COLOPHON

157       This  page  is  part of release 3.25 of the Linux man-pages project.  A
158       description of the project, and information about reporting  bugs,  can
159       be found at http://www.kernel.org/doc/man-pages/.
160
161
162
163GNU                               2010-06-17                       RESOLVER(3)
Impressum