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

NAME

6       res_ninit,   res_nclose,   res_nquery,  res_nsearch,  res_nquerydomain,
7       res_nmkquery, res_nsend, res_init, res_query, res_search,  res_querydo‐
8       main, res_mkquery, res_send, dn_comp, dn_expand - resolver routines
9

SYNOPSIS

11       #include <netinet/in.h>
12       #include <arpa/nameser.h>
13       #include <resolv.h>
14
15       struct __res_state;
16       typedef struct __res_state *res_state;
17
18       int res_ninit(res_state statep);
19
20       void res_nclose(res_state statep);
21
22       int res_nquery(res_state statep,
23                  const char *dname, int class, int type,
24                  unsigned char *answer, int anslen);
25
26       int res_nsearch(res_state statep,
27                  const char *dname, int class, int type,
28                  unsigned char *answer, int anslen);
29
30       int res_nquerydomain(res_state statep,
31                  const char *name, const char *domain,
32                  int class, int type, unsigned char *answer,
33                  int anslen);
34
35       int res_nmkquery(res_state statep,
36                  int op, const char *dname, int class,
37                  int type, const unsigned char *data, int datalen,
38                  const unsigned char *newrr,
39                  unsigned char *buf, int buflen);
40
41       int res_nsend(res_state statep,
42                  const unsigned char *msg, int msglen,
43                  unsigned char *answer, int anslen);
44
45       int dn_comp(const char *exp_dn, unsigned char *comp_dn,
46                  int length, unsigned char **dnptrs,
47                  unsigned char **lastdnptr);
48
49       int dn_expand(const unsigned char *msg,
50                  const unsigned char *eomorig,
51                  const unsigned char *comp_dn, char *exp_dn,
52                  int length);
53
54   Deprecated
55       extern struct __res_state _res;
56
57       int res_init(void);
58
59       int res_query(const char *dname, int class, int type,
60                  unsigned char *answer, int anslen);
61
62       int res_search(const char *dname, int class, int type,
63                  unsigned char *answer, int anslen);
64
65       int res_querydomain(const char *name, const char *domain,
66                  int class, int type, unsigned char *answer,
67                  int anslen);
68
69       int res_mkquery(int op, const char *dname, int class,
70                  int type, const unsigned char *data, int datalen,
71                  const unsigned char *newrr,
72                  unsigned char *buf, int buflen);
73
74       int res_send(const unsigned char *msg, int msglen,
75                  unsigned char *answer, int anslen);
76
77       Link with -lresolv.
78

DESCRIPTION

