1inet_res(3)                Erlang Module Definition                inet_res(3)
2
3
4

NAME

6       inet_res - A rudimentary DNS client.
7

DESCRIPTION

9       This module performs DNS name resolving to recursive name servers.
10
11       See  also  ERTS  User's  Guide: Inet Configuration for more information
12       about how to configure an Erlang runtime system for  IP  communication,
13       and how to enable this DNS client by defining 'dns' as a lookup method.
14       The DNS client then acts as a backend for the  resolving  functions  in
15       inet.
16
17       This DNS client can resolve DNS records even if it is not used for nor‐
18       mal name resolving in the node.
19
20       This is not a full-fledged resolver, only a DNS client that  relies  on
21       asking trusted recursive name servers.
22

NAME RESOLVING

24       UDP queries are used unless resolver option usevc is true, which forces
25       TCP queries. If the query is too large for UDP, TCP  is  used  instead.
26       For regular DNS queries, 512 bytes is the size limit.
27
28       When  EDNS  is enabled (resolver option edns is set to the EDNS version
29       (that is, 0 instead of false), resolver  option  udp_payload_size  sets
30       the  limit.  If a name server replies with the TC bit set (truncation),
31       indicating that the answer is incomplete, the query is retried to  that
32       name  server  using TCP. Resolver option udp_payload_size also sets the
33       advertised size for the maximum allowed reply size, if EDNS is enabled,
34       otherwise  the  name  server  uses the limit 512 bytes. If the reply is
35       larger, it gets truncated, forcing a TCP requery.
36
37       For UDP queries, resolver options timeout and retry control retransmis‐
38       sion. Each name server in the nameservers list is tried with a time-out
39       of timeout/retry. Then all name servers are tried again,  doubling  the
40       time-out, for a total of retry times.
41
42       But  before  all name servers are tried again, there is a (user config‐
43       urable) timeout, servfail_retry_timeout. The point of this is  to  pre‐
44       vent the new query to be handled by a server's servfail cache (a client
45       that is to eager will actually only get what is in the servfail cache).
46       If there is too little time left of the resolver call's timeout to do a
47       retry, the resolver call may return before the call's timeout  has  ex‐
48       pired.
49
50       For  queries not using the search list, if the query to all nameservers
51       results in {error,nxdomain} or an empty answer, the same query is tried
52       for alt_nameservers.
53

RESOLVER TYPES

55       The following data types concern the resolver:
56

DATA TYPES

58       res_option() =
59           {alt_nameservers, [nameserver()]} |
60           {edns, 0 | false} |
61           {inet6, boolean()} |
62           {nameservers, [nameserver()]} |
63           {recurse, boolean()} |
64           {retry, integer()} |
65           {timeout, integer()} |
66           {udp_payload_size, integer()} |
67           {usevc, boolean()} |
68           {nxdomain_reply, boolean()}
69
70       nameserver() = {inet:ip_address(), Port :: 1..65535}
71
72       res_error() =
73           formerr | qfmterror | servfail | nxdomain | notimp | refused |
74           badvers | timeout
75

DNS TYPES

77       The following data types concern the DNS client:
78

DATA TYPES

