1RESOLVER(3)              BSD Library Functions Manual              RESOLVER(3)
2

NAME

4     res_ninit, res_ourserver_p, fp_resstat, res_hostalias, res_pquery,
5     res_nquery, res_nsearch, res_nquerydomain, res_nmkquery, res_nsend,
6     res_nupdate, res_nmkupdate, res_nclose, res_nsendsigned, res_findzonecut,
7     res_getservers, res_setservers, dn_comp, dn_expand, hstrerror, res_init,
8     res_isourserver, fp_nquery, p_query, hostalias, res_query, res_search,
9     res_querydomain, res_mkquery, res_send, res_update, res_close, herror 
10     resolver routines
11

SYNOPSIS

13     #include <sys/types.h>
14     #include <netinet/in.h>
15     #include <arpa/nameser.h>
16     #include <resolv.h>
17     #include <res_update.h>
18
19     typedef struct __res_state *res_state;
20
21     int
22     res_ninit(res_state statp);
23
24     int
25     res_ourserver_p(const res_state statp, const struct sockaddr_in *addr);
26
27     void
28     fp_resstat(const res_state statp, FILE *fp);
29
30     const char *
31     res_hostalias(const res_state statp, const char *name, char *buf,
32         size_t buflen);
33
34     int
35     res_pquery(const res_state statp, const u_char *msg, int msglen,
36         FILE *fp);
37
38     int
39     res_nquery(res_state statp, const char *dname, int class, int type,
40         u_char *answer, int anslen);
41
42     int
43     res_nsearch(res_state statp, const char *dname, int class, int type,
44         u_char * answer, int anslen);
45
46     int
47     res_nquerydomain(res_state statp, const char *name, const char *domain,
48         int class, int type, u_char *answer, int anslen);
49
50     int
51     res_nmkquery(res_state statp, int op, const char *dname, int class,
52         int type, const u_char *data, int datalen, const u_char *newrr,
53         u_char *buf, int buflen);
54
55     int
56     res_nsend(res_state statp, const u_char *msg, int msglen, u_char *answer,
57         int anslen);
58
59     int
60     res_nupdate(res_state statp, ns_updrec *rrecp_in);
61
62     int
63     res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf,
64         int buflen);
65
66     void
67     res_nclose(res_state statp);
68
69     int
70     res_nsendsigned(res_state statp, const u_char *msg, int msglen,
71         ns_tsig_key *key, u_char *answer, int anslen);
72
73     int
74     res_findzonecut(res_state statp, const char *dname, ns_class class,
75         int options, char *zname, size_t zsize, struct in_addr *addrs,
76         int naddrs);
77
78     int
79     res_getservers(res_state statp, union res_sockaddr_union *set, int cnt);
80
81     void
82     res_setservers(res_state statp, const union res_sockaddr_union *set,
83         int cnt);
84
85     int
86     dn_comp(const char *exp_dn, u_char *comp_dn, int length, u_char **dnptrs,
87         u_char **lastdnptr);
88
89     int
90     dn_expand(const u_char *msg, const u_char *eomorig,
91         const u_char *comp_dn, char *exp_dn, int length);
92
93     const char *
94     hstrerror(int err);
95
96   DEPRECATED
97     #include <sys/types.h>
98     #include <netinet/in.h>
99     #include <arpa/nameser.h>
100     #include <resolv.h>
101     #include <res_update.h>
102
103     int
104     res_init(void);
105
106     int
107     res_isourserver(const struct sockaddr_in *addr);
108
109     int
110     fp_nquery(const u_char *msg, int msglen, FILE *fp);
111
112     void
113     p_query(const u_char *msg, FILE *fp);
114
115     const char *
116     hostalias(const char *name);
117
118     int
119     res_query(const char *dname, int class, int type, u_char *answer,
120         int anslen);
121
122     int
123     res_search(const char *dname, int class, int type, u_char *answer,
124         int anslen);
125
126     int
127     res_querydomain(const char *name, const char *domain, int class,
128         int type, u_char *answer, int anslen);
129
130     int
131     res_mkquery(int op, const char *dname, int class, int type,
132         const char *data, int datalen, struct rrec *newrr, u_char *buf,
133         int buflen);
134
135     int
136     res_send(const u_char *msg, int msglen, u_char *answer, int anslen);
137
138     int
139     res_update(ns_updrec *rrecp_in);
140
141     void
142     res_close(void);
143
144     void
145     herror(const char *s);
146

DESCRIPTION

