dns-eio #
Eio-native DNS client for OCaml.
Single-shot A / AAAA / TXT queries against a configured nameserver,
wrapping the dns protocol primitives with an Eio-based UDP
transport. Designed for authenticated-channel use cases (ATProto
handle resolution, .well-known discovery) where the answer is
short and authenticity comes from a higher layer. No caching, no
TCP fallback on truncation, no DNSSEC.
Installation #
Install with opam:
$ opam install dns-eio
If opam cannot find the package, it may not yet be released in the
public opam-repository. Add the overlay repository, then install
it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install dns-eio
Usage #
A resolver picks up the nameservers from /etc/resolv.conf, falling
back to Cloudflare (1.1.1.1) and Google (8.8.8.8) if that file
is missing or empty. The list can be overridden at construction:
# let resolver =
Dns_eio.create
~nameservers:[ Ipaddr.of_string_exn "1.1.1.1" ]
~timeout_s:1.0 () in
List.map Ipaddr.to_string (Dns_eio.nameservers resolver)
- : string list = ["1.1.1.1"]
Each query takes a switch, a net, and a clock so the caller controls socket lifetime. The socket is opened, used for the single query, and closed when the switch ends:
let lookup_txt env name =
Eio.Switch.run @@ fun sw ->
let resolver = Dns_eio.create () in
match
Dns_eio.txt resolver
~sw
~net:(Eio.Stdenv.net env)
~clock:(Eio.Stdenv.clock env)
name
with
| Ok records -> List.iter print_endline records
| Error e -> Fmt.pr "DNS error: %a@." Dns_eio.pp_error e
The same pattern applies to Dns_eio.a (IPv4) and Dns_eio.aaaa
(IPv6). A name with no matching records returns Ok []; a name
that does not exist returns Error \Nxdomain`.
Licence #
ISC