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.  This  option  is  available  only  if
101              glibc  was  built  with  debugging  enabled,  which  is  not the
102              default.
103
104       RES_AAONLY
105              Accept authoritative answers only.  res_send()  continues  until
106              it finds an authoritative answer or returns an error.  [Not cur‐
107              rently implemented].
108
109       RES_USEVC
110              Use TCP connections for queries rather than UDP datagrams.
111
112       RES_PRIMARY
113              Query primary domain name server only.
114
115       RES_IGNTC
116              Ignore truncation errors.  Don't retry with TCP.  [Not currently
117              implemented].
118
119       RES_RECURSE
120              Set  the recursion desired bit in queries.  Recursion is carried
121              out by the domain name server, not by res_send().   [Enabled  by
122              default].
123
124       RES_DEFNAMES
125              If set, res_search() will append the default domain name to sin‐
126              gle component names, i.e., those that  do  not  contain  a  dot.
127              [Enabled by default].
128
129       RES_STAYOPEN
130              Used  with  RES_USEVC  to  keep  the TCP connection open between
131              queries.
132
133       RES_DNSRCH
134              If set, res_search() will search for hostnames  in  the  current
135              domain and in parent domains.  This option is used by gethostby‐
136              name(3).  [Enabled by default].
137
138       This list is not complete.  You can find some other flags described  in
139       resolv.conf(5).
140

RETURN VALUE

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

FILES

152       /etc/resolv.conf          resolver configuration file
153       /etc/host.conf            resolver configuration file
154

CONFORMING TO

156       4.3BSD.
157

SEE ALSO

159       gethostbyname(3), resolv.conf(5), resolver(5), hostname(7), named(8)
160

COLOPHON

162       This page is part of release 3.53 of the Linux  man-pages  project.   A
163       description  of  the project, and information about reporting bugs, can
164       be found at http://www.kernel.org/doc/man-pages/.
165
166
167
168GNU                               2013-03-05                       RESOLVER(3)
Impressum