ICMP
|
00001 /* 00002 * Icmp.h 00003 * 00004 * Copyright (c) Verax Systems. 00005 * All rights reserved. 00006 * 00007 * This software is furnished under a license. Use, duplication, 00008 * disclosure and all other uses are restricted to the rights 00009 * specified in the written license agreement. 00010 */ 00022 #ifndef __ICMP_H__ 00023 #define __ICMP_H__ 00024 00025 #include <windows.h> 00026 00027 /* Pack data structures so no data padding is used in messages/packets definitions */ 00028 #pragma pack(1) 00029 00030 #define IP_PROTOCOL_ICMP 1 00031 00032 #define ICMP_ECHOREPLY 0 00033 #define ICMP_DESTINATIONUNREACHABLE 3 00034 #define ICMP_SOURCEQUENCH 4 00035 #define ICMP_REDIRECT 5 00036 #define ICMP_ECHOREQEST 8 00037 #define ICMP_TIMEEXCEEDED 11 00038 #define ICMP_PARAMETERPROBLEM 12 00039 00043 #define IP_HEADER_LEN 20 00044 00048 #define ICMP_PAYLOAD_MIN_LEN 8 00049 00050 00054 #define ICMP_ERROR_MESSAGE_LEN (IP_HEADER_LEN + ICMP_PAYLOAD_MIN_LEN) 00055 00059 #define IP_MESSAGE_MAX_LEN 0xFFFF 00060 00064 #define ICMP_ECHO_MAX_DATA_LEN (IP_MESSAGE_MAX_LEN - ICMP_PAYLOAD_MIN_LEN - IP_HEADER_LEN) 00065 00066 00067 00071 typedef 00072 struct 00073 { 00074 UINT8 versionIhl; 00075 UINT8 tos; 00076 UINT16 length; 00077 UINT16 id; 00078 UINT16 flagsOffset; 00079 UINT8 ttl; 00080 UINT8 protocol; 00081 UINT16 checksum; 00082 struct in_addr iaddrSrc; 00083 struct in_addr iaddrDst; 00084 } IpHeader; 00085 00086 00087 00091 typedef 00092 struct 00093 { 00094 struct in_addr gatewayAddr; 00095 } IcmpRedirectQuench; 00096 00097 00101 typedef 00102 struct 00103 { 00104 UINT16 id; 00105 UINT16 seq; 00106 } IcmpEchoQuench; 00107 00108 00109 typedef 00110 union 00111 { 00112 IcmpRedirectQuench redirect; 00113 IcmpEchoQuench echo; 00114 } IcmpQuench; 00115 00119 typedef 00120 struct 00121 { 00122 UINT8 type; 00123 UINT8 code; 00124 UINT16 checksum; 00125 IcmpQuench quench; 00126 } IcmpHeader; 00127 00128 00135 typedef 00136 struct 00137 { 00138 IpHeader ipHeader; 00139 IcmpHeader icmp; 00140 } IcmpRawMessage; 00141 00142 00149 typedef 00150 union 00151 { 00152 IcmpRawMessage packet; 00153 UINT8 buffer[ICMP_ECHO_MAX_DATA_LEN]; 00154 } IcmpData; 00155 00156 00162 typedef 00163 struct 00164 { 00165 IcmpHeader header; 00166 IcmpData data; 00167 } IcmpMessage; 00168 00169 00175 typedef 00176 struct 00177 { 00178 IpHeader ipHeader; 00179 IcmpMessage icmp; 00180 } IcmpResponseMessage; 00181 00182 00183 #pragma pack() 00184 00198 int IcmpInitialize(void); 00199 00200 00204 void IcmpRelease(void); 00205 00206 00215 SOCKET IcmpCreateSocket(void); 00216 00217 00227 int IcmpCloseSocket(SOCKET socket); 00228 00229 00241 int IcmpWait(SOCKET socket, long timeout); 00242 00243 00260 int IcmpSendEcho(SOCKET socket, const INT8 *destAddress, UINT16 identifier, UINT16 sequenceNumber, void *dataBuffer, size_t dataLength); 00261 00262 00275 int IcmpReadMessage(SOCKET socket, IcmpResponseMessage *response); 00276 00277 00296 BOOL IcmpDecodeResponseMessage(const IcmpResponseMessage *message, UINT8 *srcAddress, UINT8 *dstAddress, UINT8 *type, UINT8 *code, UINT16 *identifier, UINT16 *sequenceNumber, void *dataBuffer, size_t dataBuffferLength, size_t *dataLength); 00297 00298 00307 int IcmpGetSocketError(SOCKET socket); 00308 00309 00317 int IcmpGetLastError(void); 00318 00319 00331 LPTSTR IcmpGetErrorString(int errorCode); 00332 00333 00339 void IcmpReleaseErrorString(LPTSTR errorStr); 00340 00341 #endif