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_TCPSOCKET_H__77DA7F21_291E_4C2A_B12B_535ABA1E829C__INCLUDED_)
00037 #define AFX_TCPSOCKET_H__77DA7F21_291E_4C2A_B12B_535ABA1E829C__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
00049
00050
00051
00052
00053
00054
00055 typedef struct _TCPHeader
00056 {
00057 unsigned short usSourcePort;
00058 unsigned short usDestinationPort;
00059 unsigned long ulSequenceNumber;
00060 unsigned long ulAcknowledgeNumber;
00061 unsigned char ucDataOffset;
00062 unsigned char ucFlags;
00063 unsigned short usWindows;
00064 unsigned short usChecksum;
00065 unsigned short usUrgentPointer;
00066 } TCPHeader;
00067
00068 typedef TCPHeader FAR * LPTCPHeader;
00069
00070 #define TCPHeaderLength sizeof(TCPHeader)
00071
00072
00073 #define TCPFlag_URG 0x20
00074 #define TCPFlag_ACK 0x10
00075 #define TCPFlag_PSH 0x08
00076 #define TCPFlag_RST 0x04
00077 #define TCPFlag_SYN 0x02
00078 #define TCPFlag_FYN 0x01
00079
00080
00081 #define TCPOptions_END 0
00082 #define TCPOptions_NO_OPERATION 1
00083 #define TCPOptions_MAX_Segment 2
00084
00085
00086 #define TCPOptions_MAX_Segment_Length 4
00087
00088 class CTCPOptions : protected CIPOptions
00089 {
00090 public:
00091
00092 void AddOption_SegmentSize(unsigned short usMax);
00093
00094
00095 void Reset();
00096
00097
00098 void SetAutoPad(BOOL bAutoPAD);
00099
00100
00101 virtual void AddOption_ENDLIST();
00102
00103
00104 int GetBufferLength()const;
00105
00106
00107 const char* GetBuffer()const;
00108
00109
00110 virtual void AddOption_Nothing();
00111
00112
00113 CTCPOptions();
00114 CTCPOptions(const CTCPOptions& rOptions);
00115 virtual ~CTCPOptions();
00116 private:
00117
00118 CTCPOptions& operator=(const CTCPOptions& rOptions);
00119 };
00120
00121 class CTCPSocket : public CSpoofSocket
00122 {
00123 public:
00124
00125 BOOL SetNagle(BOOL bNagle);
00126
00127
00128 virtual BOOL Close();
00129
00130
00131 BOOL IsConnected()const;
00132
00133
00134
00135
00136
00137 virtual int Send(const char* pBuffer,
00138 unsigned long ulBufferLength);
00139
00140
00141 BOOL Accept(CTCPSocket* pNewSocket);
00142
00143
00144 CTCPSocket* Accept();
00145
00146
00147 virtual BOOL Listen(unsigned long ulBackLog=5);
00148
00149
00150 CTCPOptions* GetTCPOptions()const;
00151
00152
00153
00154
00155 virtual BOOL Connect(unsigned short usSourcePort,
00156 IP aDestinationAddress,
00157 unsigned short usDestinationPort);
00158 virtual BOOL Connect(unsigned short usSourcePort,
00159 const std::string& rDestinationAddress,
00160 unsigned short usDestinationPort);
00161
00162
00163
00164 virtual BOOL Connect(IP aDestinationAddress,
00165 unsigned short usDestinationPort);
00166 virtual BOOL Connect(const std::string& rDestinationAddress,
00167 unsigned short usDestinationPort);
00168
00169
00170 virtual BOOL Create();
00171
00172
00173 void SetTCPOptions(BOOL bOptions);
00174
00175
00176 CTCPSocket(BOOL bRawSocket);
00177 virtual ~CTCPSocket();
00178 protected:
00179
00180 virtual void BeforeAccept();
00181
00182
00183 virtual BOOL IsAsyncClass()const;
00184
00185
00186 void SetConnectionStatus(BOOL bConnected);
00187
00188
00189 virtual void Accepted();
00190
00191
00192 virtual LPTCPHeader ConstructTCPHeader(unsigned short usSourcePort,
00193 unsigned short usDestinationPort,
00194 unsigned char ucHeaderLength)const;
00195
00196
00197 virtual void FinalTCPHeader(LPTCPHeader lpHead)const;
00198
00199
00200
00201
00202
00203 virtual int SendRaw(unsigned short usSourcePort,
00204 IP aDestinationAddress,
00205 unsigned short usDestinationPort,
00206 const char* pBuffer,
00207 unsigned long ulBufferLength,
00208 unsigned char ucFlags=0);
00209
00210
00211
00212
00213
00214 virtual int SendRaw(unsigned short usSourcePort,
00215 const std::string& rDestinationAddress,
00216 unsigned short usDestinationPort,
00217 const char* pBuffer,
00218 unsigned long ulBufferLength,
00219 unsigned char ucFlags=0);
00220 private:
00221
00222 CTCPSocket(SOCKET aSocket);
00223
00224
00225 CTCPSocket(const CTCPSocket& rSocket);
00226
00227
00228 CTCPSocket& operator=(const CTCPSocket& rSocket);
00229
00230
00231 void InitializeTCP();
00232
00233
00234 void SetHeaderFlag(LPTCPHeader lpHead,
00235 unsigned char ucFlags);
00236
00237
00238 CTCPOptions* m_pTCPOptions;
00239
00240
00241 BOOL m_bOptions;
00242
00243
00244 static unsigned int m_uiSequence;
00245
00246
00247 BOOL m_bConnected;
00248 };
00249
00250 KOMODIA_NAMESPACE_END
00251
00252 #endif // !defined(AFX_TCPSOCKET_H__77DA7F21_291E_4C2A_B12B_535ABA1E829C__INCLUDED_)