Class Dns.resolver


class resolver : object .. end
DNS resolver.

High Level Methods

method reset_queries : unit
Delete all queries.

NOTE: when doing this, answers, authorities and additionals are reseted as well as though the resolver was new.

This methods allows the same resolver to be used multiple times with the same configuration.

method add_query : ?qtype:string -> ?qclass:string -> qname:string -> unit
add_query ~qname ~qtype ~qclass adds a new query to the packet.

The exceptions Dns.Unknown_type and Dns.Unknown_class may occurre when a support of a query type or class is missing in ODNS. If this was to happen, you can still construct the query by adding the type and the class as their integer value using Dns.resolver.raw_query.

NOTE: when adding a query, answers, authorities and additionals are reseted as well as though the resolver was new, so that the answers are always consistent to the current list of query.
Raises

qtype : the type of the query (default to "IN").
qclass : the class of the query (default to "A").
qname : the domain name queried.
method query : unit
Actually query the nameservers (using the internal algorithm looping through the list of nameservers, waiting for timeout seconds and retrying retries times when failures occurred).
method answers : rr list
A resolver can be reused several time. Hence it will return only records returned as response of the last time you ran Dns.resolver.query. Moreover this function has no meaning before you run Dns.resolver.query (it would raise ).
Raises Returns the list of resource records in the Answer section of the DNS response. An empty list means that we had a valid response but that there is no record for the queried target, type and class (resolving errors are different and will raise Dns.Name_error or Dns.Nameservers_failure).
method authorities : rr list
A resolver can be reused several time. Hence it will return only records returned as authorities of the last time you ran Dns.resolver.query. Moreover this function has no meaning before you run Dns.resolver.query (TODO: raise an exception then).
Raises Returns the list of resource records in the Authority section of the DNS response.
method additionals : rr list
A resolver can be reused several time. Hence it will return only records returned as additionals of the last time you ran Dns.resolver.query. Moreover this function has no meaning before you run Dns.resolver.query (TODO: raise an exception then).
Raises Returns the list of resource records in the Additional section of the DNS response.

Resolver Configuration

method nameservers : string list
Returns the current list of nameservers which will be contacted in the same order as the list.
method set_nameservers : string list -> unit
set_nameservers ns sets the list ns as the new list of nameservers. Name servers will be tried and contacted in the order of the provided list.

As a special case, if an empty list is given, the system's default list of name servers (from /etc/resolv.conf) will be used instead.

method set_nocache : bool -> unit
method nocache : bool
method timeout : float
Returns the currently set timeout, in seconds, after which a query will fail if no response has returned. The default value is 5 seconds.
method set_timeout : float -> unit
set_timeout t sets a new timeout of t seconds. If you don't set any, the default value is 5 seconds.
method retries : int
Returns the number of time the resolver algorithm will retry a same request on the same server when the previous one failed.
method set_retries : int -> unit
set_retries n set to n the number of time the resolver algorithm will retry a same request on a same server when previous one failed.

As a special case, if you set it to a negative value, it will be equivalent to 0. If you don't set this parameter, the default value is 1.

method recursive : bool
Returns true if recursion is desired for the query to be sent.
method set_recursive : bool -> unit
set_recursive true makes so that the query will "ask" the name server to use its recursive capabilities.
method search_list : string list
Returns the current search list for hostname lookup (man 5 resolv.conf if you don't know what is the search list.
method set_search_list : string list -> unit
set_search ns sets the list ns as the new search list. Name servers will be tried and contacted in the order of the provided list.
method verbose : Pervasives.out_channel option
Returns None if verbose mode is disable or else the output channel where the verbose output is written to.
method set_verbose : Pervasives.out_channel option -> unit
Sets an output channel where you want verbose (debug) function to be written to. As a special value, None disables the verbose mode.

It is up to you to be sure the file can be written in and has not been closed, though in any case, this function cannot crash. It is also up to you to close this channel (if necessary) when all no output should occurre again.

method ansi_capable : bool
Returns true if you set the verbose output channel as a channel recognizing ANSI escape sequences (like most modern Terminal Emulator.
method set_ansi_capable : bool -> unit
set_ansi_capable true indicates that the verbose output channel is ANSI capable. You might want to set this if the output is a terminal emulator in order to color different kind of output for instance, but disable it when outputing to a file. Default to false.

Raw Access to Messages

In most cases, you should not have to touch to these methods. If you do, be careful not to "break" the messages (in particular the query) as no verification will be done here (contrary to high level methods which makes all necessary verifications to keep consistent messages).

method raw_response : message option
TODO: should return a list of messages, as the answer can be truncated.
Returns an optional list of messages which are the messages received as a response to our query. It will return None if all name servers timed out the query.
method raw_query : message
raw_query enables to study the generated DNS message which will be sent over the wire.

Aware developers can also directly hack this message in order to exploit DNS features non-supported by the ODNS library, for instance. This should be done after running Dns.resolver.add_query but before running Dns.resolver.query.
Returns the DNS message used as a query.