mdns_common.h
Go to the documentation of this file.
1 /**
2  * @file mdns_common.h
3  * @brief Definitions common to mDNS client and mDNS responder
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2020 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.8
29  **/
30 
31 #ifndef _MDNS_COMMON_H
32 #define _MDNS_COMMON_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "dns/dns_common.h"
37 
38 //Maximum size of DNS messages
39 #ifndef MDNS_MESSAGE_MAX_SIZE
40  #define MDNS_MESSAGE_MAX_SIZE 1024
41 #elif (MDNS_MESSAGE_MAX_SIZE < 1)
42  #error MDNS_MESSAGE_MAX_SIZE parameter is not valid
43 #endif
44 
45 //Default resource record TTL (cache lifetime)
46 #ifndef MDNS_DEFAULT_RR_TTL
47  #define MDNS_DEFAULT_RR_TTL 120
48 #elif (MDNS_DEFAULT_RR_TTL < 1)
49  #error MDNS_DEFAULT_RR_TTL parameter is not valid
50 #endif
51 
52 //mDNS port number
53 #define MDNS_PORT 5353
54 //Default IP TTL value
55 #define MDNS_DEFAULT_IP_TTL 255
56 //Maximum RR TTL in legacy unicast responses
57 #define MDNS_LEGACY_UNICAST_RR_TTL 10
58 
59 //QU flag
60 #define MDNS_QCLASS_QU 0x8000
61 //Cache Flush flag
62 #define MDNS_RCLASS_CACHE_FLUSH 0x8000
63 
64 //mDNS IPv4 multicast group
65 #define MDNS_IPV4_MULTICAST_ADDR IPV4_ADDR(224, 0, 0, 251)
66 
67 //C++ guard
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 
73 /**
74  * @brief mDNS message
75  **/
76 
77 typedef struct
78 {
80  size_t offset;
81  size_t length;
88 } MdnsMessage;
89 
90 
91 //mDNS IPv6 multicast group
93 
94 //mDNS related functions
95 error_t mdnsInit(NetInterface *interface);
96 
97 void mdnsProcessMessage(NetInterface *interface,
98  const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
99  const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary,
100  void *param);
101 
102 void mdnsProcessResponse(NetInterface *interface, MdnsMessage *response);
103 
105  const IpPseudoHeader *pseudoHeader);
106 
109 
111  const IpAddr *destIpAddr, uint_t destPort);
112 
113 size_t mdnsEncodeName(const char_t *instance, const char_t *service,
114  const char_t *domain, uint8_t *dest);
115 
116 int_t mdnsCompareName(const DnsHeader *message, size_t length, size_t pos,
117  const char_t *instance, const char_t *service, const char_t *domain, uint_t level);
118 
119 int_t mdnsCompareRecord(const MdnsMessage *message1, size_t offset1,
120  const DnsResourceRecord *record1, const MdnsMessage *message2,
121  size_t offset2, const DnsResourceRecord *record2);
122 
124  const char_t *service, const char_t *domain, uint16_t rtype);
125 
126 //C++ guard
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif
__start_packed struct @44 DnsHeader
DNS message header.
uint8_t length
Definition: coap_common.h:190
size_t mdnsEncodeName(const char_t *instance, const char_t *service, const char_t *domain, uint8_t *dest)
Encode instance, service and domain names using the DNS name notation.
Definition: mdns_common.c:562
int bool_t
Definition: compiler_port.h:49
__start_packed struct @46 DnsResourceRecord
Resource record format.
size_t offset
Definition: mdns_common.h:80
signed int int_t
Definition: compiler_port.h:44
IP network address.
Definition: ip.h:78
uint_t sharedRecordCount
Definition: mdns_common.h:87
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:88
NetBuffer * buffer
Definition: mdns_common.h:79
bool_t mdnsCheckSourceAddr(NetInterface *interface, const IpPseudoHeader *pseudoHeader)
Source address check.
Definition: mdns_common.c:276
systime_t timeout
Definition: mdns_common.h:86
DnsHeader * dnsHeader
Definition: mdns_common.h:84
uint16_t destPort
Definition: tcp.h:303
uint16_t rtype
Definition: dns_common.h:203
bool_t mdnsCheckDuplicateRecord(const MdnsMessage *message, const char_t *instance, const char_t *service, const char_t *domain, uint16_t rtype)
Check for duplicate resource records.
Definition: mdns_common.c:911
const Ipv6Addr MDNS_IPV6_MULTICAST_ADDR
Definition: mdns_common.c:59
uint8_t level
Definition: tls.h:1725
IP pseudo header.
Definition: ip.h:97
error_t
Error codes.
Definition: error.h:42
error_t mdnsSendMessage(NetInterface *interface, const MdnsMessage *message, const IpAddr *destIpAddr, uint_t destPort)
Send mDNS message.
Definition: mdns_common.c:458
const IpPseudoHeader * pseudoHeader
Definition: mdns_common.h:82
size_t length
Definition: mdns_common.h:81
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
void mdnsDeleteMessage(MdnsMessage *message)
release a mDNS message
Definition: mdns_common.c:434
void mdnsProcessMessage(NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary, void *param)
Process incoming mDNS message.
Definition: mdns_common.c:112
mDNS message
Definition: mdns_common.h:77
char char_t
Definition: compiler_port.h:43
const UdpHeader * udpHeader
Definition: mdns_common.h:83
void mdnsProcessResponse(NetInterface *interface, MdnsMessage *response)
Process mDNS response message.
Definition: mdns_common.c:182
uint8_t message[]
Definition: chap.h:152
__start_packed struct @77 Ipv6Addr
IPv6 network address.
__start_packed struct @20 UdpHeader
UDP header.
int_t mdnsCompareRecord(const MdnsMessage *message1, size_t offset1, const DnsResourceRecord *record1, const MdnsMessage *message2, size_t offset2, const DnsResourceRecord *record2)
Compare resource records.
Definition: mdns_common.c:805
error_t mdnsCreateMessage(MdnsMessage *message, bool_t queryResponse)
Create an empty mDNS message.
Definition: mdns_common.c:358
unsigned int uint_t
Definition: compiler_port.h:45
TCP/IP stack core.
error_t mdnsInit(NetInterface *interface)
mDNS related initialization
Definition: mdns_common.c:69
systime_t timestamp
Definition: mdns_common.h:85
Common DNS routines.
uint32_t systime_t
Definition: compiler_port.h:46
int_t mdnsCompareName(const DnsHeader *message, size_t length, size_t pos, const char_t *instance, const char_t *service, const char_t *domain, uint_t level)
Compare instance, service and domain names.
Definition: mdns_common.c:652
Ipv4Addr destIpAddr
Definition: ipcp.h:78