MdnsLite (mdns_lite v0.8.0) View Source
MdnsLite is a simple, limited, no frills mDNS implementation
Advertising hostnames and services is generally done using the application
config. See MdnsLite.Options
for documentation.
To change the advertised hostnames or services at runtime, see set_host/1
,
add_mdns_service/1
and remove_mdns_service/1
.
MdnsLite's mDNS record tables and caches can be inspected using
MdnsLite.Info
if you're having trouble.
Finally, check out the MdnsLite README.md
for more information.
Link to this section Summary
Functions
Start advertising a service
Lookup a hostname using mDNS
Stop advertising a service
Set the list of host names
Link to this section Types
Specs
service() :: %{ :id => service_id(), :port => 1..65535, optional(:txt_payload) => [String.t()], optional(:priority) => 0..255, optional(:protocol) => String.t(), optional(:transport) => String.t(), optional(:type) => String.t(), optional(:weight) => 0..255 }
mDNS service description
Keys include:
:id
- an atom for referring to this service (only required if you want to reference the service at runtime):port
- the TCP/UDP port number for the service (required):transport
- the transport protocol. E.g.,"tcp"
(specify this and:protocol
, or:type
) *:protocol
- the application protocol. E.g.,"ssh"
(specify this and:transport
, or:type
):type
- the transport/protocol to advertize. E.g.,"_ssh._tcp"
(only needed if:protocol
and:transport
aren't specified):weight
- the service weight. Defaults to0
. (optional):priority
- the service priority. Defaults to0
. (optional):txt_payload
- a list of strings to advertise
Example:
%{id: :my_ssh, port: 22, protocol: "ssh", transport: "tcp"}
Specs
A user-specified ID for referring to a service
Atoms are recommended, but binaries are still supported since they were used in the past.
Link to this section Functions
Specs
add_mdns_service(service()) :: :ok
Start advertising a service
Services can be added at compile-time via the :services
key in the mdns_lite
application environment or they can be added at runtime using this function.
See the service
type for information on what's needed.
Example:
iex> service = %{
id: :my_web_server,
protocol: "http",
transport: "tcp",
port: 80
}
iex> MdnsLite.add_mdns_service(service)
:ok
Lookup a hostname using mDNS
The hostname should be a .local name since the query only goes out via mDNS. On success, an IP address is returned.
Specs
remove_mdns_service(service_id()) :: :ok
Stop advertising a service
Example:
iex> MdnsLite.remove_mdns_service(:my_ssh)
:ok
Specs
set_hosts([:hostname | String.t()]) :: :ok
Set the list of host names
This replaces the list of hostnames that MdnsLite will respond to. The first hostname in the list is special. Service advertisements will use it. The remainder are aliases.
Hostnames should not have the ".local" extension. MdnsLite will add it.
To specify the hostname returned by :inet.gethostname/0
, use :hostname
.
To make MdnsLite respond to queries for "<hostname>.local" and "nerves.local", run this:
iex> MdnsLite.set_hosts([:hostname, "nerves"])
:ok