80       dns_name() = string()
81
82              A string with no adjacent dots.
83
84       rr_type() =
85           a | aaaa | caa | cname | gid | hinfo | ns | mb | md | mg |
86           mf | minfo | mx | naptr | null | ptr | soa | spf | srv | txt |
87           uid | uinfo | unspec | uri | wks
88
89       dns_class() = in | chaos | hs | any
90
91       dns_msg() = term()
92
93              This  is  the start of a hiearchy of opaque data structures that
94              can be examined with access functions in inet_dns, which  return
95              lists of {Field,Value} tuples. The arity 2 functions only return
96              the value for a specified field.
97
98              dns_msg() = DnsMsg
99                  inet_dns:msg(DnsMsg) ->
100                      [ {header, dns_header()}
101                      | {qdlist, dns_query()}
102                      | {anlist, dns_rr()}
103                      | {nslist, dns_rr()}
104                      | {arlist, dns_rr()} ]
105                  inet_dns:msg(DnsMsg, header) -> dns_header() % for example
106                  inet_dns:msg(DnsMsg, Field) -> Value
107
108              dns_header() = DnsHeader
109                  inet_dns:header(DnsHeader) ->
110                      [ {id, integer()}
111                      | {qr, boolean()}
112                      | {opcode, query | iquery | status | integer()}
113                      | {aa, boolean()}
114                      | {tc, boolean()}
115                      | {rd, boolean()}
116                      | {ra, boolean()}
117                      | {pr, boolean()}
118                      | {rcode, integer(0..16)} ]
119                  inet_dns:header(DnsHeader, Field) -> Value
120
121              query_type() = axfr | mailb | maila | any | rr_type()
122
123              dns_query() = DnsQuery
124                  inet_dns:dns_query(DnsQuery) ->
125                      [ {domain, dns_name()}
126                      | {type, query_type()}
127                      | {class, dns_class()} ]
128                  inet_dns:dns_query(DnsQuery, Field) -> Value
129
130              dns_rr() = DnsRr
131                  inet_dns:rr(DnsRr) -> DnsRrFields | DnsRrOptFields
132                  DnsRrFields = [ {domain, dns_name()}
133                                | {type, rr_type()}
134                                | {class, dns_class()}
135                                | {ttl, integer()}
136                                | {data, dns_data()} ]
137                  DnsRrOptFields = [ {domain, dns_name()}
138                                   | {type, opt}
139                                   | {udp_payload_size, integer()}
140                                   | {ext_rcode, integer()}
141                                   | {version, integer()}
142                                   | {z, integer()}
143                                   | {data, dns_data()} ]
144                  inet_dns:rr(DnsRr, Field) -> Value
145
146              There is an information function for the types above:
147
148              inet_dns:record_type(dns_msg()) -> msg;
149              inet_dns:record_type(dns_header()) -> header;
150              inet_dns:record_type(dns_query()) -> dns_query;
151              inet_dns:record_type(dns_rr()) -> rr;
152              inet_dns:record_type(_) -> undefined.
153
154              So, inet_dns:(inet_dns:record_type(X))(X) converts any of  these
155              data structures into a {Field,Value} list.
156
157       dns_data() =
158           dns_name() |
159           inet:ip4_address() |
160           inet:ip6_address() |
161           {MName :: dns_name(),
162            RName :: dns_name(),
163            Serial :: integer(),
164            Refresh :: integer(),
165            Retry :: integer(),
166            Expiry :: integer(),
167            Minimum :: integer()} |
168           {inet:ip4_address(), Proto :: integer(), BitMap :: binary()} |
169           {CpuString :: string(), OsString :: string()} |
170           {RM :: dns_name(), EM :: dns_name()} |
171           {Prio :: integer(), dns_name()} |
172           {Prio :: integer(),
173            Weight :: integer(),
174            Port :: integer(),
175            dns_name()} |
176           {Order :: integer(),
177            Preference :: integer(),
178            Flags :: string(),
179            Services :: string(),
180            Regexp :: string(),
181            dns_name()} |
182           [string()] |
183           binary()
184
185              Regexp  is  a string with characters encoded in the UTF-8 coding
186              standard.
187

EXPORTS

