icmp.h
Go to the documentation of this file.
1 /**
2  * @file icmp.h
3  * @brief ICMP (Internet Control Message Protocol)
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 _ICMP_H
30 #define _ICMP_H
31 
32 //Dependencies
33 #include "core/net.h"
34 
35 //C++ guard
36 #ifdef __cplusplus
37  extern "C" {
38 #endif
39 
40 
41 /**
42  * @brief ICMP message type
43  *
44  * The type field indicates the type of the message. Its
45  * value determines the format of the remaining data
46  *
47  **/
48 
49 typedef enum
50 {
64 } IcmpType;
65 
66 
67 /**
68  * @brief Destination Unreachable message codes
69  **/
70 
71 typedef enum
72 {
80 
81 
82 /**
83  * @brief Time Exceeded message codes
84  **/
85 
86 typedef enum
87 {
91 
92 
93 //CodeWarrior or Win32 compiler?
94 #if defined(__CWCC__) || defined(_WIN32)
95  #pragma pack(push, 1)
96 #endif
97 
98 
99 /**
100  * @brief ICMP header
101  **/
102 
103 typedef __start_packed struct
104 {
105  uint8_t type; //0
106  uint8_t code; //1
107  uint16_t checksum; //2-3
108  uint8_t data[]; //4
110 
111 
112 /**
113  * @brief ICMP Error message
114  **/
115 
116 typedef __start_packed struct
117 {
118  uint8_t type; //0
119  uint8_t code; //1
120  uint16_t checksum; //2-3
121  uint32_t parameter : 8; //4
122  uint32_t unused : 24; //5-7
123  uint8_t data[]; //8
125 
126 
127 /**
128  * @brief ICMP Destination Unreachable message
129  **/
130 
131 typedef __start_packed struct
132 {
133  uint8_t type; //0
134  uint8_t code; //1
135  uint16_t checksum; //2-3
136  uint32_t unused; //4-7
137  uint8_t data[]; //8
139 
140 
141 /**
142  * @brief ICMP Time Exceeded message
143  **/
144 
145 typedef __start_packed struct
146 {
147  uint8_t type; //0
148  uint8_t code; //1
149  uint16_t checksum; //2-3
150  uint32_t unused; //4-7
151  uint8_t data[]; //8
153 
154 
155 /**
156  * @brief ICMP Parameter Problem message
157  **/
158 
159 typedef __start_packed struct
160 {
161  uint8_t type; //0
162  uint8_t code; //1
163  uint16_t checksum; //2-3
164  uint32_t pointer : 8; //4
165  uint32_t unused : 24; //5-7
166  uint8_t data[]; //8
168 
169 
170 /**
171  * @brief ICMP Echo Request and Echo Reply messages
172  **/
173 
174 typedef __start_packed struct
175 {
176  uint8_t type; //0
177  uint8_t code; //1
178  uint16_t checksum; //2-3
179  uint16_t identifier; //4-5
180  uint16_t sequenceNumber; //6-7
181  uint8_t data[]; //8
183 
184 
185 //CodeWarrior or Win32 compiler?
186 #if defined(__CWCC__) || defined(_WIN32)
187  #pragma pack(pop)
188 #endif
189 
190 
191 //ICMP related functions
192 void icmpProcessMessage(NetInterface *interface,
193  Ipv4Addr srcIpAddr, const NetBuffer *buffer, size_t offset);
194 
195 void icmpProcessEchoRequest(NetInterface *interface,
196  Ipv4Addr srcIpAddr, const NetBuffer *request, size_t requestOffset);
197 
198 error_t icmpSendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code,
199  uint8_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset);
200 
201 void icmpUpdateInStats(uint8_t type);
202 void icmpUpdateOutStats(uint8_t type);
203 
204 void icmpDumpMessage(const IcmpHeader *message);
207 
208 //C++ guard
209 #ifdef __cplusplus
210  }
211 #endif
212 
213 #endif
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:232
uint8_t code
Definition: icmp.h:106
__start_packed struct @172 IcmpEchoMessage
ICMP Echo Request and Echo Reply messages.
uint16_t checksum
Definition: icmp.h:107
__start_packed struct @171 IcmpParamProblemMessage
ICMP Parameter Problem message.
void icmpProcessMessage(NetInterface *interface, Ipv4Addr srcIpAddr, const NetBuffer *buffer, size_t offset)
Incoming ICMP message processing.
Definition: icmp.c:54
void icmpDumpErrorMessage(const IcmpErrorMessage *message)
Dump generic ICMP Error message.
Definition: icmp.c:487
TCP/IP stack core.
uint8_t message[]
Definition: chap.h:150
uint32_t pointer
Definition: icmp.h:164
void icmpDumpMessage(const IcmpHeader *message)
Dump ICMP message for debugging purpose.
Definition: icmp.c:457
IcmpTimeExceededCode
Time Exceeded message codes.
Definition: icmp.h:86
IcmpDestUnreachableCode
Destination Unreachable message codes.
Definition: icmp.h:71
uint8_t ipPacket[]
Definition: ndp.h:427
uint32_t parameter
Definition: icmp.h:121
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
uint16_t sequenceNumber
Definition: icmp.h:180
__start_packed struct @167 IcmpHeader
ICMP header.
uint32_t unused
Definition: icmp.h:122
void icmpProcessEchoRequest(NetInterface *interface, Ipv4Addr srcIpAddr, const NetBuffer *request, size_t requestOffset)
Echo Request message processing.
Definition: icmp.c:134
void icmpDumpEchoMessage(const IcmpEchoMessage *message)
Dump ICMP Echo Request or Echo Reply message.
Definition: icmp.c:471
Ipv4Addr srcIpAddr
Definition: ipcp.h:75
__start_packed struct _Ipv4Header __end_packed
__start_packed struct @169 IcmpDestUnreachableMessage
ICMP Destination Unreachable message.
error_t
Error codes.
Definition: error.h:40
uint8_t type
Definition: icmp.h:105
#define NetInterface
Definition: net.h:34
__start_packed struct @170 IcmpTimeExceededMessage
ICMP Time Exceeded message.
error_t icmpSendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code, uint8_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset)
Send an ICMP Error message.
Definition: icmp.c:230
uint8_t data[]
Definition: icmp.h:108
void icmpUpdateInStats(uint8_t type)
Update ICMP input statistics.
Definition: icmp.c:325
uint16_t identifier
Definition: icmp.h:179
void icmpUpdateOutStats(uint8_t type)
Update ICMP output statistics.
Definition: icmp.c:389
IcmpType
ICMP message type.
Definition: icmp.h:49
__start_packed struct @168 IcmpErrorMessage
ICMP Error message.