xref: /reactos/drivers/network/tcpip/lwip/doc/mdns.txt (revision 63bb46a2)
1Multicast DNS for lwIP
2
3Author: Erik Ekman
4
5
6Note! The MDNS responder does not have all features required by the standards.
7See notes in src/apps/mdns/mdns.c for what is left. It is however usable in normal
8cases - but watch out if many devices on the same network try to use the same
9host/service instance names.
10
11
12How to enable:
13==============
14
15MDNS support does not depend on DNS.
16MDNS supports using IPv4 only, v6 only, or v4+v6.
17
18To enable MDNS responder, set
19  LWIP_MDNS_RESPONDER = 1
20in lwipopts.h and add src/apps/mdns/mdns.c to your list of files to build.
21
22The max number of services supported per netif is defined by MDNS_MAX_SERVICES,
23default is 1.
24
25Increase MEMP_NUM_UDP_PCB by 1. MDNS needs one PCB.
26Increase LWIP_NUM_NETIF_CLIENT_DATA by 1 (MDNS needs one entry on netif).
27
28MDNS with IPv4 requires LWIP_IGMP = 1, and preferably LWIP_AUTOIP = 1.
29MDNS with IPv6 requires LWIP_IPV6_MLD = 1, and that a link-local address is
30generated.
31
32The MDNS code puts its structs on the stack where suitable to reduce dynamic
33memory allocation. It may use up to 1kB of stack.
34
35MDNS (like other apps) needs a strncasecmp() implementation. If you have one, define
36'lwip_strnicmp' to it. Otherwise the code will provide an implementation
37for you.
38
39
40How to use:
41===========
42
43Call mdns_resp_init() during system initialization.
44This opens UDP sockets on port 5353 for IPv4 and IPv6.
45
46
47To start responding on a netif, run
48  mdns_resp_add_netif(struct netif *netif, const char *hostname)
49
50The hostname will be copied. If this returns successfully, the netif will join
51the multicast groups and any MDNS/legacy DNS requests sent unicast or multicast
52to port 5353 will be handled:
53- <hostname>.local type A, AAAA or ANY returns relevant IP addresses
54- Reverse lookups (PTR in-addr.arpa, ip6.arpa) of netif addresses
55  returns <hostname>.local
56MDNS allows UTF-8 names, but it is recommended to stay within ASCII,
57since the default case-insensitive comparison assumes this.
58
59Call mdns_resp_announce() every time the IP address on the netif has changed.
60
61Call mdns_resp_restart() every time the network interface comes up after being
62down, for example cable connected after being disconnected, administrative
63interface comes up after being down, or the device wakes up from sleep.
64
65To stop responding on a netif, run
66  mdns_resp_remove_netif(struct netif *netif)
67
68
69Adding services:
70================
71
72The netif first needs to be registered. Then run
73  mdns_resp_add_service(struct netif *netif, const char *name, const char *service,
74      enum mdns_sd_proto proto, u16_t port,
75      service_get_txt_fn_t txt_fn, void *txt_userdata);
76
77The name and service pointers will be copied. Name refers to the name of the
78service instance, and service is the type of service, like _http
79proto can be DNSSD_PROTO_UDP or DNSSD_PROTO_TCP which represent _udp and _tcp.
80If this call returns successfully, the following queries will be answered:
81- _services._dns-sd._udp.local type PTR returns <service>.<proto>.local
82- <service>.<proto>.local type PTR returns <name>.<service>.<proto>.local
83- <name>.<service>.<proto>.local type SRV returns hostname and port of service
84- <name>.<service>.<proto>.local type TXT builds text strings by calling txt_fn
85  with the supplied userdata. The callback adds strings to the reply by calling
86  mdns_resp_add_service_txtitem(struct mdns_service *service, char *txt,
87   int txt_len). Example callback method:
88
89   static void srv_txt(struct mdns_service *service, void *txt_userdata)
90   {
91     res = mdns_resp_add_service_txtitem(service, "path=/", 6);
92     LWIP_ERROR("mdns add service txt failed\n", (res == ERR_OK), return);
93   }
94
95  Since a hostname struct is used for TXT storage each single item can be max
96  63 bytes long, and  the total max length (including length bytes for each
97  item) is 255 bytes.
98
99If your device runs a webserver on port 80, an example call might be:
100
101  mdns_resp_add_service(netif, "myweb", "_http"
102      DNSSD_PROTO_TCP, 80, srv_txt, NULL);
103
104which will publish myweb._http._tcp.local for any hosts looking for web servers,
105and point them to <hostname>.local:80
106
107Relevant information will be sent as additional records to reduce number of
108requests required from a client.
109
110To remove a service from a netif, run
111  mdns_resp_del_service(struct netif *netif, u8_t slot)
112