Performs DNS name resolving towards recursive name servers
See also
This DNS client can resolve DNS records even if it is not used for normal name resolving in the node.
This is not a full-fledged resolver. It is just a DNS client that relies on asking trusted recursive nameservers.
UDP queries are used unless resolver option
For UDP queries, the resolver options
For queries that not use the
As defined in the module
hostent() = #hostent{}
posix() = some atom()s
ip_address() = tuple of integers of arity 4 or 8
Resolver types:
These correspond to resolver options:
res_option() =
[ {alt_nameservers, [ nameserver() ]}
| {edns, 0 | false} % Use EDNS
| {inet6, bool()} % Return IPv6 addresses
| {nameservers, [ nameserver() ]} % List of nameservers
| {recurse, bool()} % Request server recursion
| {retry, integer()} % UDP retries
| {timeout, integer()} % UDP query timeout
| {udp_payload_size, integer()} % EDNS payload size
| {usevc, bool()} ] % Use TCP (Virtual Circuit)
nameserver() = {ip_address(),Port}
Port = integer(1..65535)
res_error() =
formerr |
qfmterror |
servfail |
nxdomain |
notimp |
refused |
badvers |
timeout
DNS types:
dns_name() = string() with no adjacent dots
rr_type() = a | aaaa | cname | gid | hinfo | ns | mb | md | mg | mf
| minfo | mx | naptr | null | ptr | soa | spf | srv | txt
| uid | uinfo | unspec | wks
query_type() = axfr | mailb | maila | any | rr_type()
dns_class() = in | chaos | hs | any
dns_msg() = DnsMsg
This is the start of a hiearchy of opaque data structures
that can be examined with access functions in inet_dns
that return lists of {Field,Value} tuples. The arity 2
functions just return the value for a given field.
inet_dns:msg(DnsMsg) ->
[ {header, dns_header()}
| {qdlist, dns_query()}
| {anlist, dns_rr()}
| {nslist, dns_rr()}
| {arlist, dns_rr()} ]
inet_dns:msg(DnsMsg, header) -> dns_header() % for example
inet_dns:msg(DnsMsg, Field) -> Value
dhs_header() = DnsHeader
inet_dns:header(DnsHeader) ->
[ {id, integer()}
| {qr, bool()}
| {opcode, 'query' | iquery | status | integer()}
| {aa, bool()}
| {tc, bool()}
| {rd, bool()}
| {ra, bool()}
| {pr, bool()}
| {rcode, integer(0..16)} ]
inet_dns:header(DnsHeader, Field) -> Value
dns_query() = DnsQuery
inet_dns:dns_query(DnsQuery) ->
[ {domain, dns_name()}
| {type, query_type()}
| {class, dns_class()} ]
inet_dns:dns_query(DnsQuery, Field) -> Value
dns_rr() = DnsRr
inet_dns:rr(DnsRr) -> DnsRrFields | DnsRrOptFields
DnsRrFields = [ {domain, dns_name()}
| {type, rr_type()}
| {class, dns_class()}
| {ttl, integer()}
| {data, dns_data()} ]
DnsRrOptFields = [ {domain, dns_name()}
| {type, opt}
| {udp_payload_size, integer()}
| {ext_rcode, integer()}
| {version, integer()}
| {z, integer()}
| {data, dns_data()} ]
inet_dns:rr(DnsRr, Field) -> Value
dns_data() = % for dns_type()
[ dns_name() % ns, md, mf, cname, mb, mg, mr, ptr
| ip_address(v4) % a
| ip_address(v6) % aaaa
| {MName,RName,Serial,Refresh,Retry,Expiry,Minimum} % soa
| {ip_address(v4),Proto,BitMap} % wks
| {CpuString,OsString} % hinfo
| {RM,EM} % minfo
| {Prio,dns_name()} % mx
| {Prio,Weight,Port,dns_name()} % srv
| {Order,Preference,Flags,Services,Regexp,dns_name()} % naptr
| [ string() ] % txt, spf
| binary() ] % null, integer()
MName, RName = dns_name()
Serial, Refresh, Retry, Expiry, Minimum = integer(),
Proto = integer()
BitMap = binary()
CpuString, OsString = string()
RM = EM = dns_name()
Prio, Weight, Port = integer()
Order, Preference = integer()
Flags, Services = string(),
Regexp = string(utf8)
There is an info function for the types above:
inet_dns:record_type(dns_msg()) -> msg;
inet_dns:record_type(dns_header()) -> header;
inet_dns:record_type(dns_query()) -> dns_query;
inet_dns:record_type(dns_rr()) -> rr;
inet_dns:record_type(_) -> undefined.
So; inet_dns:(inet_dns:record_type(X))(X) will convert
any of these data structures into a {Field,Value} list.
Resolve a DNS record of the given type for the given host,
of class
This function uses the resolver option
Backend functions used by
Backend functions used by
This function uses the resolver option
If the resolver option
Resolve the DNS data for the record of the given type and class
for the given name. On success filters out the answer records
with the correct
Calls
Resolve a DNS record of the given type and class for the given name.
The returned
If
The
If
The
Access functions example: how
example_lookup(Name, Class, Type) ->
case inet_res:resolve(Name, Class, Type) of
{ok,Msg} ->
[inet_dns:rr(RR, data)
|| RR <- inet_dns:msg(Msg, anlist),
inet_dns:rr(RR, type) =:= Type,
inet_dns:rr(RR, class) =:= Class];
{error,_} ->
[]
end.
These have been deprecated due to the annoying double meaning of the nameservers/timeout argument, and because they had no decent place for a resolver options list.
Resolve a DNS record of the given type and class for the given name.
Resolve a DNS record of the given type and class for the given name.