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 *exp_dn,
36              unsigned char **lastdnptr);
37
38       int dn_expand(unsigned char *msg, unsigned char *eomorig,
39              unsigned char *comp_dn, char *exp_dn,
40              int length);
41
42       Link with -lresolv.
43

DESCRIPTION

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

RETURN VALUE

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

FILES

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

CONFORMING TO

152       4.3BSD.
153

SEE ALSO

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

COLOPHON

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