148     These routines are used for making, sending and interpreting query and
149     reply messages with Internet domain name servers.
150
151     State information is kept in statp and is used to control the behavior of
152     these functions.  statp should be set to all zeros prior to the first
153     call to any of these functions.
154
155     The functions res_init(), res_isourserver(), fp_nquery(), p_query(),
156     hostalias(), res_query(), res_search(), res_querydomain(), res_mkquery(),
157     res_send(), res_update(), res_close() and herror() are deprecated and are
158     supplied for compatability with old source code.  They use global config‐
159     uration and state information that is kept in the structure _res rather
160     than that referenced through statp.
161
162     Most of the values in statp and _res are initialized on the first call to
163     res_ninit() / res_init() to reasonable defaults and can be ignored.
164     Options stored in statp->options / _res.options are defined in resolv.h
165     and are as follows.  Options are stored as a simple bit mask containing
166     the bitwise “OR” of the options enabled.
167
168     RES_INIT
169              True if the initial name server address and default domain name
170              are initialized (i.e., res_ninit() / res_init() has been
171              called).
172
173     RES_DEBUG
174              Print debugging messages.
175
176     RES_AAONLY
177              Accept authoritative answers only.  Should continue until it
178              finds an authoritative answer or finds an error.  Currently this
179              is not implemented.
180
181     RES_USEVC
182              Use TCP connections for queries instead of UDP datagrams.
183
184     RES_STAYOPEN
185              Used with RES_USEVC to keep the TCP connection open between
186              queries.  This is useful only in programs that regularly do many
187              queries.  UDP should be the normal mode used.
188
189     RES_IGNTC
190              Ignore truncation errors, i.e., don't retry with TCP.
191
192     RES_RECURSE
193              Set the recursion-desired bit in queries.  This is the default.
194              (res_nsend() / res_send() does not do iterative queries and
195              expects the name server to handle recursion.)
196
197     RES_DEFNAMES
198              If set, res_nsearch() / res_search() will append the default
199              domain name to single-component names (those that do not contain
200              a dot).  This option is enabled by default.
201
202     RES_DNSRCH
203              If this option is set, res_nsearch() / res_search() will search
204              for host names in the current domain and in parent domains; see
205              hostname(7).  This is used by the standard host lookup routine
206              gethostbyname(3).  This option is enabled by default.
207
208     RES_NOALIASES
209              This option turns off the user level aliasing feature controlled
210              by the HOSTALIASES environment variable.  Network daemons should
211              set this option.
212
213     RES_USE_INET6
214              This option causes gethostbyname(3) to look for AAAA records
215              before looking for A records if none are found.
216
217     RES_ROTATE
218              This options causes the res_nsend() / res_send() to rotate the
219              list of nameservers in statp->nsaddr_list / _res.nsaddr_list.
220
221     RES_KEEPTSIG
222              This option causes res_nsendsigned() to leave the message
223              unchanged after TSIG verification; otherwise the TSIG record
224              would be removed and the header updated.
225
226     RES_NOTLDQUERY
227              This option causes res_nsearch() to not attempt to resolve a
228              unqualified name as if it were a top level domain (TLD).  This
229              option can cause problems if the site has "localhost" as a TLD
230              rather than having localhost on one or more elements of the
231              search list.  This option has no effect if neither RES_DEFNAMES
232              or RES_DNSRCH is set.
233
234     The res_ninit() / res_init() routine reads the configuration file (if
235     any; see resolver(5)) to get the default domain name, search list and the
236     Internet address of the local name server(s).  If no server is config‐
237     ured, the host running the resolver is tried.  The current domain name is
238     defined by the hostname if not specified in the configuration file; it
239     can be overridden by the environment variable LOCALDOMAIN.  This environ‐
240     ment variable may contain several blank-separated tokens if you wish to
241     override the “search list” on a per-process basis.  This is similar to
242     the search command in the configuration file.  Another environment vari‐
243     able (“RES_OPTIONS”) can be set to override certain internal resolver
244     options which are otherwise set by changing fields in the statp / _res
245     structure or are inherited from the configuration file's options command.
246     The syntax of the “RES_OPTIONS” environment variable is explained in
247     resolver(5).  Initialization normally occurs on the first call to one of
248     the other resolver routines.
249
250     The res_nquery() / res_query() functions provides interfaces to the
251     server query mechanism.  They constructs a query, sends it to the local
252     server, awaits a response, and makes preliminary checks on the reply.
253     The query requests information of the specified type and class for the
254     specified fully-qualified domain name dname.  The reply message is left
255     in the answer buffer with length anslen supplied by the caller.
256     res_nquery() / res_query() return -1 on error or the length of the
257     answer.
258
259     The res_nsearch() / res_search() routines make a query and awaits a
260     response like res_nquery() / res_query(), but in addition, it implements
261     the default and search rules controlled by the RES_DEFNAMES and
262     RES_DNSRCH options.  It returns the length of the first successful reply
263     which is stored in answer or -1 on error.
264
265     The remaining routines are lower-level routines used by res_nquery() /
266     res_query().  The res_nmkquery() / res_mkquery() functions constructs a
267     standard query message and places it in buf.  It returns the size of the
268     query, or -1 if the query is larger than buflen.  The query type op is
269     usually QUERY, but can be any of the query types defined in
270     <arpa/nameser.h>.  The domain name for the query is given by dname.
271     Newrr is currently unused but is intended for making update messages.
272
273     The res_nsend() / res_send() / res_nsendsigned() routines sends a pre-
274     formatted query and returns an answer.  It will call res_ninit() /
275     res_init() if RES_INIT is not set, send the query to the local name
276     server, and handle timeouts and retries.  Additionally, res_nsendsigned()
277     will use TSIG signatures to add authentication to the query and verify
278     the response.  In this case, only one nameserver will be contacted.  The
279     length of the reply message is returned, or -1 if there were errors.
280
281     res_nquery() / res_query(), res_nsearch() / res_search() and res_nsend()
282     / res_send() return a length that may be bigger than anslen.  In that
283     case the query should be retried with a bigger buffer.  NOTE the answer
284     to the second query may be larger still so supplying a buffer that bigger
285     that the answer returned by the previous query is recommended.
286
287     answer MUST be big enough to receive a maximum UDP response from the
288     server or parts of the answer will be silently discarded.  The default
289     maximum UDP response size is 512 bytes.
290
291     The function res_ourserver_p() returns true when inp is one of the
292     servers in statp->nsaddr_list / _res.nsaddr_list.
293
294     The functions fp_nquery() / p_query() print out the query and any answer
295     in msg on fp.  p_query() is equivalent to fp_nquery() with msglen set to
296     512.
297
298     The function fp_resstat() prints out the active flag bits in
299     statp->options preceeded by the text ";; res options:" on file.
300
301     The functions res_hostalias() / hostalias() lookup up name in the file
302     referred to by the HOSTALIASES files return a fully qualified hostname if
303     found or NULL if not found or an error occurred.  res_hostalias() uses
304     buf to store the result in, hostalias() uses a static buffer.
305
306     The functions res_getservers() and res_setservers() are used to get and
307     set the list of server to be queried.
308
309     The functions res_nupdate() / res_update() take a list of ns_updrec
310     rrecp_in.  Identifies the containing zone for each record and groups the
311     records according to containing zone maintaining in zone order then sends
312     and update request to the servers for these zones.  The number of zones
313     updated is returned or -1 on error.  Note that res_nupdate() will perform
314     TSIG authenticated dynamic update operations if the key is not NULL.
315
316     The function res_findzonecut() discovers the closest enclosing zone cut
317     for a specified domain name, and finds the IP addresses of the zone's
318     master servers.
319
320     The functions res_nmkupdate() / res_mkupdate() take a linked list of
321     ns_updrec rrecp_in and construct a UPDATE message in buf.
322     res_nmkupdate() / res_mkupdate() return the length of the constructed
323     message on no error or one of the following error values.
324
325     -1 An error occurred parsing rrecp_in.
326
327     -2 The buffer buf was too small.
328
329     -3 The first record was not a zone section or there was a section order
330     problem.  The section order is S_ZONE, S_PREREQ and S_UPDATE.
331
332     -4 A number overflow occurred.
333
334     -5 Unknown operation or no records.
335
336     The functions res_nclose() / res_close() close any open files referenced
337     through statp / _res.
338
339     The dn_comp() function compresses the domain name exp_dn and stores it in
340     comp_dn.  The size of the compressed name is returned or -1 if there were
341     errors.  The size of the array pointed to by comp_dn is given by length.
342     The compression uses an array of pointers dnptrs to previously-compressed
343     names in the current message.  The first pointer points to to the begin‐
344     ning of the message and the list ends with NULL.  The limit to the array
345     is specified by lastdnptr.  A side effect of dn_comp() is to update the
346     list of pointers for labels inserted into the message as the name is com‐
347     pressed.  If dnptr is NULL, names are not compressed.  If lastdnptr is
348     NULL, the list of labels is not updated.
349
350     The dn_expand() entry expands the compressed domain name comp_dn to a
351     full domain name.  The compressed name is contained in a query or reply
352     message; msg is a pointer to the beginning of the message.  eomorig is a
353     pointer to the first location after the message.  The uncompressed name
354     is placed in the buffer indicated by exp_dn which is of size length.  The
355     size of compressed name is returned or -1 if there was an error.
356
357     The variables statp->res_h_errno / _res.res_h_errno and external variable
358     h_errno is set whenever an error occurs during resolver operation.  The
359     following definitions are given in <netdb.h>:
360
361     #define NETDB_INTERNAL -1  /* see errno */
362     #define NETDB_SUCCESS  0   /* no problem */
363     #define HOST_NOT_FOUND 1   /* Authoritative Answer Host not found */
364     #define TRY_AGAIN      2   /* Non-Authoritative not found, or SERVFAIL */
365     #define NO_RECOVERY    3   /* Non-Recoverable: FORMERR, REFUSED, NOTIMP */
366     #define NO_DATA        4   /* Valid name, no data for requested type */
367
368     The herror() function writes a message to the diagnostic output consist‐
369     ing of the string parameter s, the constant string ": ", and a message
370     corresponding to the value of h_errno.
371
372     The hstrerror() function returns a string which is the message text cor‐
373     responding to the value of the err parameter.
374

FILES

376     /etc/resolv.conf      See resolver(5).
377

SEE ALSO

379     gethostbyname(3), hostname(7), named(8), resolver(5); RFC1032, RFC1033,
380     RFC1034, RFC1035, RFC974; SMM:11, “Name Server Operations Guide for BIND”
381
3824th Berkeley Distribution        July 4, 2000        4th Berkeley Distribution
Impressum