# 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 ```ocaml (* 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 ## Related Work - [ocaml-dns](https://github.com/mirage/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](https://github.com/mirage/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](LICENSE.md) for details.