Module Dns_helper


module Dns_helper: sig .. end
dns_helper.mli --- Helpers to obtain relevant DNS information in a high level fashion.

This API is part of ODNS library.

Copyright (C) 2011 Jehan Hysseo <hysseo at zemarmot point net>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.



This module provides functions to query Domain Name servers. It makes assumption to simplify the developer's task. In particular queries will be of the Internet ("IN") class.

The goal is to keep these functions very simple to use, though they still do sometimes complex computations (like SRV), some verifications or multiple DNS queries.

If you need more control over the whole querying process, you might want to have a look to the Dns.query resolver class, or more generally to the Dns module.

val srv_lookup : ?configuration:Dns.resolver -> string -> (string * int) list
srv_lookup query will return an (ip, port) list, for the requested query which must be in a SRV query format: "_service._protocol.domain_name". This list will be in a ready to try-and-connect order. In other words, the developer should not reorder this list and should try to connect to the returned (ip, port) combinations in the given order.

Implementation Note: The function will first lookup for SRV queries on the name server.


Returns a list of (ip, port) . Note that normally, for a given query, you should always have a response, even though the domain may not advertise any such service (if so, as explained above, it will fallback to default addresses and ports. If you receive an empty list, it can mean 4 things only:
See also RFC 2782: DNS SRV
configuration : is a Dns.resolver resolver, that you can optionally set if you need particular configuration for any query which will be made (otherwise default configuration is used). You cannot assume that this resolver will be actually used for any query (it is more likely to be other resolvers with same configuration) as it is used only as a configuration model. Still you should not use any result which may be returned by this resolver after being set a parameter here as you cannot know what is the last query (if any) which has actually been made (we advice to Dns.resolver.reset_queries it if you want to use it after).
val a_lookup : ?configuration:Dns.resolver -> string -> string list
a_lookup domain will make necessary queries to return IPv4 addresses for a given domain.
Returns a list of such IPv4 addresses associated to this domain.
configuration : is a Dns.resolver resolver, that you can optionally set if you need particular configuration for any query which will be made (otherwise default configuration is used). You cannot assume that this resolver will be actually used for any query (it is more likely to be other resolvers with same configuration) as it is used only as a configuration model. Still you should not use any result which may be returned by this resolver after being set a parameter here as you cannot know what is the last query (if any) which has actually been made (we advice to Dns.resolver.reset_queries it if you want to use it after).
val aaaa_lookup : ?configuration:Dns.resolver -> string -> string list
aaaa_lookup domain will return the IPv6 addresses associated to domain.
Returns a list of such IPv6 addresses.
configuration : is a Dns.resolver resolver, that you can optionally set if you need particular configuration for any query which will be made (otherwise default configuration is used). You cannot assume that this resolver will be actually used for any query (it is more likely to be other resolvers with same configuration) as it is used only as a configuration model. Still you should not use any result which may be returned by this resolver after being set a parameter here as you cannot know what is the last query (if any) which has actually been made (we advice to Dns.resolver.reset_queries it if you want to use it after).
val address_lookup : ?configuration:Dns.resolver -> string -> string list
address_lookup domain requests both IPv4 and IPv6 addresses of domain. (basically Dns_helper.a_lookup and Dns_helper.aaaa_lookup concatanated).
Returns a list of such addresses (can be IPv4, IPv6 or both).
configuration : is a Dns.resolver resolver, that you can optionally set if you need particular configuration for any query which will be made (otherwise default configuration is used). You cannot assume that this resolver will be actually used for any query (it is more likely to be other resolvers with same configuration) as it is used only as a configuration model. Still you should not use any result which may be returned by this resolver after being set a parameter here as you cannot know what is the last query (if any) which has actually been made (we advice to Dns.resolver.reset_queries it if you want to use it after).