Domain name resolution
The emNet TCP/IP stack provides a way to easily discover a target by its name.
Overview
The emNet TCP/IP stack provides a way to easily discover a target by its name. For targets used as client, both Apple multicast DNS (mDNS / Bonjour) and Microsoft Link-Local Multicast Name Resolution (LLMNR) are supported. When the target is used as server, a simple DNS server can be used. The add-on also provides a simple support for service discovery (DNS-SD).
Key features
- Low memory footprint
- Makes your target easily discoverable
- Supports protocols for Windows, MacOS and Linux
- Easy to implement
Background
The different specifications are all based on UDP messages with DNS format. They serve the same purpose to easily identify a target by its name without prior knowledge of its IP address, or to discover the service it is proposing like a web server for example.
mDNS: Apple multicast DNS (mDNS) uses multicast messages on port 5353. A target with a mDNS server could easily be found by a request with its name (by an Apple device for example). The mDNS client is part of the base emNet package and is able to send such requests.
LLMNR: Microsoft Link-Local Multicast Name Resolution (LLMNR) uses multicast messages on port 5355. A target with a LLMNR server could easily be found by a request with its name (by a Windows computer for example). The LLMNR client is part of the base emNet package and is able to send such requests.
Simple DNS server: When the target is used as server, for example with the emNet DHCP server, a client sends unicast requests to the DNS server. The emNet simple DNS server does not provide full DNS server capabilities but covers main requirements with a low memory footprint.
Example
In the following example, a device with a Web server could be easily found by a browser with its name without a prior knowledge of its IP address.
Service discovery
Along with A and AAAA records for the IPv4 and IPv6 addresses, it is also possible to configure SRV, PTR and TXT records. This allows a device to advertise a service and be found by system like Bonjour or equivalent tools (avahi on linux for example).
For example, the following configuration advertises a web server for the device mydevice.local.
//
// Web server discovery configuration
//
static const IP_DNS_SERVER_SD_CONFIG _Config[] = {
//
// PTR record _http._tcp.local -> mydevice._http._tcp.local
//
{
.Type = IP_DNS_SERVER_TYPE_PTR,
.TTL = 0, // Use main TTL.
.Config = {
.PTR = {
.sName = "_http._tcp.local",
.sDomainName = "mydevice._http._tcp.local"
}
}
},
//
// SRV record mydevice._http._tcp.local -> mydevice.local port 80
//
{
.Type = IP_DNS_SERVER_TYPE_SRV,
.TTL = 0, // Use main TTL.
.Config = {
.SRV = {
.sName = "mydevice._http._tcp.local",
.Priority = 0,
.Weight = 0,
.Port = 80,
.sTarget = NULL // Use default hostname mydevice.local
}
}
},
//
// TXT record. Path of the web server.
//
{
.Type = IP_DNS_SERVER_TYPE_TXT,
.TTL = 0, // Use main TTL.
.Config = {
.TXT = {
.sName = "mydevice._http._tcp.local",
.sTXT = "PATH=/"
}
}
}
};
static const IP_DNS_SERVER_CONFIG _DiscoverConfig = {
.sHostname = "mydevice.local",
.TTL = 120u,
.NumConfig = 3,
.apSDConfig = _Config
};
The device could then be discovered easily, for example on Linux with avahi-discover tool. In this example the discovery tool and the device exchange the following mDNS messages:
- Tool sends request: PTR _http._tcp.local to identify web servers.
- Device replies that it proposes the service mydevice._http._tcp.local
- Tool sends request: SRV mydevice._http._tcp.local to get service details.
- Device replies with the SRV information such as the port 80 and server target name mydevice.local.
- Tool sends request: TXT mydevice._http._tcp.local to get more information.
- Device replies with the web server path "/"
- Tool sends request: A mydevice.local and/or AAAA mydevice.local to get the IPv4/IPv6 address.
- Device replies with its IP address.
Resource usage
The ROM usage depends on the compiler options, the compiler version and the used CPU. The memory requirements presented below have been measured on a Cortex-M4 system with the default configuration.Only the server is shown below as the client is part of the emNet base package.
Relevant parts
The relevant parts of the following Request For Comments (RFC) are implemented.
RFC# | Description |
---|---|
[RFC 6762] | Direct Link: Multicast DNS |
[RFC 4795] | Direct Link: Link-Local Multicast Name Resolution (LLMNR) |
[RFC 6763] | Direct Link: DNS-Based Service Discovery |
[RFC 2782] | Direct Link: A DNS RR for specifying the location of services (DNS SRV) |
[RFC 1035] | Direct Link: DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION |