mDNS: Multicast Domain Name System¶
https://en.wikipedia.org/wiki/Multicast_DNS
Responder¶
Sming provides the mDNS::Responder
class to allow applications
to advertise themselves on the local network.
To use:
Add
COMPONENT_DEPENDS += MDNS
to your application componenent.mk file.Add these lines to your application:
#include <Mdns/Responder.h> static mDNS::Responder responder; // Call when IP address has been obtained void startmDNS() { responder.begin(F("myhostname"); }
This will advertise the device as myhostname.local
.
To provide a custom service, implement a mDNS::Service
class
and call mDNS::Responder::addService()
.
See the UDP Server mDNS sample application.
Discovery¶
This library also provides support for device discovery using a separate set of classes,
based on the mDNS::Server
.
See Basic_Mdns for an example.
Testing¶
For linux, you can use avahi to perform mDNS queries and confirm output is as expected:
sudo apt install avahi
avahi-browse --all -r
References¶
Multicast DNS RFC6762 https://tools.ietf.org/html/rfc6762
Zero-configuration networking (DNS-SD) https://en.wikipedia.org/wiki/Zero-configuration_networking
DNS-Based Service Discovery https://tools.ietf.org/html/rfc6763
DNS record types https://en.wikipedia.org/wiki/List_of_DNS_record_types
Domain Names: Implementation and Specification https://tools.ietf.org/html/rfc1035
API Documentation¶
-
namespace
mDNS
¶ -
Functions
Variables
-
constexpr uint32_t
MDNS_IP
= {0xFB0000E0}¶
-
constexpr uint16_t
MDNS_TARGET_PORT
= {5353}¶
-
constexpr uint16_t
MDNS_SOURCE_PORT
= {5353}¶
-
constexpr uint16_t
MDNS_TTL
= {255}¶
-
constexpr uint16_t
MAX_PACKET_SIZE
= {1024}¶
-
class
Handler
: public LinkedObjectTemplate<Handler>¶ - #include <Handler.h>
Virtual base class used for chaining message handlers.
Subclassed by mDNS::Responder
-
class
Message
¶ - #include <Message.h>
Encapsulates a message packet for flexible introspection.
Subclassed by mDNS::Request
-
class
Name
¶ - #include <Name.h>
Encoded DNS name.
mDNS-SD names are represented as instance.service.domain. See https://tools.ietf.org/html/rfc6763#section-4.1
Instance names should be friendly and not attempt to be unique. See https://tools.ietf.org/html/rfc6763#appendix-D
Example: “UDP Server._http._tcp.local” instance: “UDP Server” service: “_http._tcp” name: “http” protocol: Protocol::Tcp domain: “local”
-
class
Responder
: public mDNS::Handler¶ - #include <Responder.h>
Special name for querying list of services.
-
class
Server
: protected UdpConnection¶ - #include <Server.h>
Locates mDNS services by issuing queries.
-
class
Service
: public LinkedObjectTemplate<Service>¶ - #include <Service.h>
Describes a basic service.
The default methods translate to a DNS-SD name of “Sming._http._tcp.local”. See :cpp:class:
mDNS::Name
for a description of how names are defined.
-
namespace
Resource
¶ -
-
class
AAAA
: public mDNS::Resource::Record¶ - #include <Resource.h>
‘AAAA’ record containing 128-bit IPv6 address
-
class
HINFO
: public mDNS::Resource::Record¶ - #include <Resource.h>
‘HINFO’ record containing Host information
-
class
PTR
: public mDNS::Resource::Record¶ - #include <Resource.h>
‘PTR’ record containing pointer to a canonical name
-
class
Record
¶ - #include <Resource.h>
Resource Record with no specific type.
Subclassed by mDNS::Resource::A, mDNS::Resource::AAAA, mDNS::Resource::HINFO, mDNS::Resource::PTR, mDNS::Resource::SRV, mDNS::Resource::TXT
-
class
-
constexpr uint32_t
References¶
Source Code (submodule, may be patched).
Used by¶
GoogleCast Library
Basic MDNS Sample
UDP Server mDNS Sample