80       Note:  This  page is incomplete (various resolver functions provided by
81       glibc are not described) and likely out of date.
82
83       The functions  described  below  make  queries  to  and  interpret  the
84       responses from Internet domain name servers.
85
86       The  API  consists  of a set of more modern, reentrant functions and an
87       older set of nonreentrant functions that  have  been  superseded.   The
88       traditional  resolver interfaces such as res_init() and res_query() use
89       some static (global) state stored  in  the  _res  structure,  rendering
90       these  functions  non-thread-safe.   BIND  8.2  introduced a set of new
91       interfaces res_ninit(), res_nquery(), and so on, which take a res_state
92       as their first argument, so you can use a per-thread resolver state.
93
94       The  res_ninit()  and res_init() functions read the configuration files
95       (see resolv.conf(5)) to get the default domain  name  and  name  server
96       address(es).   If  no  server is given, the local host is tried.  If no
97       domain is given, that associated with the local host is used.   It  can
98       be  overridden  with the environment variable LOCALDOMAIN.  res_ninit()
99       or res_init() is normally executed by the first  call  to  one  of  the
100       other  functions.   Every  call to res_ninit() requires a corresponding
101       call to res_nclose() to free memory allocated by res_ninit() and subse‐
102       quent calls to res_nquery().
103
104       The  res_nquery()  and  res_query() functions query the name server for
105       the fully qualified domain name name of specified type and class.   The
106       reply  is  left  in  the buffer answer of length anslen supplied by the
107       caller.
108
109       The res_nsearch() and res_search() functions make a query and waits for
110       the  response  like  res_nquery() and res_query(), but in addition they
111       implement the default and search rules controlled by  RES_DEFNAMES  and
112       RES_DNSRCH (see description of _res options below).
113
114       The  res_nquerydomain()  and  res_querydomain()  functions make a query
115       using res_nquery()/res_query() on the concatenation of name and domain.
116
117       The   following   functions   are   lower-level   routines   used    by
118       res_query()/res_query().
119
120       The  res_nmkquery()  and res_mkquery() functions construct a query mes‐
121       sage in buf of length buflen for the domain name dname.  The query type
122       op is one of the following (typically QUERY):
123
124       QUERY  Standard query.
125
126       IQUERY Inverse  query.  This option was removed in glibc 2.26, since it
127              has not been supported by DNS servers for a very long time.
128
129       NS_NOTIFY_OP
130              Notify secondary of SOA (Start of Authority) change.
131
132       newrr is currently unused.
133
134       The res_nsend() and res_send() function send a preformatted query given
135       in  msg  of  length msglen and returns the answer in answer which is of
136       length anslen.  They will call res_ninit()/res_init()  if  it  has  not
137       already been called.
138
139       The  dn_comp() function compresses the domain name exp_dn and stores it
140       in the buffer comp_dn of length length.  The compression uses an  array
141       of  pointers  dnptrs to previously compressed names in the current mes‐
142       sage.  The first pointer points to the beginning of the message and the
143       list ends with NULL.  The limit of the array is specified by lastdnptr.
144       If dnptr is NULL, domain names are not  compressed.   If  lastdnptr  is
145       NULL, the list of labels is not updated.
146
147       The  dn_expand() function expands the compressed domain name comp_dn to
148       a full domain name, which is  placed  in  the  buffer  exp_dn  of  size
149       length.   The compressed name is contained in a query or reply message,
150       and msg points to the beginning of the message.
151
152       The resolver routines use configuration and state information contained
153       in a __res_state structure (either passed as the statep argument, or in
154       the global variable _res, in the case of the older  nonreentrant  func‐
155       tions).   The only field of this structure that is normally manipulated
156       by the user is the options field.  This field can contain  the  bitwise
157       "OR" of the following options:
158
159       RES_INIT
160              True if res_ninit() or res_init() has been called.
161
162       RES_DEBUG
163              Print  debugging  messages.   This  option  is available only if
164              glibc was  built  with  debugging  enabled,  which  is  not  the
165              default.
166
167       RES_AAONLY (unimplemented; deprecated in glibc 2.25)
168              Accept  authoritative  answers only.  res_send() continues until
169              it finds an authoritative answer  or  returns  an  error.   This
170              option  was  present  but  unimplemented  in glibc until version
171              2.24; since glibc 2.25, it is deprecated, and its usage produces
172              a warning.
173
174       RES_USEVC
175              Use TCP connections for queries rather than UDP datagrams.
176
177       RES_PRIMARY (unimplemented; deprecated in glibc 2.25)
178              Query  primary domain name server only.  This option was present
179              but unimplemented in glibc until version 2.24; since glibc 2.25,
180              it is deprecated, and its usage produces a warning.
181
182       RES_IGNTC
183              Ignore truncation errors.  Don't retry with TCP.
184
185       RES_RECURSE
186              Set  the recursion desired bit in queries.  Recursion is carried
187              out by the domain name server, not by res_send().   [Enabled  by
188              default].
189
190       RES_DEFNAMES
191              If set, res_search() will append the default domain name to sin‐
192              gle component names—that is, those that do not  contain  a  dot.
193              [Enabled by default].
194
195       RES_STAYOPEN
196              Used  with  RES_USEVC  to  keep  the TCP connection open between
197              queries.
198
199       RES_DNSRCH
200              If set, res_search() will search for hostnames  in  the  current
201              domain and in parent domains.  This option is used by gethostby‐
202              name(3).  [Enabled by default].
203
204       RES_INSECURE1
205              Accept a response from a wrong server.   This  can  be  used  to
206              detect potential security hazards, but you need to compile glibc
207              with debugging enabled and use RES_DEBUG option (for debug  pur‐
208              pose only).
209
210       RES_INSECURE2
211              Accept  a  response  which  contains a wrong query.  This can be
212              used to detect potential security hazards, but you need to  com‐
213              pile  glibc with debugging enabled and use RES_DEBUG option (for
214              debug purpose only).
215
216       RES_NOALIASES
217              Disable usage of HOSTALIASES environment variable.
218
219       RES_USE_INET6
220              Try an AAAA query before an A query inside the  gethostbyname(3)
221              function,  and  map IPv4 responses in IPv6 "tunneled form" if no
222              AAAA records are found but an A record set exists.  Since  glibc
223              2.25,  this option is deprecated, and its usage produces a warn‐
224              ing; applications should use getaddrinfo(3), rather  than  geth‐
225              ostbyname(3).
226
227       RES_ROTATE
228              Causes  round-robin  selection  of name servers from among those
229              listed.  This has the effect of spreading the query  load  among
230              all listed servers, rather than having all clients try the first
231              listed server first every time.
232
233       RES_NOCHECKNAME (unimplemented; deprecated in glibc 2.25)
234              Disable the modern BIND checking of incoming hostnames and  mail
235              names  for invalid characters such as underscore (_), non-ASCII,
236              or control characters.  This option was present in  glibc  until
237              version  2.24; since glibc 2.25, it is deprecated, and its usage
238              produces a warning.
239
240       RES_KEEPTSIG (unimplemented; deprecated in glibc 2.25)
241              Do not strip TSIG records.  This option was present but unimple‐
242              mented in glibc until version 2.24; since glibc 2.25, it is dep‐
243              recated, and its usage produces a warning.
244
245       RES_BLAST (unimplemented; deprecated in glibc 2.25)
246              Send each query simultaneously and recursively to  all  servers.
247              This option was present but unimplemented in glibc until version
248              2.24; since glibc 2.25, it is deprecated, and its usage produces
249              a warning.
250
251       RES_USEBSTRING (glibc 2.3.4 to 2.24)
252              Make  reverse  IPv6 lookups using the bit-label format described
253              in RFC 2673; if this option is not set (which is  the  default),
254              then  nibble  format  is used.  This option was removed in glibc
255              2.25, since it relied on a backward-incompatible  DNS  extension
256              that was never deployed on the Internet.
257
258       RES_NOIP6DOTINT (glibc 2.24 and earlier)
259              Use  ip6.arpa  zone  in  IPv6 reverse lookup instead of ip6.int,
260              which is deprecated since glibc 2.3.4.  This option  is  present
261              in  glibc  up to and including version 2.24, where it is enabled
262              by default.  In glibc 2.25, this option was removed.
263
264       RES_USE_EDNS0 (since glibc 2.6)
265              Enables support for the DNS extensions (EDNS0) described in  RFC
266              2671.
267
268       RES_SNGLKUP (since glibc 2.10)
269              By  default,  glibc  performs  IPv4 and IPv6 lookups in parallel
270              since version 2.9.  Some appliance  DNS  servers  cannot  handle
271              these  queries  properly  and  make the requests time out.  This
272              option disables the behavior and makes glibc  perform  the  IPv6
273              and  IPv4 requests sequentially (at the cost of some slowdown of
274              the resolving process).
275
276       RES_SNGLKUPREOP
277              When RES_SNGLKUP option is enabled, opens a new socket  for  the
278              each request.
279
280       RES_USE_DNSSEC
281              Use  DNSSEC  with  OK  bit  in  OPT record.  This option implies
282              RES_USE_EDNS0.
283
284       RES_NOTLDQUERY
285              Do not look up unqualified name as a top-level domain (TLD).
286
287       RES_DEFAULT
288              Default  option  which   implies:   RES_RECURSE,   RES_DEFNAMES,
289              RES_DNSRCH and RES_NOIP6DOTINT.
290

