llmnr_common.h
Go to the documentation of this file.
1 /**
2  * @file llmnr_common.h
3  * @brief Definitions common to LLMNR client and 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.2
29  **/
30 
31 #ifndef _LLMNR_COMMON_H
32 #define _LLMNR_COMMON_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "dns/dns_common.h"
37 
38 //Default resource record TTL (cache lifetime)
39 #ifndef LLMNR_DEFAULT_RESOURCE_RECORD_TTL
40  #define LLMNR_DEFAULT_RESOURCE_RECORD_TTL 30
41 #elif (LLMNR_DEFAULT_RESOURCE_RECORD_TTL < 1)
42  #error LLMNR_DEFAULT_RESOURCE_RECORD_TTL parameter is not valid
43 #endif
44 
45 //LLMNR port number
46 #define LLMNR_PORT 5355
47 //Default IP TTL value
48 #define LLMNR_DEFAULT_IP_TTL 255
49 
50 //LLMNR IPv4 multicast group
51 #define LLMNR_IPV4_MULTICAST_ADDR IPV4_ADDR(224, 0, 0, 252)
52 
53 //C++ guard
54 #ifdef __cplusplus
55  extern "C" {
56 #endif
57 
58 
59 //CodeWarrior or Win32 compiler?
60 #if defined(__CWCC__) || defined(_WIN32)
61  #pragma pack(push, 1)
62 #endif
63 
64 
65 /**
66  * @brief LLMNR message header
67  **/
68 
69 typedef __start_packed struct
70 {
71  uint16_t id; //0-1
72 #ifdef _CPU_BIG_ENDIAN
73  uint8_t qr : 1; //2
74  uint8_t opcode : 4;
75  uint8_t c : 1;
76  uint8_t tc : 1;
77  uint8_t t : 1;
78  uint8_t z : 4; //3
79  uint8_t rcode : 4;
80 #else
81  uint8_t t : 1; //2
82  uint8_t tc : 1;
83  uint8_t c : 1;
84  uint8_t opcode : 4;
85  uint8_t qr : 1;
86  uint8_t rcode : 4; //3
87  uint8_t z : 4;
88 #endif
89  uint16_t qdcount; //4-5
90  uint16_t ancount; //6-7
91  uint16_t nscount; //8-9
92  uint16_t arcount; //10-11
93  uint8_t questions[]; //12
95 
96 
97 //CodeWarrior or Win32 compiler?
98 #if defined(__CWCC__) || defined(_WIN32)
99  #pragma pack(pop)
100 #endif
101 
102 
103 //LLMNR IPv6 multicast group
105 
106 //LLMNR related functions
107 error_t llmnrInit(NetInterface *interface);
108 
109 void llmnrProcessMessage(NetInterface *interface, const IpPseudoHeader *pseudoHeader,
110  const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, void *param);
111 
112 //C++ guard
113 #ifdef __cplusplus
114  }
115 #endif
116 
117 #endif
TCP/IP stack core.
void llmnrProcessMessage(NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, void *param)
Process incoming LLMNR message.
Definition: llmnr_common.c:101
__start_packed struct @183 Ipv6Addr
IPv6 network address.
uint8_t t
Definition: llmnr_common.h:81
uint8_t rcode
Definition: llmnr_common.h:86
uint16_t id
Definition: llmnr_common.h:71
uint8_t questions[]
Definition: llmnr_common.h:93
uint8_t tc
Definition: llmnr_common.h:82
uint16_t qdcount
Definition: llmnr_common.h:89
uint16_t nscount
Definition: llmnr_common.h:91
__start_packed struct @126 UdpHeader
UDP header.
const Ipv6Addr LLMNR_IPV6_MULTICAST_ADDR
Definition: llmnr_common.c:49
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:88
uint8_t opcode
Definition: llmnr_common.h:84
__start_packed struct _Ipv4Header __end_packed
uint8_t c
Definition: llmnr_common.h:83
error_t
Error codes.
Definition: error.h:42
#define NetInterface
Definition: net.h:36
__start_packed struct @208 LlmnrHeader
LLMNR message header.
uint16_t arcount
Definition: llmnr_common.h:92
IP pseudo header.
Definition: ip.h:78
uint8_t qr
Definition: llmnr_common.h:85
Common DNS routines.
uint8_t z
Definition: llmnr_common.h:87
uint16_t ancount
Definition: llmnr_common.h:90
error_t llmnrInit(NetInterface *interface)
LLMNR related initialization.
Definition: llmnr_common.c:59