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-2019 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.6
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, const IpPseudoHeader *pseudoHeader,
98  const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, void *param);
99 
100 void mdnsProcessResponse(NetInterface *interface, MdnsMessage *response);
101 
103  const IpPseudoHeader *pseudoHeader);
104 
107 
109  const IpAddr *destIpAddr, uint_t destPort);
110 
111 size_t mdnsEncodeName(const char_t *instance, const char_t *service,
112  const char_t *domain, uint8_t *dest);
113 
114 int_t mdnsCompareName(const DnsHeader *message, size_t length, size_t pos,
115  const char_t *instance, const char_t *service, const char_t *domain, uint_t level);
116 
117 int_t mdnsCompareRecord(const MdnsMessage *message1, size_t offset1,
118  const DnsResourceRecord *record1, const MdnsMessage *message2,
119  size_t offset2, const DnsResourceRecord *record2);
120 
122  const char_t *service, const char_t *domain, uint16_t rtype);
123 
124 //C++ guard
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif
uint8_t length
Definition: dtls_misc.h:149
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:540
int bool_t
Definition: compiler_port.h:49
size_t offset
Definition: mdns_common.h:80
signed int int_t
Definition: compiler_port.h:44
IP network address.
Definition: ip.h:71
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:272
systime_t timeout
Definition: mdns_common.h:86
__start_packed struct @146 DnsHeader
DNS message header.
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:889
__start_packed struct @148 DnsResourceRecord
Resource record format.
const Ipv6Addr MDNS_IPV6_MULTICAST_ADDR
Definition: mdns_common.c:59
uint8_t level
Definition: tls.h:1702
IP pseudo header.
Definition: ip.h:90
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:454
const IpPseudoHeader * pseudoHeader
Definition: mdns_common.h:82
size_t length
Definition: mdns_common.h:81
void mdnsProcessMessage(NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, void *param)
Process incoming mDNS message.
Definition: mdns_common.c:110
#define NetInterface
Definition: net.h:36
__start_packed struct @179 Ipv6Addr
IPv6 network address.
__start_packed struct @122 UdpHeader
UDP header.
void mdnsDeleteMessage(MdnsMessage *message)
release a mDNS message
Definition: mdns_common.c:430
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:178
uint8_t message[]
Definition: chap.h:152
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:783
error_t mdnsCreateMessage(MdnsMessage *message, bool_t queryResponse)
Create an empty mDNS message.
Definition: mdns_common.c:354
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:630
Ipv4Addr destIpAddr
Definition: ipcp.h:78