189       getbyname(Name, Type) -> {ok, Hostent} | {error, Reason}
190
191       getbyname(Name, Type, Timeout) -> {ok, Hostent} | {error, Reason}
192
193              Types:
194
195                 Name = dns_name()
196                 Type = rr_type()
197                 Timeout = timeout()
198                 Hostent = inet:hostent()
199                 Reason = inet:posix() | res_error()
200
201              Resolves a DNS record of the specified type  for  the  specified
202              host,  of class in. Returns, on success, a hostent() record with
203              dns_data() elements in the address list field.
204
205              This function uses resolver option search that is a list of  do‐
206              main  names.  If  the  name  to  resolve contains no dots, it is
207              prepended to each domain name in the search list, and  they  are
208              tried  in order. If the name contains dots, it is first tried as
209              an absolute name and if that fails, the search list is used.  If
210              the  name  has  a trailing dot, it is supposed to be an absolute
211              name and the search list is not used.
212
213       gethostbyaddr(Address) -> {ok, Hostent} | {error, Reason}
214
215       gethostbyaddr(Address, Timeout) -> {ok, Hostent} | {error, Reason}
216
217              Types:
218
219                 Address = inet:ip_address()
220                 Timeout = timeout()
221                 Hostent = inet:hostent()
222                 Reason = inet:posix() | res_error()
223
224              Backend functions used by inet:gethostbyaddr/1.
225
226       gethostbyname(Name) -> {ok, Hostent} | {error, Reason}
227
228       gethostbyname(Name, Family) -> {ok, Hostent} | {error, Reason}
229
230       gethostbyname(Name, Family, Timeout) ->
231                        {ok, Hostent} | {error, Reason}
232
233              Types:
234
235                 Name = dns_name()
236                 Hostent = inet:hostent()
237                 Timeout = timeout()
238                 Family = inet:address_family()
239                 Reason = inet:posix() | res_error()
240
241              Backend functions used by inet:gethostbyname/1,2.
242
243              This function uses  resolver  option  search  just  like  getby‐
244              name/2,3.
245
246              If resolver option inet6 is true, an IPv6 address is looked up.
247
248       lookup(Name, Class, Type) -> [dns_data()]
249
250       lookup(Name, Class, Type, Opts) -> [dns_data()]
251
252       lookup(Name, Class, Type, Opts, Timeout) -> [dns_data()]
253
254              Types:
255
256                 Name = dns_name() | inet:ip_address()
257                 Class = dns_class()
258                 Type = rr_type()
259                 Opts = [res_option() | verbose]
260                 Timeout = timeout()
261
262              Resolves  the  DNS data for the record of the specified type and
263              class for the specified name. On success, filters out the answer
264              records  with  the correct Class and Type, and returns a list of
265              their data fields. So, a lookup for type any gives an empty  an‐
266              swer,  as  the  answer  records have specific types that are not
267              any. An empty answer or a failed lookup returns an empty list.
268
269              Calls resolve/* with the same arguments and filters the  result,
270              so Opts is described for those functions.
271
272       resolve(Name, Class, Type) -> {ok, dns_msg()} | Error
273
274       resolve(Name, Class, Type, Opts) -> {ok, dns_msg()} | Error
275
276       resolve(Name, Class, Type, Opts, Timeout) ->
277                  {ok, dns_msg()} | Error
278
279              Types:
280
281                 Name = dns_name() | inet:ip_address()
282                 Class = dns_class()
283                 Type = rr_type()
284                 Opts = [Opt]
285                 Opt = res_option() | verbose | atom()
286                 Timeout = timeout()
287                 Error = {error, Reason} | {error, {Reason, dns_msg()}}
288                 Reason = inet:posix() | res_error()
289
290              Resolves  a  DNS  record of the specified type and class for the
291              specified name. The returned dns_msg() can be examined using ac‐
292              cess functions in inet_db, as described in section in DNS Types.
293
294              If Name is an ip_address(), the domain name to query for is gen‐
295              erated as the standard reverse ".IN-ADDR.ARPA." name for an IPv4
296              address,  or  the ".IP6.ARPA." name for an IPv6 address. In this
297              case, you most probably want to use Class = in and Type  =  ptr,
298              but it is not done automatically.
299
300              Opts  overrides  the  corresponding  resolver options. If option
301              nameservers is specified, it is assumed that it is the  complete
302              list  of  name  serves, so resolver option alt_nameserves is ig‐
303              nored. However, if option alt_nameserves is  also  specified  to
304              this function, it is used.
305
306              Option  verbose  (or  rather  {verbose,true}) causes diagnostics
307              printout through io:format/2  of  queries,  replies  retransmis‐
308              sions,  and  so  on,  similar to from utilities, such as dig and
309              nslookup.
310
311              Option nxdomain_reply (or rather  {nxdomain_reply,true})  causes
312              nxdomain  errors from DNS servers to be returned as {error, {nx‐
313              domain, dns_msg()}}. dns_msg() contains the additional  sections
314              that where included by the answering server. This is mainly use‐
315              ful to inspect the SOA  record  to  get  the  TTL  for  negative
316              caching.
317
318              If  Opt  is any atom, it is interpreted as {Opt,true} unless the
319              atom  string  starts  with  "no",  making   the   interpretation
320              {Opt,false}. For example, usevc is an alias for {usevc,true} and
321              nousevc is an alias for {usevc,false}.
322
323              Option inet6 has no effect on this function. You  probably  want
324              to use Type = a | aaaa instead.
325

EXAMPLE

327       This access functions example shows how lookup/3 can be implemented us‐
328       ing resolve/3 from outside the module:
329
330       example_lookup(Name, Class, Type) ->
331           case inet_res:resolve(Name, Class, Type) of
332               {ok,Msg} ->
333                   [inet_dns:rr(RR, data)
334                    || RR <- inet_dns:msg(Msg, anlist),
335                        inet_dns:rr(RR, type) =:= Type,
336                        inet_dns:rr(RR, class) =:= Class];
337               {error,_} ->
338                   []
339            end.
340

LEGACY FUNCTIONS

342       These are deprecated because the annoying double meaning  of  the  name
343       servers/time-out  argument, and because they have no decent place for a
344       resolver options list.
345

EXPORTS

347       nslookup(Name, Class, Type) -> {ok, dns_msg()} | {error, Reason}
348
349       nslookup(Name, Class, Type, Timeout) ->
350                   {ok, dns_msg()} | {error, Reason}
351
352       nslookup(Name, Class, Type, Nameservers) ->
353                   {ok, dns_msg()} | {error, Reason}
354
355              Types:
356
357                 Name = dns_name() | inet:ip_address()
358                 Class = dns_class()
359                 Type = rr_type()
360                 Timeout = timeout()
361                 Nameservers = [nameserver()]
362                 Reason = inet:posix() | res_error()
363
364              Resolves a DNS record of the specified type and  class  for  the
365              specified name.
366
367       nnslookup(Name, Class, Type, Nameservers) ->
368                    {ok, dns_msg()} | {error, Reason}
369
370       nnslookup(Name, Class, Type, Nameservers, Timeout) ->
371                    {ok, dns_msg()} | {error, Reason}
372
373              Types:
374
375                 Name = dns_name() | inet:ip_address()
376                 Class = dns_class()
377                 Type = rr_type()
378                 Timeout = timeout()
379                 Nameservers = [nameserver()]
380                 Reason = inet:posix()
381
382              Resolves  a  DNS  record of the specified type and class for the
383              specified name.
384
385
386
387Ericsson AB                      kernel 8.1.3                      inet_res(3)
Impressum