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