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_SPOOFSOCKET_H__5BAEA068_961A_4652_8BBD_90B78F6FBB09__INCLUDED_)
00037 #define AFX_SPOOFSOCKET_H__5BAEA068_961A_4652_8BBD_90B78F6FBB09__INCLUDED_
00038
00039 #if _MSC_VER > 1000
00040 #pragma once
00041 #endif // _MSC_VER > 1000
00042
00043 #include "SocketBase.h"
00044
00045 KOMODIA_NAMESPACE_START
00046
00047 class CSocket : virtual public CSocketBase
00048 {
00049 public:
00050
00051 typedef enum _SocketShutdown
00052 {
00053 ssReceive,
00054 ssSend,
00055 ssBoth
00056 } SocketShutdown;
00057
00058
00059 friend class CIPCrafter;
00060 public:
00061
00062 unsigned char GetProtocol()const;
00063
00064
00065 void SetProtocol(unsigned char iProtocol);
00066
00067
00068 BOOL IsRaw()const;
00069
00070
00071 BOOL SetReceiveTimeout(unsigned long ulMS);
00072
00073
00074 SOCKET GetHandle()const;
00075
00076
00077 virtual SOCKET Detach();
00078
00079
00080 BOOL SetBroadcast(BOOL bBroadcast);
00081
00082
00083 BOOL IsCreated()const;
00084
00085
00086 BOOL CanWrite()const;
00087
00088
00089 BOOL CanRead()const;
00090
00091
00092 unsigned short GetPeerPort()const;
00093
00094
00095 BOOL Shutdown(SocketShutdown eHow);
00096
00097
00098 long GetPeerAddress()const;
00099
00100
00101
00102
00103
00104
00105
00106 virtual int Receive(char* pBuffer,
00107 unsigned long ulBufferLength);
00108
00109
00110
00111
00112
00113
00114
00115 virtual int Peek(char* pBuffer,
00116 unsigned long ulBufferLength);
00117
00118
00119 void SetTTL(unsigned char ucTTL);
00120
00121
00122 virtual void SetSourceAddress(IP aSourceAddress);
00123 virtual void SetSourceAddress(const std::string& rSourceAddress);
00124
00125
00126 virtual BOOL Close();
00127
00128
00129 virtual IP GetBindAddress()const;
00130
00131
00132 virtual unsigned short GetBindPort()const;
00133
00134
00135 virtual BOOL Bind(const std::string& rSourceAddress,
00136 unsigned short usPort);
00137 virtual BOOL Bind(IP aSourceAddress,
00138 unsigned short usPort);
00139
00140
00141
00142
00143
00144
00145 virtual int Send(IP aDestinationAddress,
00146 const char* pBuffer,
00147 unsigned long ulBufferLength,
00148 unsigned short usDestinationPort=0);
00149 virtual int Send(const std::string& rDestinationAddress,
00150 const char* pBuffer,
00151 unsigned long ulBufferLength,
00152 unsigned short usDestinationPort=0);
00153
00154
00155 BOOL Create(int iProtocol);
00156
00157
00158 bool operator==(const CSocket& rSocket)const;
00159 bool operator<(const CSocket& rSocket)const;
00160
00161
00162 CSocket(BOOL bRawSocket=false);
00163 virtual ~CSocket();
00164 protected:
00165
00166 CSocket(SOCKET aSocket);
00167
00168
00169 void SetConnectedTo(const sockaddr_in& rAddress);
00170
00171
00172 IP GetSourceAddress()const;
00173
00174
00175 unsigned char GetTTL()const;
00176
00177
00178 BOOL CheckSocketValid()const;
00179
00180
00181 void AssignSocket(SOCKET aNewSocket,
00182 unsigned char ucProtocol=IPPROTO_TCP);
00183
00184
00185 BOOL ValidSocket()const;
00186
00187
00188 virtual void InitializeIP();
00189
00190
00191 virtual int ReceiveFrom(char* pBuffer,
00192 unsigned long ulBufferLength,
00193 IP& rIP,
00194 unsigned short& rSourcePort);
00195 private:
00196
00197 CSocket(const CSocket& rSocket);
00198
00199
00200 CSocket& operator=(const CSocket& rSocket);
00201
00202
00203 int LocalReceive(char* pBuffer,
00204 unsigned long ulBufferLength,
00205 BOOL bPeek);
00206
00207
00208 BOOL m_bRaw;
00209
00210
00211 unsigned char m_ucProtocol;
00212
00213
00214 unsigned char m_ucTTL;
00215
00216
00217 IP m_ulSourceAddress;
00218
00219
00220 SOCKET m_aSocket;
00221
00222
00223 BOOL m_bOverlapped;
00224
00225
00226 sockaddr_in m_aConnectedTo;
00227 };
00228
00229 KOMODIA_NAMESPACE_END
00230
00231 #endif // !defined(AFX_SPOOFSOCKET_H__5BAEA068_961A_4652_8BBD_90B78F6FBB09__INCLUDED_)