mDNS/DNS-SD service discovery for OCaml (RFC 6762/6763)
OCaml 85.2%
Python 4.7%
Dune 3.1%
Other 7.1%
12 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-mdns
git@git.recoil.org:gazagnaire.org/ocaml-mdns

For self-hosted knots, clone URLs may differ based on your setup.

README.md

mdns#

mDNS/DNS-SD service discovery (RFC 6762/6763) for OCaml.

Overview#

mdns provides Multicast DNS for DNS-based Service Discovery as specified in RFC 6762 and RFC 6763. It uses Eio for async networking and the dns library for query encoding.

This implementation handles raw domain names to support DNS-SD service instance names containing spaces (e.g., "My Device._http._tcp.local").

Features#

  • RFC 6762/6763 compliant: Implements mDNS for DNS-SD
  • Record types: PTR, SRV, TXT, A, AAAA
  • Eio-based: Modern async networking with Eio
  • Space-safe: Handles service names with spaces
  • Fuzz tested: Parser tested with Crowbar

Installation#

opam install mdns

Usage#

(* Discover HTTP services on the local network *)
Eio_main.run @@ fun env ->
Eio.Switch.run @@ fun sw ->
let name = Domain_name.of_string_exn "_http._tcp.local" in
let responses = Mdns.query
  ~sw ~net:(Eio.Stdenv.net env)
  ~clock:(Eio.Stdenv.clock env)
  ~timeout:2.0 name
in
let merged = Mdns.merge responses in
List.iter (fun (_, instance) ->
  Format.printf "Found: %a@." Domain_name.pp instance
) merged.ptrs

API#

  • Mdns.query ~sw ~net ~clock ~timeout name - Send mDNS query and collect responses
  • Mdns.merge responses - Combine multiple responses
  • Mdns.parse buf - Parse a raw mDNS packet
  • Mdns.encode_query name - Encode an mDNS query packet
  • ocaml-dns - DNS library used for query encoding. Provides full DNS client/server but doesn't handle mDNS multicast or DNS-SD service names with spaces.
  • charrua - DHCP implementation for MirageOS, often used alongside mDNS for network discovery.

This library provides a focused mDNS/DNS-SD implementation using Eio for modern async networking.

License#

MIT License. See LICENSE.md for details.