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-2024 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 2.4.4
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 mDNS messages
39 #ifndef MDNS_MESSAGE_MAX_SIZE
40  #define MDNS_MESSAGE_MAX_SIZE 1232
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,
120  const DnsResourceRecord *record1, const MdnsMessage *message2,
121  const DnsResourceRecord *record2);
122 
124  const char_t *instance, const char_t *service, const char_t *domain,
125  uint16_t rtype, const uint8_t *rdata, size_t rdlength);
126 
127 //C++ guard
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif
int_t mdnsCompareRecord(const MdnsMessage *message1, const DnsResourceRecord *record1, const MdnsMessage *message2, const DnsResourceRecord *record2)
Compare resource records.
Definition: mdns_common.c:799
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:544
int bool_t
Definition: compiler_port.h:53
size_t offset
Definition: mdns_common.h:80
signed int int_t
Definition: compiler_port.h:49
IP network address.
Definition: ip.h:90
uint_t sharedRecordCount
Definition: mdns_common.h:87
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t message[]
Definition: chap.h:154
NetBuffer * buffer
Definition: mdns_common.h:79
bool_t mdnsCheckSourceAddr(NetInterface *interface, const IpPseudoHeader *pseudoHeader)
Source address check.
Definition: mdns_common.c:275
systime_t timeout
Definition: mdns_common.h:86
Ipv6Addr
Definition: ipv6.h:260
DnsHeader * dnsHeader
Definition: mdns_common.h:84
DnsHeader
Definition: dns_common.h:199
uint16_t destPort
Definition: tcp.h:340
uint16_t rdlength
Definition: dns_common.h:222
const Ipv6Addr MDNS_IPV6_MULTICAST_ADDR
Definition: mdns_common.c:59
IP pseudo header.
Definition: ip.h:110
error_t
Error codes.
Definition: error.h:43
error_t mdnsSendMessage(NetInterface *interface, const MdnsMessage *message, const IpAddr *destIpAddr, uint_t destPort)
Send mDNS message.
Definition: mdns_common.c:458
bool_t mdnsCheckDuplicateRecord(const MdnsMessage *message, const char_t *instance, const char_t *service, const char_t *domain, uint16_t rtype, const uint8_t *rdata, size_t rdlength)
Check for duplicate resource records.
Definition: mdns_common.c:921
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
uint8_t length
Definition: tcp.h:368
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
UdpHeader
Definition: udp.h:85
uint32_t systime_t
System time.
mDNS message
Definition: mdns_common.h:78
char char_t
Definition: compiler_port.h:48
const UdpHeader * udpHeader
Definition: mdns_common.h:83
void mdnsProcessResponse(NetInterface *interface, MdnsMessage *response)
Process mDNS response message.
Definition: mdns_common.c:180
uint8_t rdata[]
Definition: dns_common.h:223
error_t mdnsCreateMessage(MdnsMessage *message, bool_t queryResponse)
Create an empty mDNS message.
Definition: mdns_common.c:357
unsigned int uint_t
Definition: compiler_port.h:50
TCP/IP stack core.
DnsResourceRecord
Definition: dns_common.h:224
error_t mdnsInit(NetInterface *interface)
mDNS related initialization
Definition: mdns_common.c:69
systime_t timestamp
Definition: mdns_common.h:85
Common DNS routines.
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:648
Ipv4Addr destIpAddr
Definition: ipcp.h:80