5 * Copyright (C) 2003 Jer <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/rfc1035.h
72 * \brief Standalone DNS parsing functions
74 * Implementation follows RF1035 [http://www.rfc-editor.org/rfc/rfc1035.txt] and
75 * includes decoding functions for svr rr's code type 33. See RFC2782
76 * [http://www.rfc-editor.org/rfc/rfc2782.txt]*
88 * \addtogroup xgMulticastDns
92 #define PACKET_BUFFER_LEN 4096
93 #define MAX_PACKET_LEN 4000
94 #define MAX_LABEL_SIZE 256
103 #define QTYPE_ANY 255
105 #define RRTYPE_A QTYPE_A
106 #define RRTYPE_NS QTYPE_NS
107 #define RRTYPE_CNAME QTYPE_CNAME
108 #define RRTYPE_PTR QTYPE_PTR
109 #define RRTYPE_TXT QTYPE_TXT
110 #define RRTYPE_SRV QTYPE_SRV
114 * \brief DNS question structure type.
116 * Contains the name, query type and class
127 * \brief DNS ressource record structure type.
162 * \brief DNS message structure type.
187 /* internal variables */
189 uint8_t *labels[MAX_LABEL];
194 uint8_t packet[MAX_PACKET_LEN];
197 /* Conversion of the network byte order buffer content into uint16_t or uint32_t values.
198 * Buffer pointer is incremented accordingly
200 uint16_t DnsNet2Short(uint8_t **buf);
201 uint32_t DnsNet2Long(uint8_t **buf);
203 /* Copies a short or long value in host byte order to the buffer and convert it to network byte order */
204 void DnsShort2Net(uint16_t val, uint8_t **buf);
205 void DnsLong2net(uint32_t val, uint8_t **buf);
207 /* Parsing function to parse a DNS packet into message format. Therfor the packet
208 must be at least MAX_PACKET_LEN bytes in size and must be allocated clean (zeroed)
210 void DnsParseMsg(DNSMESSAGE *msg, uint8_t *packet);
212 /* Create a message for sending out on the network. */
213 DNSMESSAGE *DnsCreateMsg(void);
215 /* Append a question to the message buffer */
216 void DnsMsgAdd_qd(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class);
218 /* Append a resource record to the message. Call these functions in the below order. */
219 void DnsMsgAdd_an(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class, uint32_t ttl);
220 void DnsMsgAdd_ns(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class, uint32_t ttl);
221 void DnsMsgAdd_ar(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class, uint32_t ttl);
223 /* Append resource data types blocks */
224 void DnsMsgAdd_rdata_long(DNSMESSAGE *msg, uint32_t val);
225 void DnsMsgAdd_rdata_name(DNSMESSAGE *msg, char *name);
226 void DnsMsgAdd_rdata_srv(DNSMESSAGE *msg, uint16_t priority, uint16_t weight, uint16_t port, char *name);
227 void DnsMsgAdd_rdata_raw(DNSMESSAGE *msg, uint8_t *rdata, uint16_t rdlength);
229 /* Generate the message packet to be send out and return the length */
230 uint8_t *DnsMsg2Pkt(DNSMESSAGE *msg);
231 int DnsMsgLen(DNSMESSAGE *msg);