00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #if !defined(AFX_ICMPSOCKET_H__543E6F8C_42FA_4317_B799_0056E8B44467__INCLUDED_)
00037 #define AFX_ICMPSOCKET_H__543E6F8C_42FA_4317_B799_0056E8B44467__INCLUDED_
00038
00039 #if _MSC_VER > 1000
00040 #pragma once
00041 #endif // _MSC_VER > 1000
00042
00043 #include "SpoofSocket.h"
00044
00045 KOMODIA_NAMESPACE_START
00046
00047
00048 typedef struct _ICMPHeader
00049 {
00050 unsigned char ucICMPType;
00051 unsigned char ucICMPCode;
00052 unsigned short usICMPChecksum;
00053 union
00054 {
00055 struct {unsigned char uc1,uc2,uc3,uc4;} sUC;
00056 struct {unsigned short us1,us2;} sUS;
00057 unsigned long sUL;
00058 } sICMP;
00059 unsigned long ulICMP_Originate_Timestamp;
00060 unsigned long ulICMP_Receive_Timestamp;
00061 unsigned long ulICMP_Transmit_Timestamp;
00062 } ICMPHeader;
00063
00064 typedef ICMPHeader FAR * LPICMPHeader;
00065
00066 #define ICMPHeaderLength sizeof(ICMPHeader)
00067
00068
00069 #define ICMP_DATA_SIZE 8
00070
00071
00072 #define ICMP_Unreachable 3
00073 #define ICMP_Unreachable_SIZE 8
00074
00075 #define ICMP_Unreachable_NET 0
00076 #define ICMP_Unreachable_HOST 1
00077 #define ICMP_Unreachable_PROTOCOL 2
00078 #define ICMP_Unreachable_PORT 3
00079 #define ICMP_Unreachable_FRAGMENTATION 4
00080 #define ICMP_Unreachable_SOURCE 5
00081
00082
00083 #define ICMP_Time 11
00084
00085 #define ICMP_Time_TRANSIT 0
00086 #define ICMP_Time_FRAGMENT 1
00087
00088
00089 #define ICMP_Parameter 12
00090
00091 #define ICMP_Parameter_ERROR 0
00092
00093
00094 #define ICMP_Quench 4
00095
00096
00097 #define ICMP_Redirect 5
00098
00099 #define ICMP_Redirect_NETWORK 0
00100 #define ICMP_Redirect_HOST 1
00101 #define ICMP_Redirect_SERVICE_NETWORK 2
00102 #define ICMP_Redirect_SERVICE_HOST 3
00103
00104
00105 #define ICMP_Echo 8
00106 #define ICMP_Echo_Reply 0
00107
00108
00109 #define ICMP_Timestamp 13
00110 #define ICMP_Timestamp_Reply 14
00111
00112
00113 #define ICMP_Information 15
00114 #define ICMP_Information_Reply 16
00115
00116 #define ICMP_Information_SIZE 8
00117
00118
00119 #define ICMP_BUF 100
00120
00121 class CICMPSocket : public CSpoofSocket
00122 {
00123 public:
00124
00125
00126
00127 void SetSendBuffer(const char* pBuffer,
00128 unsigned short usSendSize);
00129
00130
00131 const LPIpHeader GetLastICMPIPHeader()const;
00132
00133
00134 const LPICMPHeader GetLastICMPICMPHeader()const;
00135
00136
00137 unsigned long GetLastDataSize();
00138
00139
00140 const char* GetLastData()const;
00141
00142
00143 const LPIpHeader GetLastIPHeader()const;
00144
00145
00146 const LPICMPHeader GetLastICMPHeader()const;
00147
00148
00149 BOOL SendInformation(const std::string& rDestinationAddress,
00150 BOOL bReply,
00151 unsigned short usIdentifier,
00152 unsigned short usSequence);
00153 BOOL SendInformation(IP aDestinationAddress,
00154 BOOL bReply,
00155 unsigned short usIdentifier,
00156 unsigned short usSequence);
00157
00158 BOOL SendTimestamp(const std::string& rDestinationAddress,
00159 BOOL bReply,
00160 unsigned short usIdentifier,
00161 unsigned short usSequence,
00162 unsigned long ulOriginateTimestamp,
00163 unsigned long ulReceiveTimestamp,
00164 unsigned long ulTransmitTimestamp);
00165 BOOL SendTimestamp(IP aDestinationAddress,
00166 BOOL bReply,
00167 unsigned short usIdentifier,
00168 unsigned short usSequence,
00169 unsigned long ulOriginateTimestamp,
00170 unsigned long ulReceiveTimestamp,
00171 unsigned long ulTransmitTimestamp);
00172
00173 BOOL SendEcho(const std::string& rDestinationAddress,
00174 BOOL bReply,
00175 unsigned short usIdentifier,
00176 unsigned short usSequence,
00177 unsigned long ulData);
00178 BOOL SendEcho(IP aDestinationAddress,
00179 BOOL bReply,
00180 unsigned short usIdentifier,
00181 unsigned short usSequence,
00182 unsigned long ulData);
00183
00184 BOOL SendRedirect(const std::string& rDestinationAddress,
00185 unsigned char ucType,
00186 const std::string& rGatewayAddress);
00187 BOOL SendRedirect(IP aDestinationAddress,
00188 unsigned char ucType,
00189 IP aGatewayAddress);
00190
00191 BOOL SendQuench(const std::string& rDestinationAddress);
00192 BOOL SendQuench(IP aDestinationAddress);
00193
00194 BOOL SendParameter(const std::string& rDestinationAddress,
00195 unsigned char ucError);
00196 BOOL SendParameter(IP aDestinationAddress,
00197 unsigned char ucError);
00198
00199 BOOL SendTime(const std::string& rDestinationAddress,
00200 unsigned char ucType);
00201 BOOL SendTime(IP aDestinationAddress,
00202 unsigned char ucType);
00203
00204 BOOL SendUnreachable(const std::string& rDestinationAddress,
00205 unsigned char ucType);
00206 BOOL SendUnreachable(IP aDestinationAddress,
00207 unsigned char ucType);
00208
00209
00210 virtual BOOL Create();
00211
00212
00213 CICMPSocket(BOOL bRawSocket);
00214 virtual ~CICMPSocket();
00215 protected:
00216
00217 const char* GetSendBuffer()const;
00218
00219
00220 int GetBufferSize()const;
00221
00222
00223 virtual void FinalICMPHeader(LPICMPHeader lpHead)const;
00224
00225
00226 BOOL SendICMP(LPICMPHeader lpHead,
00227 const std::string& rDestinationAddress);
00228 BOOL SendICMP(LPICMPHeader lpHead,
00229 IP aDestinationAddress);
00230
00231
00232 virtual LPICMPHeader ConstructICMP()const;
00233
00234
00235 virtual BOOL ProccessICMP(const char* pBuffer);
00236 private:
00237
00238 CICMPSocket(const CICMPSocket& rICMP);
00239
00240
00241 CICMPSocket& operator=(CICMPSocket& rSocket);
00242
00243
00244 void ReverseHeader(LPICMPHeader pHeader);
00245
00246
00247 BOOL Send(IP aDestinationAddress,
00248 unsigned char cICMP,
00249 unsigned char ucType);
00250
00251
00252 LPIpHeader m_pICMPIPHeader;
00253
00254
00255 LPICMPHeader m_pICMPICMPHeader;
00256
00257
00258 unsigned short m_usDataSize;
00259
00260
00261 LPIpHeader m_pIPHeader;
00262
00263
00264 LPICMPHeader m_pICMPHeader;
00265
00266
00267 const char* m_pSendBuffer;
00268
00269
00270 unsigned short m_usBufferSendSize;
00271
00272
00273 char* m_pICMPReceiveData;
00274 };
00275
00276 KOMODIA_NAMESPACE_END
00277
00278 #endif // !defined(AFX_ICMPSOCKET_H__543E6F8C_42FA_4317_B799_0056E8B44467__INCLUDED_)