5 * Copyright (C) 2003 Jeremie Miller <jer@jabber.org>
6 * Copyright (c) 2009 Simon Budig <simon@budig.org>
7 * Copyright (C) 2013 Ole Reinhardt <ole.reinhardt@embedded-it.de>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the copyright holders nor the names of
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
31 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
34 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * For additional information see http://www.ethernut.de/
40 /* This code is based on
41 * Based on BSD licensed mdnsd implementation by Jer <jer@jabber.org>
42 * http://dotlocal.org/mdnsd/
44 * Unfortunately this site is now longer alive. You can still find it at:
45 * http://web.archive.org/web/20080705131510/http://dotlocal.org/mdnsd/
47 * mdnsd - embeddable Multicast DNS Daemon
48 * =======================================
50 * "mdnsd" is a very lightweight, simple, portable, and easy to integrate
51 * open source implementation of Multicast DNS (part of Zeroconf, also called
52 * Rendezvous by Apple) for developers. It supports both acting as a Query and
53 * a Responder, allowing any software to participate fully on the .localnetwork
54 * just by including a few files and calling a few functions. All of the
55 * complexity of handling the Multicast DNS retransmit timing, duplicate
56 * suppression, probing, conflict detection, and other facets of the DNS
57 * protocol is hidden behind a very simple and very easy to use interface,
58 * described in the header file. The single small c source file has almost no
59 * dependencies, and is portable to almost any embedded platform.
60 * Multiple example applications and usages are included in the download,
61 * including a simple persistent query browser and a tool to advertise .local
64 * The code is licensed under both the GPL and BSD licenses, for use in any
65 * free software or commercial application. If there is a licensing need not
66 * covered by either of those, alternative licensing is available upon request.
71 * \file include/pro/mdnsd.h
72 * \brief Multicast DNS Deamon
83 #include <netinet/in.h>
84 #include <arpa/inet.h>
87 #elif defined(__GNUC__)
88 # define UNUSED(x) UNUSED_ ## x __attribute__((unused))
89 #elif defined(__LCLINT__)
90 # define UNUSED(x) /*@unused@*/ x
95 #define MDNS_PORT 5353
96 #define MDNS_MULTICAST_IP "224.0.0.251"
98 /* Size of query/publish hashes */
101 /* size of cache hash */
104 /* brute force garbage cleanup frequency, rarely needed (daily default) */
109 * \brief MDNS answer data
111 typedef struct _mdnsda_struct TMdnsdAnswer;
112 struct _mdnsda_struct
119 struct in_addr ip; // A
120 uint8_t *rdname; // NS/CNAME/PTR/SRV
130 * \brief MDNS record entry
132 typedef struct _mdnsdr_struct TMdnsdRecord;
133 struct _mdnsdr_struct
136 int8_t unique; // # of checks performed to ensure
138 void (*conflict)(TMdnsdRecord *record,char *name, int type, void *arg);
146 * \brief MDNS query struct
148 typedef struct _query_struct TQuery;
155 int (*answer)(TMdnsdAnswer *answer, void *arg);
163 * \brief Unicast record data
165 typedef struct _unicast_struct TUnicast;
166 struct _unicast_struct
171 TMdnsdRecord *record;
177 * \brief Cached record entry struct
179 typedef struct _cached_struct TCached;
180 struct _cached_struct
189 * \brief Main MDNS deamon data
191 typedef struct _mdnsd_struct TMdnsd;
195 uint32_t expireall, checkqlist;
197 struct timeval sleep;
198 struct timeval pause;
199 struct timeval probe;
200 struct timeval publish;
203 TCached *cache[LPRIME];
204 TMdnsdRecord *published[SPRIME];
205 TMdnsdRecord *probing;
207 TMdnsdRecord *a_pause;
208 TMdnsdRecord *a_publish;
210 TQuery *queries[SPRIME];
214 /* Global functions */
215 TMdnsd *MdnsdNew(int class, int frame);
216 void MdnsdShutdown(TMdnsd *mdnsd);
217 void MdnsdFlush(TMdnsd *mdnsd);
218 void MdnsdFree(TMdnsd *mdnsd);
221 void MdnsdInput(TMdnsd *mdnsd, DNSMESSAGE *m, struct in_addr ip, uint16_t port);
222 int MdnsdOutput(TMdnsd *mdnsd, DNSMESSAGE *m, struct in_addr *ip, uint16_t *port);
223 struct timeval *MdnsdGetMaxSleepTime(TMdnsd *mdnsd);
225 /* Qery / Answer functions */
226 void MdnsdQuery(TMdnsd *mdnsd, char *host, int type, int (*answer)(TMdnsdAnswer *a, void *arg), void *arg);
227 TMdnsdAnswer *MdnsdListCachedAnswers(TMdnsd *mdnsd, char *host, int type, TMdnsdAnswer *last);
229 /* Publishing functions */
230 TMdnsdRecord *MdnsdAllocUnique(TMdnsd *mdnsd, char *host, int type, uint32_t ttl, void (*conflict)(TMdnsdRecord *record, char *host, int type, void *arg), void *arg);
231 TMdnsdRecord *MdnsdAllocShared(TMdnsd *mdnsd, char *host, int type, uint32_t ttl);
232 void MdnsdDone(TMdnsd *mdnsd, TMdnsdRecord *record);
234 /* These all set/update the data for the given record, nothing is published until they are called */
235 void MdnsdSetRaw(TMdnsd *mdnsd, TMdnsdRecord *record, uint8_t *data, int len);
236 void MdnsdSetHost(TMdnsd *mdnsd, TMdnsdRecord *record, char *name);
237 void MdnsdSetIp(TMdnsd *mdnsd, TMdnsdRecord *record, struct in_addr ip);
238 void MdnsdSetSrv(TMdnsd *mdnsd, TMdnsdRecord *record, int priority, int weight, uint16_t port, char *name);