Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
icmp.h
00001 /** 00002 * @file icmp.h 00003 * @brief ICMP (Internet Control Message Protocol) 00004 * 00005 * @section License 00006 * 00007 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. 00008 * 00009 * This file is part of CycloneTCP Open. 00010 * 00011 * This program is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU General Public License 00013 * as published by the Free Software Foundation; either version 2 00014 * of the License, or (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software Foundation, 00023 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00024 * 00025 * @author Oryx Embedded SARL (www.oryx-embedded.com) 00026 * @version 1.7.6 00027 **/ 00028 00029 #ifndef _ICMP_H 00030 #define _ICMP_H 00031 00032 //Dependencies 00033 #include "core/net.h" 00034 00035 00036 /** 00037 * @brief ICMP message type 00038 * 00039 * The type field indicates the type of the message. Its 00040 * value determines the format of the remaining data 00041 * 00042 **/ 00043 00044 typedef enum 00045 { 00046 ICMP_TYPE_ECHO_REPLY = 0, 00047 ICMP_TYPE_DEST_UNREACHABLE = 3, 00048 ICMP_TYPE_SOURCE_QUENCH = 4, 00049 ICMP_TYPE_REDIRECT = 5, 00050 ICMP_TYPE_ECHO_REQUEST = 8, 00051 ICMP_TYPE_TIME_EXCEEDED = 11, 00052 ICMP_TYPE_PARAM_PROBLEM = 12, 00053 ICMP_TYPE_TIMESTAMP_REQUEST = 13, 00054 ICMP_TYPE_TIMESTAMP_REPLY = 14, 00055 ICMP_TYPE_INFO_REQUEST = 15, 00056 ICMP_TYPE_INFO_REPLY = 16 00057 } IcmpType; 00058 00059 00060 /** 00061 * @brief Destination Unreachable message codes 00062 **/ 00063 00064 typedef enum 00065 { 00066 ICMP_CODE_NET_UNREACHABLE = 0, 00067 ICMP_CODE_HOST_UNREACHABLE = 1, 00068 ICMP_CODE_PROTOCOL_UNREACHABLE = 2, 00069 ICMP_CODE_PORT_UNREACHABLE = 3, 00070 ICMP_CODE_FRAG_NEEDED_AND_DF_SET = 4, 00071 ICMP_CODE_SOURCE_ROUTE_FAILED = 5 00072 } IcmpDestUnreachableCode; 00073 00074 00075 /** 00076 * @brief Time Exceeded message codes 00077 **/ 00078 00079 typedef enum 00080 { 00081 ICMP_CODE_TTL_EXCEEDED = 0, 00082 ICMP_CODE_REASSEMBLY_TIME_EXCEEDED = 1 00083 } IcmpTimeExceededCode; 00084 00085 00086 //CodeWarrior or Win32 compiler? 00087 #if defined(__CWCC__) || defined(_WIN32) 00088 #pragma pack(push, 1) 00089 #endif 00090 00091 00092 /** 00093 * @brief ICMP header 00094 **/ 00095 00096 typedef __start_packed struct 00097 { 00098 uint8_t type; //0 00099 uint8_t code; //1 00100 uint16_t checksum; //2-3 00101 uint8_t data[]; //4 00102 } __end_packed IcmpHeader; 00103 00104 00105 /** 00106 * @brief ICMP Error message 00107 **/ 00108 00109 typedef __start_packed struct 00110 { 00111 uint8_t type; //0 00112 uint8_t code; //1 00113 uint16_t checksum; //2-3 00114 uint32_t parameter : 8; //4 00115 uint32_t unused : 24; //5-7 00116 uint8_t data[]; //8 00117 } __end_packed IcmpErrorMessage; 00118 00119 00120 /** 00121 * @brief ICMP Destination Unreachable message 00122 **/ 00123 00124 typedef __start_packed struct 00125 { 00126 uint8_t type; //0 00127 uint8_t code; //1 00128 uint16_t checksum; //2-3 00129 uint32_t unused; //4-7 00130 uint8_t data[]; //8 00131 } __end_packed IcmpDestUnreachableMessage; 00132 00133 00134 /** 00135 * @brief ICMP Time Exceeded message 00136 **/ 00137 00138 typedef __start_packed struct 00139 { 00140 uint8_t type; //0 00141 uint8_t code; //1 00142 uint16_t checksum; //2-3 00143 uint32_t unused; //4-7 00144 uint8_t data[]; //8 00145 } __end_packed IcmpTimeExceededMessage; 00146 00147 00148 /** 00149 * @brief ICMP Parameter Problem message 00150 **/ 00151 00152 typedef __start_packed struct 00153 { 00154 uint8_t type; //0 00155 uint8_t code; //1 00156 uint16_t checksum; //2-3 00157 uint32_t pointer : 8; //4 00158 uint32_t unused : 24; //5-7 00159 uint8_t data[]; //8 00160 } __end_packed IcmpParamProblemMessage; 00161 00162 00163 /** 00164 * @brief ICMP Echo Request and Echo Reply messages 00165 **/ 00166 00167 typedef __start_packed struct 00168 { 00169 uint8_t type; //0 00170 uint8_t code; //1 00171 uint16_t checksum; //2-3 00172 uint16_t identifier; //4-5 00173 uint16_t sequenceNumber; //6-7 00174 uint8_t data[]; //8 00175 } __end_packed IcmpEchoMessage; 00176 00177 00178 //CodeWarrior or Win32 compiler? 00179 #if defined(__CWCC__) || defined(_WIN32) 00180 #pragma pack(pop) 00181 #endif 00182 00183 00184 //ICMP related functions 00185 void icmpProcessMessage(NetInterface *interface, 00186 Ipv4Addr srcIpAddr, const NetBuffer *buffer, size_t offset); 00187 00188 void icmpProcessEchoRequest(NetInterface *interface, 00189 Ipv4Addr srcIpAddr, const NetBuffer *request, size_t requestOffset); 00190 00191 error_t icmpSendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code, 00192 uint8_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset); 00193 00194 void icmpDumpMessage(const IcmpHeader *message); 00195 void icmpDumpEchoMessage(const IcmpEchoMessage *message); 00196 void icmpDumpErrorMessage(const IcmpErrorMessage *message); 00197 00198 #endif 00199
Generated on Tue Jul 12 2022 17:10:13 by
1.7.2