RETURN VALUE

292       The  res_ninit() and res_init() functions return 0 on success, or -1 if
293       an error occurs.
294
295       The res_nquery(), res_query(), res_nsearch(), res_search(), res_nquery‐
296       domain(),     res_querydomain(),     res_nmkquery(),     res_mkquery(),
297       res_nsend(),  and  res_send()  functions  return  the  length  of   the
298       response, or -1 if an error occurs.
299
300       The  dn_comp()  and dn_expand() functions return the length of the com‐
301       pressed name, or -1 if an error occurs.
302
303       In  the  case  of  an  error  return  from  res_nquery(),  res_query(),
304       res_nsearch(),  res_search(), res_nquerydomain(), or res_querydomain(),
305       the global variable h_errno (see gethostbyname(3)) can be consulted  to
306       determine the cause of the error.
307

FILES

309       /etc/resolv.conf
310              resolver configuration file
311
312       /etc/host.conf
313              resolver configuration file
314

ATTRIBUTES

316       For   an   explanation   of   the  terms  used  in  this  section,  see
317       attributes(7).
318
319       ┌───────────────────────────────────┬───────────────┬────────────────┐
320Interface                          Attribute     Value          
321       ├───────────────────────────────────┼───────────────┼────────────────┤
322res_ninit(),         res_nclose(), │ Thread safety │ MT-Safe locale │
323res_nquery(),                      │               │                │
324res_nsearch(), res_nquerydomain(), │               │                │
325res_nsend()                        │               │                │
326       ├───────────────────────────────────┼───────────────┼────────────────┤
327res_nmkquery(), dn_comp(),         │ Thread safety │ MT-Safe        │
328dn_expand()                        │               │                │
329       └───────────────────────────────────┴───────────────┴────────────────┘
330

CONFORMING TO

332       4.3BSD.
333

SEE ALSO

335       gethostbyname(3), resolv.conf(5), resolver(5), hostname(7), named(8)
336
337       The GNU C library source file resolv/README.
338

COLOPHON

340       This page is part of release 5.07 of the Linux  man-pages  project.   A
341       description  of  the project, information about reporting bugs, and the
342       latest    version    of    this    page,    can     be     found     at
343       https://www.kernel.org/doc/man-pages/.
344
345
346
347GNU                               2019-03-06                       RESOLVER(3)
Impressum