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, unsigned 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
98       RES_INIT
99              True if res_init() has been called.
100
101       RES_DEBUG
102              Print debugging messages.
103
104       RES_AAONLY
105              Accept authoritative answers only.  res_send()  continues  until
106              it  fins 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, ie.  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 host names in  the  current
135              domain and in parent domains.  This option is used by gethostby‐
136              name(3).  [Enabled by default].
137

RETURN VALUE

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

FILES

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

CONFORMING TO

153       4.3BSD
154

SEE ALSO

156       gethostbyname(3), resolver(5), hostname(7), resolv.conf(5), named(8)
157
158
159
160BSD                               2004-10-31                       RESOLVER(3)
Impressum