Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tag: v0.3
Fetching contributors…

Cannot retrieve contributors at this time

154 lines (114 sloc) 5.73 KB


dnssd_erlang is an interface to Apple's Bonjour DNS Service Discovery implementation. Bonjour allows applications to browse, resolve and register network services via link-local multicast DNS on the local network and via unicast DNS over the internet. In the later case if the service is running behind a NAT gateway Bonjour will only advertise it if a port forward can be negotiated via NAT-PMP or uPNP (which is attempted automatically).

Development Status

The API and functionality provided aren't yet set in stone but will be locked down before release 1.0.


Apple Bonjour or compatible API with the appropriate development files available.

Build Process

make compile (or ./rebar compile)

If you are running Linux with Avahi you will need Avahi's Bonjour compatibility layer installed.

If you are running Windows you will need Visual Studio and the Bonjour SDK installed. The project can then be built from a Visual Studio command prompt.


Please direct your feedback here.

Example use

Eshell V5.8.2  (abort with ^G)
1> dnssd:start().

First start the application via dnssd:start/1 or application:start(dnssd).

Browsing for Services

2> dnssd:browse("_http._tcp").

In the success case, all functions return a tuple of the form {ok, Reference}. Reference should be retained to pass to dnssd:stop/1 when no further results are required.

3> flush().
Shell got {dnssd,#Ref<>,
Shell got {dnssd,#Ref<>,

Results will be sent in tuples of the form {dnssd, Reference, {Operation, Change, Result}}.

4> dnssd:browse(<<"_http._tcp">>, <<"">>).
5> flush().
Shell got {dnssd,#Ref<>,
                         {<<" * Apple, makers of the iPod">>,
Shell got {dnssd,#Ref<>,
                         {<<" * Google, searching the Web">>,
%% snipped %%

Browsing can be limited to a specific domain by specifying the domain as argument two. Both domains and service types may be specified as lists or binaries.

Resolving a Service Instance

6> dnssd:resolve(<<" * DNS Service Discovery">>, <<"_http._tcp.">>, <<"">>). 

To resolve a service, supply it's name, registration type and domain to the resolve function.

7> flush().
Shell got {dnssd,#Ref<>,

Unlike the other operations results won't be tagged add or remove as the underlying DNSSD API does not provide this information. As resolve is generally called just prior to connecting to a service this shouldn't pose a problem.

8> dnssd:resolve_sync(<<" * DNS Service Discovery">>, <<"_http._tcp.">>, <<"">>).

A synchronous wrapper to resolve is also provided. A timeout in milliseconds can also be specified by adding a fourth argument. The default is 5 seconds.

Registering Services

9> dnssd:register("_answer._udp",42).
10> flush().
Shell got {dnssd,#Ref<>,

The minimum arguments needed to register a service are the service type and port. If no service name is supplied, the machines name is used (in the example above, that's <<"atj-mbp">>).

For brevity, the alternative invocations of register are:

dnssd:register(Name, Type, Port).
dnssd:register(Type, Port, Txt).
dnssd:register(Name, Type, Port, Txt).
dnssd:register(Name, Type, Port, Txt, Host, Domain).


  • Txt is a TXT record data in either binary form (a sequence of <<Size, String:Size/binary>>), a list of atoms, strings or binaries or tuples of the form {Key,Value} where Key and Value are atoms, strings or binaries.
  • Host is the hostname of the machine running the service. Pass an empty string or binary for the local machine.
  • Domain is the domain to register the service within. Pass an empty string or binary for all domains.

Local Registrations

If localhost is passed as Host to dnssd:register/6 the service will be registered only in the local domain (regardless of the Domain argument) and only on the local machine.

Enumerating Domains

11> dnssd:enumerate(browse).
12> flush().
Shell got {dnssd,#Ref<>,{enumerate,add,<<"local.">>}}
Shell got {dnssd,#Ref<>,{enumerate,add,<<"">>}}
13> dnssd:enumerate(reg).
14> flush().
Shell got {dnssd,#Ref<>,{enumerate,add,<<"local.">>}}
Shell got {dnssd,#Ref<>,{enumerate,add,<<"">>}}

Stopping Operations

It's important to stop operations when no more results are needed to avoid generating needless network traffic. To stop an operation pass the Reference returned when you started the operation to dnssd:stop/1. Operations will also be stopped if your process exits.

Retrieving Results

Results from a running operation can be retrieved by calling dnssd:results(Ref). For resolve operations this will only return the last result. For all other operations it will return all current results.

Jump to Line
Something went wrong with that request. Please try again.