Retail products


Traffic interception SDK

Control every TCP/IP network connection

  • Route connections via proxy
  • Redirect connections and modify the data
  • Block connections and applications
SSL interception SDK

View SSL in plaintext and modify it

  • View the SSL stream decrypted in plaintext
  • Redirect SSL connection and modify decrypted data
  • Browser shows "SSL lock" without warnings

Documentation


CWhoisSocket Class Reference

#include <WhoisSocket.h>

Inheritance diagram for CWhoisSocket:
Collaboration diagram for CWhoisSocket:

List of all members.


Public Types

enum  _WhoisServer {
  wsNone, wsArin, wsApnic, wsRipe,
  wsLast
}
typedef enum
CWhoisSocket::_WhoisServer 
WhoisServer
typedef std::vector< std::string > AddressVector

Public Member Functions

const std::string & GetLastTarget () const
const std::string & GetAdditionalWhoisServer () const
BOOL IsIPTrace () const
void SetWhoisTimeout (DWORD dwMS)
const std::string & GetWhoisData () const
virtual BOOL IsError () const
virtual BOOL IsWhoisDone () const
virtual BOOL Create ()
BOOL WhoisURL (const std::string &rURL)
BOOL WhoisURL (const std::string &rURL, const std::string &rWhoisServer)
BOOL WhoisIP (const std::string &rIP)
BOOL WhoisIP (IP aAddress)
BOOL WhoisIP (IP aAddress, const std::string &rWhoisServer)
 CWhoisSocket (BOOL bAsync)
virtual ~CWhoisSocket ()
BOOL SetConnectionTimeout (unsigned long ulMS)
virtual int Send (const char *pBuffer, unsigned long ulBufferLength)
virtual int Send (IP aDestinationAddress, const char *pBuffer, unsigned long ulBufferLength, unsigned short usDestinationPort=0)
virtual int Send (const std::string &rDestinationAddress, const char *pBuffer, unsigned long ulBufferLength, unsigned short usDestinationPort=0)
virtual BOOL Close ()
virtual int Receive (char *pBuffer, unsigned long ulBufferLength)
virtual BOOL Connect (IP aDestinationAddress, unsigned short usDestinationPort, BOOL bDisableAsync=FALSE, BOOL bForceErrorEvent=FALSE)
virtual BOOL Connect (const std::string &rDestinationAddress, unsigned short usDestinationPort, BOOL bDisableAsync=FALSE, BOOL bForceErrorEvent=FALSE)
virtual BOOL Connect (unsigned short usSourcePort, IP aDestinationAddress, unsigned short usDestinationPort, BOOL bDisableAsync=FALSE, BOOL bForceErrorEvent=FALSE)
virtual BOOL Connect (unsigned short usSourcePort, const std::string &rDestinationAddress, unsigned short usDestinationPort, BOOL bDisableAsync=FALSE, BOOL bForceErrorEvent=FALSE)
virtual BOOL Connect (unsigned short usSourcePort, IP aDestinationAddress, unsigned short usDestinationPort)
virtual BOOL Connect (unsigned short usSourcePort, const std::string &rDestinationAddress, unsigned short usDestinationPort)
virtual BOOL Connect (IP aDestinationAddress, unsigned short usDestinationPort)
virtual BOOL Connect (const std::string &rDestinationAddress, unsigned short usDestinationPort)
virtual BOOL Listen (unsigned long ulBackLog=5)
BOOL Create (int iProtocol)
BOOL SetNagle (BOOL bNagle)
BOOL IsConnected () const
BOOL Accept (CTCPSocket *pNewSocket)
CTCPSocketAccept ()
CTCPOptionsGetTCPOptions () const
void SetTCPOptions (BOOL bOptions)
BOOL SetReceiveTimeout (unsigned long ulMS)
SOCKET GetHandle () const
BOOL SetBroadcast (BOOL bBroadcast)
BOOL IsCreated () const
BOOL CanWrite () const
BOOL CanRead () const
unsigned short GetPeerPort () const
BOOL Shutdown (SocketShutdown eHow)
long GetPeerAddress () const
virtual BOOL Sniff (BOOL bSniff)
CIPOptionsGetOptions () const
void SetOptions (BOOL bOptions)
void SetTTL (unsigned char ucTTL)
unsigned short CalculatePseudoChecksum (const char *pBuffer, int iBufferLength, IP aDestinationAddress, int iPacketLength) const
virtual void SetSourceAddress (IP aSourceAddress)
virtual void SetSourceAddress (const std::string &rSourceAddress)
virtual BOOL Bind (const std::string &rSourceAddress, unsigned short usPort)
virtual BOOL Bind (IP aSourceAddress, unsigned short usPort)
virtual int SendRawBuffer (IP aDestinationAddress, const char *pBuffer, unsigned long ulBufferLength, unsigned short usDestinationPort)
bool operator== (const CSpoofSocket &rSocket) const
bool operator< (const CSpoofSocket &rSocket) const
int GetSystemLastError () const
int GetLastError () const
void SetLocalLog (CErrorLog *pLog)
BOOL HasTimeout () const
void DisableEvents (unsigned char ucEvents)
BOOL IsClosing () const
void ForceReceiveEvent ()
virtual void DeleteSocketFromThread ()
virtual void DeleteSocketFromThread (DWORD dwTimeToWait)
void AllowBlockedBuffer (BOOL bAllow)
virtual BOOL ReAsync ()
virtual BOOL ReBlock ()
void FreezeThread ()
BOOL DisableAsync ()
BOOL KillTimer ()
BOOL SetTimeout (int iMs)

Static Public Member Functions

static std::string GetAddressForWhois (const std::string &rAddress)
static AddressVector AnalyzeAddress (const std::string &rAddress)
static void Shutdown ()
static long ResolveDNS (const std::string &rAddress)
static BOOL ValidAddress (const std::string &rAddress)
static LPIpHeader ConstructStaticIPHeader (unsigned char ucProtocol, unsigned short usFragmentationFlags, unsigned char ucTTL, unsigned short usIdentification, unsigned char ucHeaderLength)
static unsigned short CalculateChecksum (const unsigned short *pBuffer, int iSize)
static int GetErrorCode ()
static BOOL IsInitialized ()
static unsigned long StringToLong (const std::string &rAddress)
static char FAR * LongToString (unsigned long ulAddr)
static std::string LongToStdString (unsigned long ulAddr)
static BOOL InitializeSockets (BOOL bMultiThreaded=TRUE, unsigned long ulNumberOfThreads=10)
static BOOL InitializeSocketsNoMap (BOOL bMultiThreaded=TRUE, unsigned long ulNumberOfThreads=10)
static BOOL ShutdownSockets ()
static unsigned long GetNumberOfThreads ()
static BOOL IsMultiThreaded ()
static CGenericCriticalSectionGetGlobalCriticalSection ()
static std::string GetCurrentDateTime ()
static std::string ErrorCodeToString (DWORD dwErrorCode)
static void SetLog (CErrorLog *pLog)
static void SimpleMessageMap ()
static void SimpleMessageMap (DWORD dwRunTimeMS)
static void SimpleMessageMap (LPMapProc pProc, BOOL bStopWhenTRUE, DWORD dwSleep)
static char SimpleMessageMapKey (DWORD dwSleep)
static void Initialize ()
static void SetInstance (HINSTANCE hInst)

Protected Member Functions

virtual void WhoisDone (BOOL bError)
virtual BOOL OnSocketTimeout ()
virtual BOOL OnSocketConnect (int iErrorCode)
virtual BOOL OnSocketClose (int iErrorCode)
virtual BOOL OnSocketReceive (int iErrorCode)
NO_OnSocketAccept
NO_OnSocketOOB
NO_OnSocketWrite const
std::string & 
GetWhoisServer (const std::string &rURL) const
virtual int SendNoAdd (const char *pBuffer, unsigned long ulBufferLength)
virtual BOOL IsAsyncClass () const
virtual BOOL SetAsync ()
virtual SOCKET GetAsyncHandle () const
virtual BOOL SendBlockedBuffer (const CBlockedBuffer::CBlockedData &rData)
void SetConnectionStatus (BOOL bConnected)
virtual LPTCPHeader ConstructTCPHeader (unsigned short usSourcePort, unsigned short usDestinationPort, unsigned char ucHeaderLength) const
virtual void FinalTCPHeader (LPTCPHeader lpHead) const
virtual int SendRaw (unsigned short usSourcePort, IP aDestinationAddress, unsigned short usDestinationPort, const char *pBuffer, unsigned long ulBufferLength, unsigned char ucFlags=0)
virtual int SendRaw (unsigned short usSourcePort, const std::string &rDestinationAddress, unsigned short usDestinationPort, const char *pBuffer, unsigned long ulBufferLength, unsigned char ucFlags=0)
void SetConnectedTo (const sockaddr_in &rAddress)
IP GetSourceAddress () const
unsigned char GetTTL () const
unsigned char GetProtocol () const
BOOL HasOptions () const
virtual LPIpHeader ConstructIPHeader (unsigned char ucProtocol, unsigned short usFragmentationFlags, unsigned char ucTTL, unsigned short usIdentification, unsigned char ucHeaderLength) const
BOOL CheckSocketValid () const
void AssignSocket (SOCKET aNewSocket, unsigned char ucProtocol=IPPROTO_TCP)
BOOL IsRaw () const
void SetProtocol (unsigned char iProtocol)
BOOL ValidSocket () const
virtual void InitializeIP ()
virtual void SetIPHeaderAddress (LPIpHeader lpHead, IP aSourceAddress, IP aDestinationAddress) const
virtual void FinalIPHeader (LPIpHeader lpHead) const
virtual int ReceiveFrom (char *pBuffer, unsigned long ulBufferLength, IP &rIP, unsigned short &rSourcePort)
virtual void NotifyShutdown ()
void RegisterShutdown (CSpoofBase *pBase)
void SetLastError (const std::string &rMethod) const
void SetLastError (const std::string &, int iErrorCode) const
const std::string & GetClassName () const
void WriteMessage (const std::string &rMethod, const std::string &rMessage, LogPriority aPriority=lpMessage)
void WriteMessage (const std::string &rMethod, const std::string &rMessage, DWORD dwAdditionalData, LogPriority aPriority=lpMessage)
virtual void ReportError (const std::string &rMethod) const
virtual void ReportError (const std::string &rMethod, const std::string &rMessage) const
virtual void ReportError (const std::string &rMethod, const std::string &rMessage, DWORD dwAdditionalData) const
virtual void ReportError (const std::string &rMethod, int iErrorCode) const
virtual void ReportError (const std::string &rMethod, const std::string &rMessage, int iErrorCode) const
virtual void ReportErrorOS (const std::string &rMethod, const std::string &rMessage) const
void SetName (const std::string &rName) const
virtual BOOL OnSocketAccept (int iErrorCode)=0
virtual BOOL OnSocketOOB (int iErrorCode)=0
virtual BOOL OnSocketWrite (int iErrorCode)=0
BOOL IsBlocking () const
int InternalWSAAsyncSelect (unsigned int wMsg, long lEvent)
void SocketClosing ()
int GetSocketID () const
HWND GetWindowHandle () const
void RemoveSocketFromList ()
void AddSocketToList ()
BOOL IsTimeout () const
BOOL Block ()
CBlockedBufferGetBlockedBuffer () const
BOOL SetSystemTimeout (int iMS)
BOOL KillSystemTimer ()
BOOL HasSystemTimer () const
virtual void OnSocketDelete ()
virtual void SocketCreated ()

Static Protected Member Functions

static void WriteStaticMessage (const std::string &rClass, const std::string &rMethod, const std::string &rMessage, LogPriority aPriority=lpMessage)
static void WriteStaticMessage (const std::string &rClass, const std::string &rMethod, const std::string &rMessage, DWORD dwAdditionalData, LogPriority aPriority=lpMessage)
static void ReportStaticError (const std::string &rClass, const std::string &rMethod)
static void ReportStaticError (const std::string &rClass, const std::string &rMethod, const std::string &rMessage)
static void ReportStaticError (const std::string &rClass, const std::string &rMethod, const std::string &rMessage, DWORD dwAdditionalData)
static CSocketThreadManagerGetSocketThreadManager ()

Static Protected Attributes

static CGenericCriticalSectionm_pCSection = NULL

Friends

class CIPCrafter

Detailed Description

Definition at line 52 of file WhoisSocket.h.


Member Typedef Documentation

typedef std::vector<std::string> CWhoisSocket::AddressVector

Definition at line 66 of file WhoisSocket.h.

typedef MapProc CAsyncSocket::LPMapProc [inherited]

Definition at line 93 of file AsyncSocket.h.

typedef BOOL(* CAsyncSocket::MapProc)() [inherited]


Member Enumeration Documentation

enum CAsyncSocket::_AsyncEvents [inherited]

Enumerator:
aeReceive 
aeSend 
aeOOB 
aeClose 

Definition at line 83 of file AsyncSocket.h.

00084     {
00085         aeReceive=1,
00086         aeSend=2,
00087         aeOOB=4,
00088         aeClose=8
00089     } AsyncEvents;

enum CErrorHandler::_LogPriority [inherited]

Enumerator:
lpDebug 
lpMessage 
lpCritical 
lpError 

Definition at line 53 of file ErrorHandler.h.

00054     {
00055         lpDebug,
00056         lpMessage,
00057         lpCritical,
00058         lpError
00059     } LogPriority;

Enumerator:
ssReceive 
ssSend 
ssBoth 

Definition at line 444 of file SpoofSocket.h.

00445     {
00446         ssReceive,
00447         ssSend,
00448         ssBoth
00449     } SocketShutdown;

Enumerator:
wsNone 
wsArin 
wsApnic 
wsRipe 
wsLast 

Definition at line 56 of file WhoisSocket.h.

00057     {
00058         wsNone,
00059         wsArin,
00060         wsApnic,
00061         wsRipe,
00062         wsLast
00063     } WhoisServer;


Constructor & Destructor Documentation

CWhoisSocket::CWhoisSocket ( BOOL  bAsync  ) 

Definition at line 150 of file WhoisSocket.cpp.

00150                                       : CTCPSocketAsync(FALSE),
00151                                           m_bAsync(bAsync),
00152                                           m_bDone(TRUE),
00153                                           m_bError(FALSE),
00154                                           m_aServer(wsNone),
00155                                           m_dwTimeout(5000)
00156 {
00157     try
00158     {
00159         //Set our name
00160         SetName(CWhoisSocket_Class);
00161     }
00162     ERROR_HANDLER("CWhoisSocket")
00163 }

CWhoisSocket::~CWhoisSocket (  )  [virtual]

Definition at line 165 of file WhoisSocket.cpp.

00166 {
00167 }


Member Function Documentation

CTCPSocket * CTCPSocket::Accept (  )  [inherited]

Definition at line 458 of file TCPSocket.cpp.

00459 {
00460     try
00461     {
00462         //Quit if not ok
00463         if (!CheckSocketValid())
00464             return FALSE;
00465 
00466         //First accept the socket
00467         SOCKET aSocket;
00468         
00469         //Where we are connected to
00470         sockaddr_in aConnected;
00471         
00472         //Size of the structure
00473         int iSize;
00474         iSize=sizeof(aConnected);
00475 
00476         //Accept it
00477         aSocket=accept(GetHandle(),
00478                        (sockaddr*)&aConnected,
00479                        &iSize);
00480 
00481         //Is all OK
00482         if (aSocket!=INVALID_SOCKET)
00483         {
00484             //Create the new tcp socket
00485             CTCPSocket* pSocket;
00486             pSocket=new CTCPSocket(aSocket);
00487 
00488             //Set the address
00489             pSocket->SetConnectedTo(aConnected);
00490             pSocket->SetConnectionStatus(TRUE);
00491 
00492             //Done
00493             return pSocket;
00494         }
00495         else
00496         {
00497             //Error
00498             SetLastError("Accept");
00499 
00500             //Exit
00501             return NULL;
00502         }
00503     }
00504     ERROR_HANDLER_RETURN("Accept",NULL)
00505 }

BOOL CTCPSocket::Accept ( CTCPSocket pNewSocket  )  [inherited]

Definition at line 521 of file TCPSocket.cpp.

00522 {
00523     try
00524     {
00525         //Quit if not ok
00526         if (!CheckSocketValid())
00527             return FALSE;
00528 
00529         //First accept the socket
00530         SOCKET aNewSocket;
00531         
00532         //Where we are connected to
00533         sockaddr_in aAddress;
00534         
00535         //Size of the structure
00536         int iSize;
00537         iSize=sizeof(aAddress);
00538 
00539         //Accept it
00540         aNewSocket=accept(GetHandle(),
00541                           (sockaddr*)&aAddress,
00542                           &iSize);
00543 
00544         //Is it OK
00545         if (aNewSocket!=INVALID_SOCKET)
00546         {
00547             //Call before accept routing
00548             pNewSocket->BeforeAccept();
00549 
00550             //Set the socket data
00551             pNewSocket->SetConnectedTo(aAddress);
00552             pNewSocket->AssignSocket(aNewSocket);
00553             pNewSocket->SetConnectionStatus(TRUE);
00554             pNewSocket->Accepted();
00555 
00556             //Exit
00557             return TRUE;
00558         }
00559         else
00560         {
00561             //Error
00562             SetLastError("Accept");
00563 
00564             //Exit
00565             return FALSE;
00566         }
00567     }
00568     ERROR_HANDLER_RETURN("Accept",FALSE)
00569 }

void CAsyncSocket::AddSocketToList (  )  [protected, inherited]

Definition at line 184 of file AsyncSocket.cpp.

00185 {
00186     try
00187     {
00188         //Allocate our window
00189         AllocateHandle();
00190 
00191         //Do we have a CS
00192         if (m_pCSection)
00193         {
00194             //Enter the CS
00195             CCriticalAutoRelease aRelease(m_pCSection);
00196 
00197             //Add socket to list
00198             m_iSocketID=GetAsyncHandle();
00199             m_aSocketMap.insert(SocketMap::value_type(m_iSocketID,this));
00200 
00201             //Added to list
00202             m_bList=TRUE;
00203         }
00204         else
00205             ReportError("AddSocketToList","Critical section not initialized");
00206     }
00207     ERROR_HANDLER("AddSocketToList")
00208 }

void CAsyncSocket::AllowBlockedBuffer ( BOOL  bAllow  )  [inherited]

Definition at line 865 of file AsyncSocket.cpp.

00866 {
00867     try
00868     {
00869         //Do we have a buffer
00870         if (bAllow && 
00871             !m_pBlockedBuffer)
00872             m_pBlockedBuffer=new CBlockedBuffer(this);
00873         else if (!bAllow && 
00874                  m_pBlockedBuffer)
00875         {
00876             //Delete and reset the blocked buffer
00877             delete m_pBlockedBuffer;
00878             m_pBlockedBuffer=NULL;
00879         }
00880     }
00881     ERROR_HANDLER("AllowBlockedBuffer")
00882 }

CWhoisSocket::AddressVector CWhoisSocket::AnalyzeAddress ( const std::string &  rAddress  )  [static]

Definition at line 880 of file WhoisSocket.cpp.

00881 {
00882     //Our vector
00883     AddressVector aVector;
00884 
00885     //Do we have data in the string
00886     if (!rAddress.length())
00887     {
00888         //Report it
00889         ReportStaticError(CWhoisSocket_Class,"AnalyzeAddress","Recieved empty string!");
00890 
00891         //Exit
00892         return aVector;
00893     }
00894 
00895     try
00896     {
00897         //Copy the string to a tmp buffer
00898         std::string sTmp;
00899         sTmp=rAddress;
00900 
00901         //Get the last part of the address
00902         std::string::size_type aPos;
00903         aPos=sTmp.find_last_of('.');
00904 
00905         //Do we have it
00906         while (aPos!=std::string::npos)
00907         {
00908             //How much to copy
00909             int iCopySize;
00910             iCopySize=sTmp.length()-aPos-1;
00911 
00912             //Allocate the buffer
00913             char* pExtension;
00914             pExtension=new char[iCopySize+1];
00915 
00916             //Take it
00917             std::string::size_type aCopied;
00918             aCopied=sTmp.copy(pExtension,iCopySize,aPos+1);
00919             pExtension[aCopied]=0;
00920 
00921             //Convert it to upper case
00922             strupr(pExtension);
00923 
00924             //Put it in a string
00925             std::string sData;
00926             sData=pExtension;
00927 
00928             //Put inside the vector
00929             aVector.push_back(sData);
00930 
00931             //Done with the buffer
00932             delete [] pExtension;
00933 
00934             //Cut the string
00935             sTmp=sTmp.substr(0,aPos);
00936 
00937             //Get the last part of the address
00938             aPos=sTmp.find_last_of('.');
00939         }
00940 
00941         //Insert this string
00942         aVector.push_back(sTmp);
00943 
00944         //Done
00945         return aVector;
00946     }
00947     ERROR_HANDLER_STATIC_RETURN(CWhoisSocket_Class,"AnalyzeAddress",aVector)
00948 }

void CSpoofSocket::AssignSocket ( SOCKET  aNewSocket,
unsigned char  ucProtocol = IPPROTO_TCP 
) [protected, inherited]

Definition at line 1127 of file SpoofSocket.cpp.

01128 {
01129     try
01130     {
01131         //Sets the protocol
01132         m_ucProtocol=ucProtocol;
01133 
01134         //Binds to a socket
01135         m_aSpoofSocket=aNewSocket;
01136     }
01137     ERROR_HANDLER("AssignSocket")
01138 }

BOOL CSpoofSocket::Bind ( IP  aSourceAddress,
unsigned short  usPort 
) [virtual, inherited]

Definition at line 852 of file SpoofSocket.cpp.

00854 {
00855     try
00856     {
00857         //Quit if not ok
00858         if (!CheckSocketValid())
00859             return FALSE;
00860 
00861         //Create the local address
00862         sockaddr_in soSrc;
00863 
00864         //Set to 0
00865         memset(&soSrc,0,sizeof(soSrc));
00866         soSrc.sin_family=AF_INET;
00867 
00868         //Populate the connection data
00869         if (aSourceAddress)
00870             soSrc.sin_addr.s_addr=aSourceAddress;
00871         else
00872             soSrc.sin_addr.s_addr=ADDR_ANY ;
00873 
00874         soSrc.sin_port=htons(usPort);
00875 
00876         //Now we need to bind it
00877         if (bind(GetHandle(),
00878                  (sockaddr*)&soSrc,
00879                  sizeof(soSrc)))
00880         {
00881             //Error
00882             SetLastError("Bind");
00883 
00884             //Exit
00885             return FALSE;
00886         }
00887         else
00888             //Save the address
00889             m_aConnectedTo=soSrc;
00890 
00891         //If already has a source address then don't change it
00892         if (!m_ulSourceAddress)
00893             //Save it as the source address (spoofing options only)
00894             m_ulSourceAddress=aSourceAddress;
00895 
00896         return TRUE;
00897     }
00898     ERROR_HANDLER_RETURN("Bind",FALSE)
00899 }

BOOL CSpoofSocket::Bind ( const std::string &  rSourceAddress,
unsigned short  usPort 
) [virtual, inherited]

Definition at line 901 of file SpoofSocket.cpp.

00903 {
00904     try
00905     {
00906         //Quit if not ok
00907         if (!CheckSocketValid())
00908             return FALSE;
00909 
00910         if (rSourceAddress.empty())
00911             return Bind((IP)0,
00912                         usPort);
00913         else
00914             return Bind(inet_addr(rSourceAddress.c_str()),
00915                         usPort);
00916     }
00917     ERROR_HANDLER_RETURN("Bind",FALSE)
00918 }

BOOL CAsyncSocket::Block (  )  [protected, inherited]

Definition at line 818 of file AsyncSocket.cpp.

00819 {
00820     try
00821     {
00822         //First disable the events
00823         int iResult;
00824         iResult=WSAAsyncSelect(GetAsyncHandle(),
00825                                GetWindowHandle(),
00826                                0,
00827                                0);
00828 
00829         if (iResult)
00830         {
00831             //Report it
00832             SetLastError("Block");
00833 
00834             //Exit
00835             return FALSE;
00836         }
00837 
00838         unsigned long ulBlocking;
00839         ulBlocking=0;
00840 
00841         //And return to non-blocking
00842         iResult=ioctlsocket(GetAsyncHandle(),
00843                             FIONBIO,
00844                             &ulBlocking);
00845 
00846         if (iResult)
00847         {
00848             //Report it
00849             SetLastError("Block");
00850 
00851             //Exit
00852             return FALSE;
00853         }
00854 
00855         return TRUE;
00856     }
00857     ERROR_HANDLER_RETURN("Block",FALSE)
00858 }

unsigned short CSpoofSocket::CalculateChecksum ( const unsigned short *  pBuffer,
int  iSize 
) [static, inherited]

Definition at line 824 of file SpoofSocket.cpp.

00826 {
00827     try
00828     {
00829         unsigned long usChksum=0;
00830 
00831         //Calculate the checksum
00832         while (iSize>1)
00833         {
00834             usChksum+=*pBuffer++;
00835             iSize-=sizeof(unsigned short);
00836         }
00837 
00838         //If we have one char left
00839         if (iSize)
00840             usChksum+=*(unsigned char*)pBuffer;
00841 
00842         //Complete the calculations
00843         usChksum=(usChksum >> 16) + (usChksum & 0xffff);
00844         usChksum+=(usChksum >> 16);
00845 
00846         //Return the value (inversed)
00847         return (unsigned short)(~usChksum);
00848     }
00849     ERROR_HANDLER_STATIC_RETURN(CSpoofSocket_LOGNAME,"CalculateChecksum",0)
00850 }

unsigned short CSpoofSocket::CalculatePseudoChecksum ( const char *  pBuffer,
int  iBufferLength,
IP  aDestinationAddress,
int  iPacketLength 
) const [inherited]

Definition at line 997 of file SpoofSocket.cpp.

01001 {
01002     try
01003     {
01004         //Calculate the checksum
01005         LPPseudoHeader lpPseudo;
01006         lpPseudo=new PseudoHeader;
01007 
01008         //Protect it
01009         std::auto_ptr<PseudoHeader> pProtection(lpPseudo);
01010 
01011         //Set the values
01012         lpPseudo->ulDestinationAddress=aDestinationAddress;
01013         lpPseudo->ulSourceAddress=m_ulSourceAddress;
01014         lpPseudo->ucZeros=0;
01015         lpPseudo->ucPTCL=m_ucProtocol;
01016         lpPseudo->usLength=htons(iPacketLength);
01017 
01018         //Calculate checksum of all
01019         int iTotalLength;
01020         iTotalLength=PseudoHeaderLength+iBufferLength;
01021 
01022         //Allocate the buffer
01023         char* pNewBuffer;
01024         pNewBuffer=new char[iTotalLength];
01025 
01026         //Protect the new buffer
01027         CArray_ptr<char> pBufferProtection(pNewBuffer);
01028 
01029         //Copy pseudo
01030         memcpy(pNewBuffer,lpPseudo,PseudoHeaderLength);
01031 
01032         //Copy header
01033         memcpy(pNewBuffer+PseudoHeaderLength,
01034                pBuffer,
01035                iBufferLength);
01036 
01037         //Calculate the checksum
01038         unsigned short usChecksum;
01039         usChecksum=CalculateChecksum((unsigned short*)pNewBuffer,iTotalLength);
01040 
01041         //Return checksum
01042         return usChecksum;
01043     }
01044     ERROR_HANDLER_RETURN("CalculatePseudoChecksum",0)
01045 }

BOOL CSpoofSocket::CanRead (  )  const [inherited]

Definition at line 1437 of file SpoofSocket.cpp.

01438 {
01439     try
01440     {
01441         //Quit if not ok
01442         if (!CheckSocketValid())
01443             return FALSE;
01444 
01445         //Create our structure
01446         fd_set aDescriptor;
01447         FD_ZERO(&aDescriptor);
01448 
01449         //Add our socket
01450         FD_SET(GetHandle(),&aDescriptor);
01451 
01452         //And create the timeval
01453         timeval aTime;
01454         aTime.tv_sec=0;
01455         aTime.tv_usec=0;
01456 
01457         //And run the select
01458         int iRetVal;
01459         iRetVal=select(NULL,&aDescriptor,NULL,NULL,&aTime);
01460 
01461         //Check if we had an error
01462         if (iRetVal==GetErrorCode())
01463         {
01464             //Report it
01465             SetLastError("CanRead");
01466 
01467             //Exit
01468             return FALSE;
01469         }
01470         else
01471             //Check is our socket set
01472             return FD_ISSET(GetHandle(),&aDescriptor);
01473     }
01474     ERROR_HANDLER_RETURN("CanRead",FALSE)
01475 }

BOOL CSpoofSocket::CanWrite (  )  const [inherited]

Definition at line 1477 of file SpoofSocket.cpp.

01478 {
01479     try
01480     {
01481         //Quit if not ok
01482         if (!CheckSocketValid())
01483             return FALSE;
01484 
01485         //Create our structure
01486         fd_set aDescriptor;
01487         FD_ZERO(&aDescriptor);
01488 
01489         //Add our socket
01490         FD_SET(GetHandle(),&aDescriptor);
01491 
01492         //And create the timeval
01493         timeval aTime;
01494         aTime.tv_sec=0;
01495         aTime.tv_usec=0;
01496 
01497         //And run the select
01498         int iRetVal;
01499         iRetVal=select(NULL,NULL,&aDescriptor,NULL,&aTime);
01500 
01501         //Check if we had an error
01502         if (iRetVal==GetErrorCode())
01503         {
01504             //Report it
01505             SetLastError("CanWrite");
01506 
01507             //Exit
01508             return FALSE;
01509         }
01510         else
01511             //Check is our socket set
01512             return FD_ISSET(GetHandle(),&aDescriptor);
01513     }
01514     ERROR_HANDLER_RETURN("CanWrite",FALSE)
01515 }

BOOL CSpoofSocket::CheckSocketValid (  )  const [protected, inherited]

Definition at line 925 of file SpoofSocket.cpp.

00926 {
00927     try
00928     {
00929         //Check if socket is invalid
00930         if (!ValidSocket())
00931         {
00932             //Report it
00933             ReportError("CheckSocketValid","Operation made on non existant socket!");
00934 
00935             //Exit
00936             return FALSE;
00937         }   
00938 
00939         //OK
00940         return TRUE;
00941     }
00942     ERROR_HANDLER_RETURN("CheckSocketValid",FALSE)
00943 }

BOOL CTCPSocketAsync::Close (  )  [virtual, inherited]

Reimplemented from CTCPSocket.

Definition at line 369 of file TCPSocketAsync.cpp.

00370 {
00371     try
00372     {
00373         //Quit if not ok
00374         if (!ValidSocket())
00375             return FALSE;
00376 
00377         //Kill the timer
00378         CAsyncSocket::SocketClosing();
00379 
00380         //Remove from socket list
00381         RemoveSocketFromList();
00382 
00383         //Done
00384         return CTCPSocket::Close();
00385     }
00386     ERROR_HANDLER_RETURN("Close",FALSE)
00387 }

BOOL CTCPSocket::Connect ( const std::string &  rDestinationAddress,
unsigned short  usDestinationPort 
) [virtual, inherited]

Definition at line 249 of file TCPSocket.cpp.

00251 {
00252     try
00253     {
00254         return Connect(0,
00255                        rDestinationAddress,
00256                        usDestinationPort);
00257     }
00258     ERROR_HANDLER_RETURN("Connect",FALSE)
00259 }

BOOL CTCPSocket::Connect ( IP  aDestinationAddress,
unsigned short  usDestinationPort 
) [virtual, inherited]

Definition at line 237 of file TCPSocket.cpp.

00239 {
00240     try
00241     {
00242         return Connect(0,
00243                        aDestinationAddress,
00244                        usDestinationPort);
00245     }
00246     ERROR_HANDLER_RETURN("Connect",FALSE)
00247 }

BOOL CTCPSocket::Connect ( unsigned short  usSourcePort,
const std::string &  rDestinationAddress,
unsigned short  usDestinationPort 
) [virtual, inherited]

Definition at line 341 of file TCPSocket.cpp.

00344 {
00345     try
00346     {
00347         //Quit if not ok
00348         if (!CheckSocketValid())
00349             return FALSE;
00350 
00351         //Delegate the call
00352         return Connect(usSourcePort,
00353                        StringToLong(rDestinationAddress),
00354                        usDestinationPort);
00355     }
00356     ERROR_HANDLER_RETURN("Connect",FALSE)
00357 }

BOOL CTCPSocket::Connect ( unsigned short  usSourcePort,
IP  aDestinationAddress,
unsigned short  usDestinationPort 
) [virtual, inherited]

Special handling for raw sockets

Definition at line 261 of file TCPSocket.cpp.

00264 {
00265     try
00266     {
00267         //Quit if not ok
00268         if (!CheckSocketValid())
00269             return FALSE;
00270 
00271         ///Special handling for raw sockets
00272         if (IsRaw())
00273             return SendRaw(usSourcePort,
00274                            aDestinationAddress,
00275                            usDestinationPort,
00276                            NULL,
00277                            0,
00278                            TCPFlag_SYN);
00279         else
00280         {
00281             //Set async notification
00282             int iResult;
00283             
00284             //Create the address
00285             sockaddr_in aSrc;
00286         
00287             //Set to 0
00288             memset(&aSrc,
00289                    0,
00290                    sizeof(aSrc));
00291             aSrc.sin_family=AF_INET;
00292             aSrc.sin_addr.s_addr=aDestinationAddress;
00293             aSrc.sin_port=htons(usDestinationPort);
00294 
00295             //Connect
00296             iResult=connect(GetHandle(),
00297                             (sockaddr*)&aSrc,
00298                             sizeof(aSrc));
00299 
00300             //Did we have a blocked error
00301             BOOL bBlocked;
00302             bBlocked=FALSE;
00303 
00304             //Check the result
00305             if (iResult==GetErrorCode())
00306             {
00307                 //Check is it blocking error so we can ignore
00308                 if (WSAGetLastError()!=WSAEWOULDBLOCK)
00309                     SetLastError("Connect");
00310                 else
00311                 {
00312                     //Indicate it's blocked error
00313                     bBlocked=TRUE;
00314                     iResult=!GetErrorCode();
00315                 }
00316             }
00317             else
00318                 //Report the error
00319                 SetLastError("Connect");
00320             
00321             if (iResult!=GetErrorCode())
00322             {
00323                 //Check if we are a sync socket
00324                 if (!IsAsyncClass())
00325                     SetConnectionStatus(TRUE);
00326 
00327                 //Save where we are connected
00328                 SetConnectedTo(aSrc);
00329             }
00330 
00331             //Done
00332             if (!bBlocked)
00333                 return iResult!=GetErrorCode();
00334             else
00335                 return FALSE;
00336         }
00337     }
00338     ERROR_HANDLER_RETURN("Connect",FALSE)
00339 }

BOOL CTCPSocketAsync::Connect ( unsigned short  usSourcePort,
const std::string &  rDestinationAddress,
unsigned short  usDestinationPort,
BOOL  bDisableAsync = FALSE,
BOOL  bForceErrorEvent = FALSE 
) [virtual, inherited]

Definition at line 218 of file TCPSocketAsync.cpp.

00223 {
00224     try
00225     {
00226         //Quit if not ok
00227         if (!CheckSocketValid())
00228             return FALSE;
00229 
00230         //Delegate the call
00231         return Connect(usSourcePort,
00232                        StringToLong(rDestinationAddress),
00233                        usDestinationPort,
00234                        bDisableAsync,
00235                        bForceErrorEvent);
00236     }
00237     ERROR_HANDLER_RETURN("Connect",FALSE)
00238 }

BOOL CTCPSocketAsync::Connect ( unsigned short  usSourcePort,
IP  aDestinationAddress,
unsigned short  usDestinationPort,
BOOL  bDisableAsync = FALSE,
BOOL  bForceErrorEvent = FALSE 
) [virtual, inherited]

Definition at line 110 of file TCPSocketAsync.cpp.

00115 {
00116     try
00117     {
00118         //Quit if not ok
00119         if (!CheckSocketValid())
00120             return FALSE;
00121 
00122         //Set the async notification
00123         if (!bDisableAsync)
00124         {
00125             int iResult;
00126             iResult=InternalWSAAsyncSelect(WM_SOCKET_CONNECT,
00127                                            FD_CONNECT);
00128 
00129             if (iResult)
00130             {
00131                 //Get the error code
00132                 int iErrorCode;
00133                 iErrorCode=GetSystemLastError();
00134 
00135                 //Report it
00136                 SetLastError("Connect");
00137 
00138                 //Do we need to call event?
00139                 if (bForceErrorEvent)
00140                     SocketConnected(iErrorCode);
00141 
00142                 //Exit
00143                 return FALSE;
00144             }
00145 
00146             //Set our timeout
00147             if (m_ulTimeout &&
00148                 !IsBlocking())
00149                 if (!SetSystemTimeout(m_ulTimeout))
00150                 {
00151                     //Report it
00152                     ReportError("Connect","Failed to set timer!");
00153 
00154                     //Do we need to call event?
00155                     if (bForceErrorEvent)
00156                         SocketConnected(GetErrorCode());
00157 
00158                     //Exit
00159                     return FALSE;
00160                 }
00161         }
00162         //Set to non blocking!
00163         else if (!Block())
00164             return FALSE;
00165 
00166         //Set the flag
00167         m_bDisabledConnect=bDisableAsync;
00168 
00169         //Call the original connect
00170         BOOL bResult;
00171         bResult=CTCPSocket::Connect(usSourcePort,
00172                                     aDestinationAddress,
00173                                     usDestinationPort);
00174 
00175         //Reset the flag
00176         m_bDisabledConnect=FALSE;
00177 
00178         if (bResult)
00179         {
00180             //Call event, but only if in async
00181             if (!bDisableAsync &&
00182                 !IsBlocking())
00183                 //Call user, will add socket automatically
00184                 return SocketConnected(0);
00185             else
00186                 //Set as async
00187                 return SetAsync();
00188         }
00189         else if (GetSystemLastError()!=WSAEWOULDBLOCK ||
00190                  bDisableAsync ||
00191                  IsBlocking())
00192         {
00193             if (m_ulTimeout)
00194                 //Kill the timer
00195                 KillSystemTimer();
00196 
00197             //Get the error code
00198             int iErrorCode;
00199             iErrorCode=GetSystemLastError();
00200 
00201             //Report it
00202             SetLastError("Connect");
00203 
00204             //Do we need to call event?
00205             if (bForceErrorEvent &&
00206                 !bDisableAsync)
00207                 SocketConnected(iErrorCode);
00208 
00209             //Exit
00210             return FALSE;
00211         }
00212         else
00213             return TRUE;
00214     }
00215     ERROR_HANDLER_RETURN("Connect",FALSE)
00216 }

BOOL CTCPSocketAsync::Connect ( const std::string &  rDestinationAddress,
unsigned short  usDestinationPort,
BOOL  bDisableAsync = FALSE,
BOOL  bForceErrorEvent = FALSE 
) [virtual, inherited]

Definition at line 93 of file TCPSocketAsync.cpp.

00097 {
00098     try
00099     {
00100         //Delegate the call
00101         return Connect(0,
00102                        rDestinationAddress,
00103                        usDestinationPort,
00104                        bDisableAsync,
00105                        bForceErrorEvent);
00106     }
00107     ERROR_HANDLER_RETURN("Connect",FALSE)
00108 }

BOOL CTCPSocketAsync::Connect ( IP  aDestinationAddress,
unsigned short  usDestinationPort,
BOOL  bDisableAsync = FALSE,
BOOL  bForceErrorEvent = FALSE 
) [virtual, inherited]

Definition at line 76 of file TCPSocketAsync.cpp.

00080 {
00081     try
00082     {
00083         //Delegate the call
00084         return Connect(0,
00085                        aDestinationAddress,
00086                        usDestinationPort,
00087                        bDisableAsync,
00088                        bForceErrorEvent);
00089     }
00090     ERROR_HANDLER_RETURN("Connect",FALSE)
00091 }

LPIpHeader CSpoofSocket::ConstructIPHeader ( unsigned char  ucProtocol,
unsigned short  usFragmentationFlags,
unsigned char  ucTTL,
unsigned short  usIdentification,
unsigned char  ucHeaderLength 
) const [protected, virtual, inherited]

Reimplemented in CICMPCrafter, CTCPCrafter, and CUDPCrafter.

Definition at line 778 of file SpoofSocket.cpp.

00783 {
00784     return ConstructStaticIPHeader(ucProtocol,
00785                                    usFragmentationFlags,
00786                                    ucTTL,
00787                                    usIdentification,
00788                                    ucHeaderLength);                
00789 }

LPIpHeader CSpoofSocket::ConstructStaticIPHeader ( unsigned char  ucProtocol,
unsigned short  usFragmentationFlags,
unsigned char  ucTTL,
unsigned short  usIdentification,
unsigned char  ucHeaderLength 
) [static, inherited]

Definition at line 1398 of file SpoofSocket.cpp.

01403 {
01404     try
01405     {
01406         //Need to construct the IP header
01407         LPIpHeader lpHead=new _IpHeader;
01408 
01409         //Header length (in 32 bits)
01410         lpHead->ucHeaderLength_Version=(ucHeaderLength >> 2) |
01411                                        (IpVersion << 4);
01412 
01413         //Protocol
01414         lpHead->ucProtocol=ucProtocol;
01415 
01416         //Fragmentation flags
01417         lpHead->usFragmentationFlags=htons(usFragmentationFlags);
01418 
01419         //Time to live
01420         lpHead->ucTTL=ucTTL;
01421 
01422         //Checksum - set to 0
01423         lpHead->usChecksum=0;
01424 
01425         //Identification
01426         lpHead->usIdentification=htons(usIdentification);
01427 
01428         //Precedence
01429         lpHead->ucTypeOfService=IpService_ROUTINE;
01430 
01431         //Return IP to user
01432         return lpHead;
01433     }
01434     ERROR_HANDLER_STATIC_RETURN(CSpoofSocket_LOGNAME,"ConstructIPHeader",NULL)
01435 }

LPTCPHeader CTCPSocket::ConstructTCPHeader ( unsigned short  usSourcePort,
unsigned short  usDestinationPort,
unsigned char  ucHeaderLength 
) const [protected, virtual, inherited]

Reimplemented in CTCPCrafter.

Definition at line 359 of file TCPSocket.cpp.

00362 {
00363     try
00364     {
00365         //Construct the header
00366         LPTCPHeader lpHead=new _TCPHeader;
00367         
00368         //Set source and destination port
00369         lpHead->usSourcePort=htons(usSourcePort);
00370         lpHead->usDestinationPort=htons(usDestinationPort);
00371 
00372         //No checksums yet
00373         lpHead->usChecksum=0;
00374 
00375         //Set windows to 3.0k
00376         lpHead->usWindows=htons(512);
00377 
00378         //Set the packet number
00379         lpHead->ulAcknowledgeNumber=0;
00380 
00381         //And the sequence
00382         lpHead->ulSequenceNumber=htonl(m_uiSequence++);
00383 
00384         //Data offset
00385         lpHead->ucDataOffset=(ucHeaderLength >> 2) << 4;
00386 
00387         //Flags
00388         lpHead->ucFlags=0;
00389 
00390         //Urgent pointer
00391         lpHead->usUrgentPointer=0;
00392 
00393         //Return it to the user
00394         return lpHead;
00395     }
00396     ERROR_HANDLER_RETURN("ConstructTCPHeader",NULL)
00397 }

BOOL CSpoofSocket::Create ( int  iProtocol  )  [inherited]

Definition at line 475 of file SpoofSocket.cpp.

00476 {
00477     //Close the socket if open
00478     if (ValidSocket())
00479         Close();
00480 
00481     try
00482     {
00483         //Are we overlapped
00484         if (!m_bOverlapped)
00485         {
00486             //Here we create the raw socket
00487             if (m_bRaw || iProtocol==IPPROTO_ICMP)
00488                 m_aSpoofSocket=socket(AF_INET,
00489                                       SOCK_RAW,
00490                                       iProtocol);
00491             else
00492                 if (iProtocol==IPPROTO_TCP)
00493                     m_aSpoofSocket=socket(AF_INET,
00494                                           SOCK_STREAM,
00495                                           iProtocol);
00496                 else if (iProtocol==IPPROTO_UDP)
00497                     m_aSpoofSocket=socket(AF_INET,
00498                                           SOCK_DGRAM,
00499                                           iProtocol);
00500         }
00501         else
00502         {
00503             //Here we create the raw socket
00504             if (m_bRaw || iProtocol==IPPROTO_ICMP)
00505                 m_aSpoofSocket=WSASocket(AF_INET,
00506                                          SOCK_RAW,
00507                                          iProtocol,
00508                                          NULL,
00509                                          NULL,
00510                                          WSA_FLAG_OVERLAPPED);
00511             else
00512                 if (iProtocol==IPPROTO_TCP)
00513                     m_aSpoofSocket=WSASocket(AF_INET,
00514                                              SOCK_STREAM,
00515                                              iProtocol,
00516                                              NULL,
00517                                              NULL,
00518                                              WSA_FLAG_OVERLAPPED);
00519                 else if (iProtocol==IPPROTO_UDP)
00520                     m_aSpoofSocket=WSASocket(AF_INET,
00521                                              SOCK_DGRAM,
00522                                              iProtocol,
00523                                              NULL,
00524                                              NULL,
00525                                              WSA_FLAG_OVERLAPPED);
00526         }
00527 
00528         //Check for socket validity
00529         if (m_aSpoofSocket==INVALID_SOCKET)
00530         {
00531             //Error
00532             SetLastError("Create");
00533 
00534             //Done
00535             return FALSE;
00536         }
00537 
00538         if (m_bRaw)
00539         {
00540             //Set that the application will send the IP header
00541             unsigned int iTrue=1;
00542 
00543             if(setsockopt(m_aSpoofSocket,
00544                           IPPROTO_IP,
00545                           IP_HDRINCL,
00546                           (char*)&iTrue,
00547                           sizeof(iTrue))==GetErrorCode())
00548             {
00549                 //Check for options error
00550                 SetLastError("Create");
00551 
00552                 //Exit
00553                 return FALSE;
00554             }
00555         }
00556 
00557         //Done
00558         return TRUE;
00559     }
00560     ERROR_HANDLER_RETURN("Create",FALSE)
00561 }

BOOL CWhoisSocket::Create (  )  [virtual]

Reimplemented from CTCPSocketAsync.

Definition at line 459 of file WhoisSocket.cpp.

00460 {
00461     try
00462     {
00463         //Try to create it
00464         if (CTCPSocketAsync::Create())
00465         {
00466             if (!m_bAsync)
00467             {
00468                 if (!ReBlock())
00469                 {
00470                     //Report it
00471                     ReportError("CreateRegular","Failed to reblock!");
00472 
00473                     //Exit
00474                     return FALSE;
00475                 }
00476 
00477                 //Set it on the receive
00478                 if (!SetReceiveTimeout(m_dwTimeout))
00479                 {
00480                     //Report it
00481                     ReportError("CreateRegular","Failed to set timeout!");
00482 
00483                     //Exit
00484                     return FALSE;
00485                 }
00486             }
00487 
00488             //Done
00489             return TRUE;
00490         }
00491         else
00492             return FALSE;
00493     }
00494     ERROR_HANDLER_RETURN("Create",FALSE)
00495 }

void CAsyncSocket::DeleteSocketFromThread ( DWORD  dwTimeToWait  )  [virtual, inherited]

Definition at line 1232 of file AsyncSocket.cpp.

01233 {
01234     try
01235     {
01236         if (!dwTimeToWait)
01237             DeleteSocketFromThread();
01238         else
01239         {
01240             //We are closing
01241             SocketClosing();
01242 
01243             //Are we valid ?
01244             //And do we have a window
01245             if (!m_bList)
01246                 OnSocketDelete();
01247             else
01248             {
01249                 //Create a timer
01250                 m_aDeleteTimerID=m_pThreadManager->RegisterTimeout(dwTimeToWait,
01251                                                                    DeleteTimerProc,
01252                                                                    (LPVOID)this,
01253                                                                    TRUE,
01254                                                                    GetWindowHandle(),
01255                                                                    &m_aDeleteTimerID);
01256 
01257                 //Do we have the timer ?
01258                 if (!m_aDeleteTimerID.iTimerID)
01259                 {
01260                     //Report it
01261                     ReportError("DeleteSocketFromThread","Failed to create timeout!");
01262 
01263                     //Run regular delete
01264                     DeleteSocketFromThread();
01265                 }
01266             }
01267         }
01268     }
01269     ERROR_HANDLER("OnSocketDelete")
01270 }

void CAsyncSocket::DeleteSocketFromThread (  )  [virtual, inherited]

Definition at line 1212 of file AsyncSocket.cpp.

01213 {
01214     try
01215     {
01216         //We are closing
01217         SocketClosing();
01218 
01219         //Are we valid ?
01220         //And do we have a window
01221         if (!m_bList)
01222             OnSocketDelete();
01223         else
01224             PostMessage(GetWindowHandle(),
01225                         WM_SOCKET_DELETE,
01226                         (WPARAM)GetAsyncHandle(),
01227                         0);
01228     }
01229     ERROR_HANDLER("OnSocketDelete")
01230 }

BOOL CAsyncSocket::DisableAsync (  )  [inherited]

Definition at line 630 of file AsyncSocket.cpp.

00631 {
00632     try
00633     {
00634         //Quit if not ok
00635         if (!CheckAsyncSocketValid())
00636             return FALSE;
00637 
00638         //Set event to read / write / close / oob
00639         int iResult;
00640 
00641         iResult=WSAAsyncSelect(GetAsyncHandle(),
00642                                GetWindowHandle(),
00643                                0,
00644                                0);
00645         if (iResult)
00646         {
00647             //Report it
00648             SetLastError("DisableAsync");
00649 
00650             //Exit
00651             return FALSE;
00652         }
00653         
00654         return TRUE;
00655     }
00656     ERROR_HANDLER_RETURN("DisableAsync",FALSE)
00657 }

void CAsyncSocket::DisableEvents ( unsigned char  ucEvents  )  [inherited]

Definition at line 1303 of file AsyncSocket.cpp.

01304 {
01305     try
01306     {
01307         //Save the events
01308         m_ucEvents=ucEvents;
01309     }
01310     ERROR_HANDLER("DisableEvents")
01311 }

std::string CErrorHandler::ErrorCodeToString ( DWORD  dwErrorCode  )  [static, inherited]

Definition at line 122 of file ErrorHandler.cpp.

00123 {
00124     try
00125     {
00126         //Get the error string
00127         LPVOID lpMsgBuf;
00128         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
00129                       FORMAT_MESSAGE_FROM_SYSTEM | 
00130                       FORMAT_MESSAGE_IGNORE_INSERTS,
00131                       NULL,
00132                       dwErrorCode,
00133                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
00134                       (LPTSTR) &lpMsgBuf,
00135                       0,
00136                       NULL);
00137 
00138         //Save it
00139         std::string sMessage;
00140         sMessage+=(char*)lpMsgBuf;
00141         
00142         //Release the buffer
00143         LocalFree(lpMsgBuf);
00144 
00145         //Done
00146         return sMessage;
00147     }
00148     catch (...)
00149     {
00150         return "Unknown";
00151     }
00152 }

void CSpoofSocket::FinalIPHeader ( LPIpHeader  lpHead  )  const [protected, virtual, inherited]

Reimplemented in CICMPCrafter, CTCPCrafter, and CUDPCrafter.

Definition at line 1393 of file SpoofSocket.cpp.

01394 {
01395     //We don't do anything
01396 }

void CTCPSocket::FinalTCPHeader ( LPTCPHeader  lpHead  )  const [protected, virtual, inherited]

Reimplemented in CTCPCrafter.

Definition at line 604 of file TCPSocket.cpp.

00605 {
00606 }

void CAsyncSocket::ForceReceiveEvent (  )  [inherited]

Definition at line 1195 of file AsyncSocket.cpp.

01196 {
01197     try
01198     {
01199         //Are we valid ?
01200         //And do we have a window
01201         if (!m_bList)
01202             OnSocketDelete();
01203         else
01204             PostMessage(GetWindowHandle(),
01205                         WM_SOCKET_FORCED,
01206                         (WPARAM)GetAsyncHandle(),
01207                         0);
01208     }
01209     ERROR_HANDLER("ForceReceiveEvent")
01210 }

void CAsyncSocket::FreezeThread (  )  [inherited]

Definition at line 713 of file AsyncSocket.cpp.

00714 {
00715     m_bFreeze=TRUE;
00716 }

const std::string & CWhoisSocket::GetAdditionalWhoisServer (  )  const

Definition at line 1010 of file WhoisSocket.cpp.

01011 {
01012     return m_sAdditionalWhoisServer;
01013 }

std::string CWhoisSocket::GetAddressForWhois ( const std::string &  rAddress  )  [static]

Definition at line 950 of file WhoisSocket.cpp.

00951 {
00952     try
00953     {
00954         //Get the vector
00955         AddressVector aVector;
00956         aVector=AnalyzeAddress(rAddress);
00957 
00958         //Do we have data
00959         if (aVector.begin()==aVector.end())
00960             return "";
00961 
00962         //Get the iterator
00963         AddressVector::const_iterator aIterator;
00964         aIterator=aVector.begin();
00965 
00966         //Our address
00967         std::string sAddress;
00968         std::string sAddAddress;
00969 
00970         //Get the first one
00971         sAddress+=*aIterator;
00972 
00973         //Do we have the second one ?
00974         ++aIterator;
00975         if (aIterator==aVector.end())
00976             return "";
00977 
00978         //Add it
00979         sAddAddress=*aIterator;
00980         sAddAddress+='.';
00981         sAddAddress+=sAddress;
00982 
00983         //What type is it
00984         if (!(*aIterator=="COM" ||
00985               *aIterator=="NET" ||
00986               *aIterator=="ORG" ||
00987               *aIterator=="MIL" ||
00988               *aIterator=="EDU" ||
00989               *aIterator=="CO") ||
00990               sAddress.length()==3)
00991             //Done
00992             return sAddAddress;
00993 
00994         //Another sub address
00995         ++aIterator;
00996         if (aIterator==aVector.end())
00997             return "";
00998 
00999         //This is the final address
01000         sAddress=*aIterator;
01001         sAddress+='.';
01002         sAddress+=sAddAddress;
01003 
01004         //Done
01005         return sAddress;
01006     }
01007     ERROR_HANDLER_STATIC_RETURN(CWhoisSocket_Class,"GetAddressForWhois","")
01008 }

SOCKET CTCPSocketAsync::GetAsyncHandle (  )  const [protected, virtual, inherited]

Implements CAsyncSocket.

Definition at line 343 of file TCPSocketAsync.cpp.

00344 {
00345     return GetHandle();
00346 }

CBlockedBuffer * CAsyncSocket::GetBlockedBuffer (  )  const [protected, inherited]

Definition at line 884 of file AsyncSocket.cpp.

00885 {
00886     return m_pBlockedBuffer;
00887 }

const std::string & CErrorHandler::GetClassName (  )  const [protected, inherited]

Reimplemented in CSocketThreadManager.

Definition at line 516 of file ErrorHandler.cpp.

00517 {
00518     return m_sClassName;
00519 }

std::string CErrorHandler::GetCurrentDateTime (  )  [static, inherited]

Definition at line 521 of file ErrorHandler.cpp.

00522 {
00523     try
00524     {
00525         //Our string
00526         std::string sDate;
00527 
00528         //Our tmp buf
00529         char cTmp[128];
00530 
00531         //Get date
00532         _strdate(cTmp);
00533         sDate=cTmp;
00534         sDate+=' ';
00535 
00536         //Get time
00537         _strtime(cTmp);
00538         sDate+=cTmp;
00539 
00540         //Done
00541         return sDate;
00542     }
00543     ERROR_HANDLER_STATIC_RETURN(CErrorHandler_Class,"GetCurrentDateTime","")
00544 }

int CSpoofBase::GetErrorCode (  )  [static, inherited]

Definition at line 488 of file SpoofBase.cpp.

00489 {
00490     return SOCKET_ERROR;
00491 }

CGenericCriticalSection * CSpoofBase::GetGlobalCriticalSection (  )  [static, inherited]

Definition at line 483 of file SpoofBase.cpp.

00484 {
00485     return m_pCSection;
00486 }

SOCKET CSpoofSocket::GetHandle (  )  const [inherited]

Definition at line 920 of file SpoofSocket.cpp.

00921 {
00922     return m_aSpoofSocket;
00923 }

int CSpoofBase::GetLastError (  )  const [inherited]

Definition at line 138 of file SpoofBase.cpp.

00139 {
00140     return m_iLastError;
00141 }

const std::string & CWhoisSocket::GetLastTarget (  )  const

Definition at line 1051 of file WhoisSocket.cpp.

01052 {
01053     return m_sDataToSend;
01054 }

unsigned long CSpoofBase::GetNumberOfThreads (  )  [static, inherited]

Definition at line 463 of file SpoofBase.cpp.

00464 {
00465     return m_ulNumberOfThreads;
00466 }

CIPOptions * CSpoofSocket::GetOptions (  )  const [inherited]

Definition at line 196 of file SpoofSocket.cpp.

00197 {
00198     return m_pIPOptions;
00199 }

long CSpoofSocket::GetPeerAddress (  )  const [inherited]

Definition at line 1349 of file SpoofSocket.cpp.

01350 {
01351     //Get the address we are connected to
01352     return m_aConnectedTo.sin_addr.S_un.S_addr;
01353 }

unsigned short CSpoofSocket::GetPeerPort (  )  const [inherited]

Definition at line 1388 of file SpoofSocket.cpp.

01389 {
01390     return htons(m_aConnectedTo.sin_port);
01391 }

unsigned char CSpoofSocket::GetProtocol (  )  const [protected, inherited]

Definition at line 1564 of file SpoofSocket.cpp.

01565 {
01566     return m_ucProtocol;
01567 }

int CAsyncSocket::GetSocketID (  )  const [protected, inherited]

Definition at line 210 of file AsyncSocket.cpp.

00211 {
00212     return m_iSocketID;
00213 }

CSocketThreadManager * CAsyncSocket::GetSocketThreadManager (  )  [static, protected, inherited]

Definition at line 895 of file AsyncSocket.cpp.

00896 {
00897     return m_pThreadManager;
00898 }

IP CSpoofSocket::GetSourceAddress (  )  const [protected, inherited]

Definition at line 1554 of file SpoofSocket.cpp.

01555 {
01556     return m_ulSourceAddress;
01557 }

int CSpoofBase::GetSystemLastError (  )  const [inherited]

Definition at line 478 of file SpoofBase.cpp.

00479 {
00480     return WSAGetLastError();
00481 }

CTCPOptions * CTCPSocket::GetTCPOptions (  )  const [inherited]

Definition at line 425 of file TCPSocket.cpp.

00426 {
00427     return m_pTCPOptions;
00428 }

unsigned char CSpoofSocket::GetTTL (  )  const [protected, inherited]

Reimplemented in CPingSocket.

Definition at line 1549 of file SpoofSocket.cpp.

01550 {
01551     return m_ucTTL;
01552 }

const std::string & CWhoisSocket::GetWhoisData (  )  const

Definition at line 729 of file WhoisSocket.cpp.

00730 {
00731     return m_sWhoisData;
00732 }

const std::string & CWhoisSocket::GetWhoisServer ( const std::string &  rURL  )  const [protected]

Definition at line 416 of file WhoisSocket.cpp.

00417 {
00418     try
00419     {
00420         //Get the last part of the address
00421         std::string::size_type aPos;
00422         aPos=rURL.find_last_of('.');
00423 
00424         //Do we have it
00425         if (aPos==std::string::npos)
00426             return m_sEmpty;
00427 
00428         //Check the size of the extension
00429         if (rURL.length()-aPos>4)
00430             return m_sEmpty;
00431 
00432         //Take it
00433         std::string::size_type aCopied;
00434         char aExtension[10];
00435         aCopied=rURL.copy(aExtension,rURL.length()-aPos-1,aPos+1);
00436         aExtension[aCopied]=0;
00437 
00438         //Convert it to upper case
00439         strupr(aExtension);
00440 
00441         //Copy it into a string
00442         std::string sExtension;
00443         sExtension=aExtension;
00444 
00445         //Look in the map
00446         WhoisMAP::const_iterator aIterator;
00447         aIterator=m_aData.find(sExtension);
00448 
00449         //Do we have it
00450         if (aIterator!=m_aData.end())
00451             return aIterator->second;
00452         else
00453             //Not found
00454             return m_sEmpty;
00455     }
00456     ERROR_HANDLER_RETURN("GetWhoisServer",m_sEmpty)
00457 }

HWND CAsyncSocket::GetWindowHandle (  )  const [protected, inherited]

Definition at line 297 of file AsyncSocket.cpp.

00298 {
00299     //Check if we are multithreaded ?
00300     return m_hLocalWindowHandle;
00301 }

BOOL CSpoofSocket::HasOptions (  )  const [protected, inherited]

Definition at line 1559 of file SpoofSocket.cpp.

01560 {
01561     return m_bOptions;
01562 }

BOOL CAsyncSocket::HasSystemTimer (  )  const [protected, inherited]

Definition at line 1180 of file AsyncSocket.cpp.

01181 {
01182     return m_aTimerID.iTimerID!=0;
01183 }

BOOL CAsyncSocket::HasTimeout (  )  const [inherited]

Definition at line 1313 of file AsyncSocket.cpp.

01314 {
01315     return m_bTimeout;
01316 }

void CAsyncSocket::Initialize (  )  [static, inherited]

Definition at line 485 of file AsyncSocket.cpp.

00486 {
00487     try
00488     {
00489         //Initialize all data
00490         if (!m_bInitialized && 
00491             CSpoofBase::IsInitialized())
00492         {
00493             //Create the CS
00494             m_pCSection=COSManager::CreateCriticalSection();
00495 
00496             //Create handlers
00497             if (!SetHandlers())
00498             {
00499                 //Report it
00500                 ReportStaticError(CAsyncSocket_Class,"CAsyncSocket","Failed to init handlers!");
00501 
00502                 //Exit
00503                 return;
00504             }
00505 
00506             //Create a new socket to do the shutdown
00507             CAsyncShutdown* pShutdown;
00508             pShutdown=new CAsyncShutdown;
00509 
00510             //The class registers itself
00511             m_bInitialized=TRUE;
00512         }
00513     }
00514     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"Initialize")
00515 }

void CSpoofSocket::InitializeIP (  )  [protected, virtual, inherited]

Definition at line 1094 of file SpoofSocket.cpp.

01095 {
01096     try
01097     {
01098         //Invalid the socket
01099         m_aSpoofSocket=INVALID_SOCKET;
01100 
01101         //More invalids
01102         m_ulSourceAddress=0;
01103 
01104         //Some defaults
01105         m_ucTTL=IP_DEF_TTL;
01106 
01107         //Set our options
01108         m_pIPOptions=NULL;
01109 
01110         //Not sniffing
01111         m_bSniffing=FALSE;
01112 
01113         //We are not overlapped
01114         m_bOverlapped=FALSE;
01115 
01116         //Not connected
01117         memset(&m_aConnectedTo,
01118                0,
01119                sizeof(m_aConnectedTo));
01120 
01121         //Set options to false
01122         SetOptions(FALSE);
01123     }
01124     ERROR_HANDLER("InitializeIP")
01125 }

BOOL CSpoofBase::InitializeSockets ( BOOL  bMultiThreaded = TRUE,
unsigned long  ulNumberOfThreads = 10 
) [static, inherited]

Definition at line 279 of file SpoofBase.cpp.

00281 {
00282     //To avoid double initialize
00283     if (m_bInitialized)
00284     {
00285         //Report it
00286         ReportStaticError(CSpoofBase_Class,"InitializeSockets","Already initialized!");
00287 
00288         //Exit
00289         return TRUE;
00290     }
00291 
00292     //Check that the number of threads are OK?
00293     if (ulNumberOfThreads>CLibConfig::GetInstance().GetMaxThreads())
00294     {
00295         //Report it
00296         ReportStaticError(CSpoofBase_Class,"InitializeSockets","Too many threads!");
00297 
00298         //Exit
00299         return FALSE;
00300     }
00301 
00302     //Do we have threads at all
00303     if (bMultiThreaded &&
00304         !ulNumberOfThreads)
00305     {
00306         //Report it
00307         ReportStaticError(CSpoofBase_Class,"InitializeSockets","Didn't receive any threads!");
00308 
00309         //Exit
00310         return FALSE;
00311     }
00312 
00313     try
00314     {
00315         //Initialize the sockets
00316         WORD wVersionRequested;
00317         wVersionRequested=MAKEWORD(2,2);
00318  
00319         //Try to initialize
00320         WSADATA wsaData;
00321         int iErr;
00322         iErr=WSAStartup(wVersionRequested, 
00323                         &wsaData);
00324 
00325         //Did we succeed?
00326         if (iErr!=0)
00327             /* Tell the user that we could not find a usable */
00328             /* WinSock DLL.                                  */
00329             return FALSE;
00330  
00331         /* Confirm that the WinSock DLL supports 2.2.*/
00332         /* Note that if the DLL supports versions greater    */
00333         /* than 2.2 in addition to 2.2, it will still return */
00334         /* 2.2 in wVersion since that is the version we      */
00335         /* requested.                                        */
00336  
00337         if (LOBYTE(wsaData.wVersion)!=2 || 
00338             HIBYTE(wsaData.wVersion)!=2)
00339         {
00340             /* Tell the user that we could not find a usable */
00341             /* WinSock DLL.                                  */
00342             WSACleanup();
00343 
00344             //Exit
00345             return FALSE;
00346         }
00347 
00348         //Save the threading information
00349         m_bMultiThreaded=bMultiThreaded;
00350         m_ulNumberOfThreads=ulNumberOfThreads;
00351 
00352         //Create the critical section
00353         m_pCSection=COSManager::CreateCriticalSection();
00354 
00355         //And we are initialized
00356         m_bInitialized=TRUE;
00357 
00358         return TRUE;
00359     }
00360     ERROR_HANDLER_STATIC_RETURN(CSpoofBase_Class,"InitializeSockets",FALSE)
00361 }

BOOL CSpoofBase::InitializeSocketsNoMap ( BOOL  bMultiThreaded = TRUE,
unsigned long  ulNumberOfThreads = 10 
) [static, inherited]

Definition at line 202 of file SpoofBase.cpp.

00204 {
00205     //To avoid double initialize
00206     if (m_bInitialized)
00207     {
00208         //Report it
00209         ReportStaticError(CSpoofBase_Class,"InitializeSocketsNoMap","Already initialized!");
00210 
00211         //Exit
00212         return TRUE;
00213     }
00214 
00215     //Check that the number of threads are OK?
00216     if (ulNumberOfThreads>CLibConfig::GetInstance().GetMaxThreads())
00217     {
00218         //Report it
00219         ReportStaticError(CSpoofBase_Class,"InitializeSocketsNoMap","Too many threads!");
00220 
00221         //Exit
00222         return FALSE;
00223     }
00224 
00225     //Do we have threads at all
00226     if (bMultiThreaded &&
00227         !ulNumberOfThreads)
00228     {
00229         //Report it
00230         ReportStaticError(CSpoofBase_Class,"InitializeSocketsNoMap","Didn't receive any threads!");
00231 
00232         //Exit
00233         return FALSE;
00234     }
00235 
00236     try
00237     {
00238         //Create the thread data
00239         ThreadData* pThreadData;
00240         pThreadData=new ThreadData;
00241 
00242         //Populate the data
00243         pThreadData->pEvent=COSManager::CreateEvent();
00244         pThreadData->bMultiThreaded=bMultiThreaded;
00245         pThreadData->ulNumberOfThreads=ulNumberOfThreads;
00246 
00247         //Create the thread
00248         m_pThread=new CManagedThread(InitProc);
00249         m_pThread->Start((LPVOID)pThreadData);
00250 
00251         //Wait on the event
00252         if (pThreadData->pEvent->Wait(THREAD_TIMEOUT))
00253         {
00254             //Report it
00255             ReportStaticError(CSpoofBase_Class,"InitializeSocketsNoMap","Timeout waiting for thread");
00256 
00257             //Delete the thread
00258             delete m_pThread;
00259             m_pThread=NULL;
00260 
00261             //Exit
00262             return FALSE;
00263         }
00264 
00265         //Are we initialized
00266         if (!IsInitialized())
00267         {
00268             //Delete the thread
00269             delete m_pThread;
00270             m_pThread=NULL;
00271         }
00272 
00273         //Done
00274         return IsInitialized();
00275     }
00276     ERROR_HANDLER_STATIC_RETURN(CSpoofBase_Class,"InitializeSocketsNoMap",FALSE)
00277 }

int CAsyncSocket::InternalWSAAsyncSelect ( unsigned int  wMsg,
long  lEvent 
) [protected, inherited]

Definition at line 739 of file AsyncSocket.cpp.

00740 {
00741     try
00742     {
00743         //Cache the values
00744         m_iMsg=wMsg;
00745         m_lEvent=lEvent;
00746 
00747         //Message pairs
00748         typedef struct _MsgPair
00749         {
00750             unsigned int    uiMsg;
00751             AsyncEvents     aEvents;
00752         } MsgPair;
00753 
00754         //Our max events
00755         static const int iMaxEvents=4;
00756 
00757         //Our events data
00758         static const MsgPair aMsgPair[iMaxEvents]={{FD_READ,aeReceive},
00759                                                    {FD_WRITE,aeSend},
00760                                                    {FD_OOB,aeOOB},
00761                                                    {FD_CLOSE,aeClose}};
00762 
00763         //Check if the messages are allowed
00764         for (int iCounter=0;iCounter<iMaxEvents;++iCounter)
00765             if ((m_lEvent & aMsgPair[iCounter].uiMsg) &&
00766                 (m_ucEvents & ((unsigned char)aMsgPair[iCounter].aEvents)))
00767                 //Remove it
00768                 m_lEvent^=aMsgPair[iCounter].uiMsg;
00769 
00770         if (m_bBlocking)
00771             return 0;
00772         else
00773             //And call the async select
00774             return WSAAsyncSelect(GetAsyncHandle(),
00775                                   GetWindowHandle(),
00776                                   wMsg,
00777                                   lEvent);
00778     }
00779     ERROR_HANDLER_RETURN("InternalWSAAsyncSelect",GetErrorCode())
00780 }

BOOL CTCPSocketAsync::IsAsyncClass (  )  const [protected, virtual, inherited]

Reimplemented from CTCPSocket.

Definition at line 389 of file TCPSocketAsync.cpp.

00390 {
00391     try
00392     {
00393         //Check if we are blocking
00394         if (IsBlocking() || 
00395             m_bDisabledConnect)
00396             return FALSE;
00397         else
00398             //Not blocking
00399             return TRUE;
00400     }
00401     ERROR_HANDLER_RETURN("IsAsyncClass",FALSE)
00402 }

BOOL CAsyncSocket::IsBlocking (  )  const [protected, inherited]

Definition at line 860 of file AsyncSocket.cpp.

00861 {
00862     return m_bBlocking;
00863 }

BOOL CAsyncSocket::IsClosing (  )  const [inherited]

Definition at line 1298 of file AsyncSocket.cpp.

01299 {
01300     return m_bClosing;
01301 }

BOOL CTCPSocket::IsConnected (  )  const [inherited]

Definition at line 798 of file TCPSocket.cpp.

00799 {
00800     return m_bConnected;
00801 }

BOOL CSpoofSocket::IsCreated (  )  const [inherited]

Definition at line 1517 of file SpoofSocket.cpp.

01518 {
01519     return ValidSocket();
01520 }

BOOL CWhoisSocket::IsError (  )  const [virtual]

Definition at line 595 of file WhoisSocket.cpp.

00596 {
00597     return m_bError;
00598 }

BOOL CSpoofBase::IsInitialized (  )  [static, inherited]

Definition at line 468 of file SpoofBase.cpp.

00469 {
00470     return m_bInitialized;
00471 }

BOOL CWhoisSocket::IsIPTrace (  )  const

Definition at line 822 of file WhoisSocket.cpp.

00823 {
00824     return !m_bURL;
00825 }

BOOL CSpoofBase::IsMultiThreaded (  )  [static, inherited]

Definition at line 458 of file SpoofBase.cpp.

00459 {
00460     return m_bMultiThreaded;
00461 }

BOOL CSpoofSocket::IsRaw (  )  const [protected, inherited]

Definition at line 1089 of file SpoofSocket.cpp.

01090 {
01091     return m_bRaw;
01092 }

BOOL CAsyncSocket::IsTimeout (  )  const [protected, inherited]

Reimplemented in CPingSocket.

Definition at line 480 of file AsyncSocket.cpp.

00481 {
00482     return m_bTimeout;
00483 }

BOOL CWhoisSocket::IsWhoisDone (  )  const [virtual]

Definition at line 590 of file WhoisSocket.cpp.

00591 {
00592     return m_bDone;
00593 }

BOOL CAsyncSocket::KillSystemTimer (  )  [protected, inherited]

Definition at line 1129 of file AsyncSocket.cpp.

01130 {
01131     try
01132     {
01133         //Only if we have one
01134         if (!m_aTimerID.iTimerID)
01135             return TRUE;
01136 
01137         return GetThreadManager()->RemoveTimeout(m_aTimerID);
01138     }
01139     ERROR_HANDLER_RETURN("KillSystemTimer",FALSE)
01140 }

BOOL CAsyncSocket::KillTimer (  )  [inherited]

Definition at line 344 of file AsyncSocket.cpp.

00345 {
00346     try
00347     {
00348         HWND hWindowHandle;
00349         hWindowHandle=GetWindowHandle();
00350 
00351         if (!hWindowHandle || 
00352             !m_bTimeout)
00353             return FALSE;
00354 
00355         //No timer in any case
00356         m_bTimeout=FALSE;
00357 
00358         BOOL bResult;
00359         bResult=::KillTimer(hWindowHandle,
00360                             GetAsyncHandle());
00361 
00362         if (!bResult)
00363             //Fire an error
00364             ReportError("KillTimer");
00365 
00366         return bResult;
00367     }
00368     ERROR_HANDLER_RETURN("KillTimer",FALSE)
00369 }

BOOL CTCPSocketAsync::Listen ( unsigned long  ulBackLog = 5  )  [virtual, inherited]

Reimplemented from CTCPSocket.

Definition at line 240 of file TCPSocketAsync.cpp.

00241 {
00242     try
00243     {
00244         //Quit if not ok
00245         if (!CheckSocketValid())
00246             return FALSE;
00247 
00248         //Try to switch the mode
00249         int iResult;
00250         iResult=InternalWSAAsyncSelect(WM_SOCKET_ACCEPT,
00251                                        FD_ACCEPT);
00252 
00253         //Is it OK
00254         if (iResult)
00255         {
00256             //Report it
00257             SetLastError("Listen");
00258 
00259             //Exit
00260             return FALSE;
00261         }
00262 
00263         //Delegate the call
00264         return CTCPSocket::Listen(ulBackLog);
00265     }
00266     ERROR_HANDLER_RETURN("Listen",FALSE)
00267 }

std::string CSpoofBase::LongToStdString ( unsigned long  ulAddr  )  [static, inherited]

Definition at line 420 of file SpoofBase.cpp.

00421 {
00422     try
00423     {
00424         //First create the address
00425         in_addr addr;
00426 
00427         //Assign it
00428         addr.S_un.S_addr=ulAddr;
00429 
00430         //Enter the critical section
00431         CCriticalAutoRelease aRelease(m_pCSection);
00432 
00433         //Return the value
00434         return inet_ntoa(addr);
00435     }
00436     ERROR_HANDLER_STATIC_RETURN(CSpoofBase_Class,"LongToStdString","0.0.0.0")
00437 }

char FAR * CSpoofBase::LongToString ( unsigned long  ulAddr  )  [static, inherited]

Definition at line 439 of file SpoofBase.cpp.

00440 {
00441     try
00442     {
00443         //First create the address
00444         in_addr addr;
00445 
00446         //Assign it
00447         addr.S_un.S_addr=ulAddr;
00448 
00449         //Enter the critical section
00450         CCriticalAutoRelease aRelease(m_pCSection);
00451 
00452         //Return the value
00453         return inet_ntoa(addr);
00454     }
00455     ERROR_HANDLER_STATIC_RETURN(CSpoofBase_Class,"LongToString",NULL)
00456 }

void CSpoofBase::NotifyShutdown (  )  [protected, virtual, inherited]

Definition at line 402 of file SpoofBase.cpp.

00403 {
00404 }

virtual BOOL CAsyncSocket::OnSocketAccept ( int  iErrorCode  )  [protected, pure virtual, inherited]

BOOL CWhoisSocket::OnSocketClose ( int  iErrorCode  )  [protected, virtual]

Implements CAsyncSocket.

Definition at line 321 of file WhoisSocket.cpp.

00322 {
00323     try
00324     {
00325         //Kill the timeout
00326         KillTimer();
00327 
00328         //Close the socket
00329         if (!Close())
00330             ReportError("OnSocketClose","Failed to close socket!");
00331 
00332         //Recreate it
00333         if (!Create())
00334         {
00335             //Report it
00336             ReportError("OnSocketClose","Failed to create socket!");
00337 
00338             //Exit
00339             return FALSE;
00340         }
00341 
00342         //We are done
00343         QueryDone(FALSE,
00344                   FALSE);
00345 
00346         //Done
00347         return TRUE;
00348     }
00349     ERROR_HANDLER_RETURN("OnSocketClose",FALSE)
00350 }

BOOL CWhoisSocket::OnSocketConnect ( int  iErrorCode  )  [protected, virtual]

Implements CAsyncSocket.

Definition at line 280 of file WhoisSocket.cpp.

00281 {
00282     try
00283     {
00284         //Do we have an error
00285         if (iErrorCode)
00286         {
00287             //Report it
00288             ReportError("OnSocketConnect",iErrorCode);
00289 
00290             //We are done
00291             QueryDone(TRUE,
00292                       TRUE);
00293 
00294             //Exit
00295             return FALSE;
00296         }
00297 
00298         //Send the URL
00299         if (!SendURL(m_sDataToSend))
00300         {
00301             //Report it
00302             ReportError("OnSocketConnect","Failed to send data!");
00303 
00304             //We are done
00305             QueryDone(TRUE,
00306                       TRUE);
00307 
00308             //Exit
00309             return FALSE;
00310         }
00311 
00312         //Set the timeout
00313         SetTimeout(m_dwTimeout);
00314 
00315         //Done
00316         return TRUE;
00317     }
00318     ERROR_HANDLER_RETURN("OnSocketConnect",FALSE)
00319 }

void CAsyncSocket::OnSocketDelete (  )  [protected, virtual, inherited]

Definition at line 1185 of file AsyncSocket.cpp.

01186 {
01187     try
01188     {
01189         //Delete ourselves
01190         delete this;
01191     }
01192     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"OnSocketDelete")
01193 }

virtual BOOL CAsyncSocket::OnSocketOOB ( int  iErrorCode  )  [protected, pure virtual, inherited]

BOOL CWhoisSocket::OnSocketReceive ( int  iErrorCode  )  [protected, virtual]

Implements CAsyncSocket.

Definition at line 352 of file WhoisSocket.cpp.

00353 {
00354     try
00355     {
00356         //Kill the timer
00357         KillTimer();
00358 
00359         //Do we have an error
00360         if (iErrorCode)
00361         {
00362             //Report it
00363             ReportError("OnSocketReceive",iErrorCode);
00364 
00365             //We are done
00366             QueryDone(TRUE,
00367                       TRUE);
00368 
00369             //Exit
00370             return FALSE;
00371         }
00372 
00373         //Receive the data
00374         char aData[4000];
00375 
00376         //Get the data
00377         int iSize;
00378         iSize=Receive(aData,sizeof(aData)/2-1);
00379 
00380         //Is an error
00381         if (iSize==GetErrorCode())
00382         {
00383             //We are done
00384             QueryDone(TRUE,
00385                       TRUE);
00386 
00387             //Exit
00388             return FALSE;
00389         }
00390 
00391         //Remove nulls
00392         for (int iCounter=0;
00393              iCounter<iSize;
00394              iCounter++)
00395             if (!aData[iCounter])
00396                 aData[iCounter]=10;
00397 
00398         //Set the terminating sero
00399         aData[iSize]=0;
00400 
00401         //Modify it
00402         ModifyBuffer(aData,iSize+1);
00403 
00404         //Add it to the string
00405         m_sWhoisData+=aData;
00406 
00407         //Reset the timeout
00408         SetTimeout(m_dwTimeout);
00409         
00410         //Done
00411         return TRUE;
00412     }
00413     ERROR_HANDLER_RETURN("OnSocketReceive",FALSE)
00414 }

BOOL CWhoisSocket::OnSocketTimeout (  )  [protected, virtual]

Implements CAsyncSocket.

Definition at line 263 of file WhoisSocket.cpp.

00264 {
00265     try
00266     {
00267         //Kill the timer
00268         KillTimer();
00269 
00270         //We are done
00271         QueryDone(TRUE,
00272                   TRUE);
00273 
00274         //Exit
00275         return FALSE;
00276     }
00277     ERROR_HANDLER_RETURN("OnSocketTimeout",FALSE)
00278 }

virtual BOOL CAsyncSocket::OnSocketWrite ( int  iErrorCode  )  [protected, pure virtual, inherited]

bool CSpoofSocket::operator< ( const CSpoofSocket rSocket  )  const [inherited]

Definition at line 1601 of file SpoofSocket.cpp.

01602 {
01603     return m_aSpoofSocket<rSocket.m_aSpoofSocket;
01604 }

bool CSpoofSocket::operator== ( const CSpoofSocket rSocket  )  const [inherited]

Definition at line 1596 of file SpoofSocket.cpp.

01597 {
01598     return m_aSpoofSocket==rSocket.m_aSpoofSocket;
01599 }

BOOL CAsyncSocket::ReAsync (  )  [virtual, inherited]

Definition at line 782 of file AsyncSocket.cpp.

00783 {
00784     if (!m_bBlocking)
00785         return TRUE;
00786 
00787     try
00788     {
00789         //Quit if not ok
00790         if (!CheckAsyncSocketValid())
00791             return FALSE;
00792 
00793         //First disable the events
00794         int iResult;
00795         iResult=WSAAsyncSelect(GetAsyncHandle(),
00796                                GetWindowHandle(),
00797                                m_iMsg,
00798                                m_lEvent);
00799 
00800         if (iResult)
00801         {
00802             //Report it
00803             SetLastError("ReAsync");
00804 
00805             //Exit
00806             return FALSE;
00807         }
00808 
00809         //Set to async
00810         m_bBlocking=FALSE;
00811 
00812         //And quit
00813         return TRUE;
00814     }
00815     ERROR_HANDLER_RETURN("ReAsync",FALSE)
00816 }

BOOL CAsyncSocket::ReBlock (  )  [virtual, inherited]

Definition at line 718 of file AsyncSocket.cpp.

00719 {
00720     if (m_bBlocking)
00721         return TRUE;
00722 
00723     try
00724     {
00725         //Quit if not ok
00726         if (!CheckAsyncSocketValid())
00727             return FALSE;
00728 
00729         if (Block())
00730             //Set to reblock
00731             m_bBlocking=TRUE;
00732 
00733         //And quit
00734         return TRUE;
00735     }
00736     ERROR_HANDLER_RETURN("ReBlock",FALSE)
00737 }

int CTCPSocketAsync::Receive ( char *  pBuffer,
unsigned long  ulBufferLength 
) [virtual, inherited]

Reimplemented from CSpoofSocket.

Definition at line 529 of file TCPSocketAsync.cpp.

00531 {
00532     try
00533     {
00534         //Try to receive
00535         int iResult;
00536         if ((iResult=CTCPSocket::Receive(pBuffer,
00537                                          ulBufferLength))>=0)
00538             return iResult;
00539         //Check is it an error
00540         else if (GetSystemLastError()==WSAEWOULDBLOCK)
00541             return 0;
00542         else
00543             return GetErrorCode();
00544     }
00545     ERROR_HANDLER_RETURN("Receive",GetErrorCode())
00546 }

int CSpoofSocket::ReceiveFrom ( char *  pBuffer,
unsigned long  ulBufferLength,
IP rIP,
unsigned short &  rSourcePort 
) [protected, virtual, inherited]

Definition at line 1140 of file SpoofSocket.cpp.

01144 {
01145     try
01146     {
01147         if (!ValidSocket() ||
01148             !pBuffer ||
01149             !ulBufferLength)
01150             return GetErrorCode();
01151 
01152         //Receive data
01153         int iResult;
01154 
01155         //Receive
01156         if (m_ucProtocol!=IPPROTO_TCP && 
01157             !m_bSniffing)
01158         {
01159             //Get the remote address
01160             sockaddr saConnected;
01161 
01162             int iTmp;
01163             iTmp=sizeof(saConnected);
01164 
01165             //Accept it
01166             iResult=recvfrom(GetHandle(),
01167                              pBuffer,
01168                              ulBufferLength,
01169                              NULL,
01170                              &saConnected,
01171                              &iTmp);
01172 
01173             //If OK set it
01174             if (iResult!=GetErrorCode())
01175             {
01176                 //Address
01177                 rIP=((sockaddr_in*)&saConnected)->sin_addr.S_un.S_addr;
01178 
01179                 //Port
01180                 rSourcePort=htons(((sockaddr_in*)&saConnected)->sin_port);
01181 
01182                 //Done
01183                 return iResult;
01184             }
01185             else
01186             {
01187                 //Error
01188                 SetLastError("Receive");
01189 
01190                 //Reset the data
01191                 rIP=0;
01192                 rSourcePort=0;
01193 
01194                 //Done
01195                 return iResult;
01196             }
01197         }
01198         else
01199         {
01200             //Report it
01201             ReportError("Receive","Can't run on TCP socket!");
01202 
01203             //Exit
01204             return GetErrorCode();
01205         }
01206     }
01207     ERROR_HANDLER_RETURN("Receive",GetErrorCode())
01208 }

void CSpoofBase::RegisterShutdown ( CSpoofBase pBase  )  [protected, inherited]

Definition at line 406 of file SpoofBase.cpp.

00407 {
00408     try
00409     {
00410         //Check if we already have a class
00411         if (m_pShutdownClass)
00412             delete m_pShutdownClass;
00413 
00414         //Take it
00415         m_pShutdownClass=pBase;
00416     }
00417     ERROR_HANDLER("RegisterShutdown")
00418 }

void CAsyncSocket::RemoveSocketFromList (  )  [protected, inherited]

Definition at line 303 of file AsyncSocket.cpp.

00304 {
00305     try
00306     {
00307         if (m_bList)
00308             if (m_pCSection)
00309             {
00310                 //Enter the CS
00311                 CCriticalAutoRelease aRelease(m_pCSection);
00312 
00313                 //Erase it
00314                 m_aSocketMap.erase(GetSocketID());
00315             }
00316             else
00317                 ReportError("RemoveSocketFromList","Critical section not initialized");
00318     }
00319     ERROR_HANDLER("RemoveSocketFromList")
00320 }

void CErrorHandler::ReportError ( const std::string &  rMethod,
const std::string &  rMessage,
int  iErrorCode 
) const [protected, virtual, inherited]

Definition at line 154 of file ErrorHandler.cpp.

00157 {
00158     if (!GetLog())
00159         return;
00160 
00161     try
00162     {
00163         //Get the log
00164         CErrorLog* pLog;
00165         pLog=GetLog();
00166 
00167         //Convert the error code
00168         char aTmp[11];
00169         sprintf(aTmp,"%d",iErrorCode);
00170 
00171         //Get the string for it
00172         std::string sError;
00173         sError=rMessage;
00174         sError+=", and Socket error: ";
00175         sError+=aTmp;
00176         sError+=", ";
00177         sError+=ErrorCodeToString(iErrorCode);
00178 
00179         //Report to the log
00180         pLog->ReportError(m_sClassName,
00181                           rMethod,
00182                           sError);
00183     }
00184     ERROR_UNKNOWN("ReportError")
00185 }

void CErrorHandler::ReportError ( const std::string &  rMethod,
int  iErrorCode 
) const [protected, virtual, inherited]

Definition at line 187 of file ErrorHandler.cpp.

00189 {
00190     if (!GetLog())
00191         return;
00192 
00193     try
00194     {
00195         //Get the log
00196         CErrorLog* pLog;
00197         pLog=GetLog();
00198 
00199         //Convert the error code
00200         char aTmp[11];
00201         sprintf(aTmp,"%d",iErrorCode);
00202 
00203         //Get the string for it
00204         std::string sError;
00205         sError="Socket error: ";
00206         sError+=aTmp;
00207         sError+=", ";
00208         sError+=ErrorCodeToString(iErrorCode);
00209 
00210         //Report to the log
00211         pLog->ReportError(m_sClassName,
00212                           rMethod,
00213                           sError);
00214     }
00215     ERROR_UNKNOWN("ReportError")
00216 }

void CErrorHandler::ReportError ( const std::string &  rMethod,
const std::string &  rMessage,
DWORD  dwAdditionalData 
) const [protected, virtual, inherited]

Definition at line 275 of file ErrorHandler.cpp.

00278 {
00279     if (!GetLog())
00280         return;
00281 
00282     try
00283     {
00284         //Get the log
00285         CErrorLog* pLog;
00286         pLog=GetLog();
00287 
00288         //Convert the number
00289         char aTmp[11];
00290         ltoa(dwAdditionalData,aTmp,10);
00291 
00292         //Create the new message
00293         std::string sNewMessage(rMessage);
00294         sNewMessage+="Additional data: ";
00295         sNewMessage+=aTmp;
00296 
00297         //Report to the log
00298         pLog->ReportError(m_sClassName,
00299                           rMethod,
00300                           sNewMessage);
00301     }
00302     ERROR_UNKNOWN("ReportError")
00303 }

void CErrorHandler::ReportError ( const std::string &  rMethod,
const std::string &  rMessage 
) const [protected, virtual, inherited]

Definition at line 218 of file ErrorHandler.cpp.

00220 {
00221     if (!GetLog())
00222         return;
00223 
00224     try
00225     {
00226         CErrorLog* pLog;
00227         pLog=GetLog();
00228 
00229         //Report to the log
00230         pLog->ReportError(m_sClassName,
00231                           rMethod,
00232                           rMessage);
00233     }
00234     ERROR_UNKNOWN("ReportError")
00235 }

void CErrorHandler::ReportError ( const std::string &  rMethod  )  const [protected, virtual, inherited]

Definition at line 311 of file ErrorHandler.cpp.

00312 {
00313     if (!GetLog())
00314         return;
00315 
00316     try
00317     {
00318 #ifdef WIN32
00319         //Get the last error
00320         DWORD dwLastError;
00321         dwLastError=GetLastError();
00322 
00323         //Report the error
00324         GetLog()->ReportError(m_sClassName,
00325                               rMethod,
00326                               ErrorCodeToString(dwLastError));
00327 
00328 #else
00329         GetLog()->ReportCatchError(m_sClassName,
00330                                    rMethod,
00331                                    "Unknown error!");
00332 #endif
00333     }
00334     ERROR_UNKNOWN("ReportError")
00335 }

void CErrorHandler::ReportErrorOS ( const std::string &  rMethod,
const std::string &  rMessage 
) const [protected, virtual, inherited]

Definition at line 237 of file ErrorHandler.cpp.

00239 {
00240     if (!GetLog())
00241         return;
00242 
00243     try
00244     {
00245         //Get the last error
00246         DWORD dwLastError;
00247         dwLastError=GetLastError();
00248 
00249         //Format the message
00250         std::string sMessage;
00251         sMessage=rMessage;
00252         sMessage+=", with error code: ";
00253 
00254         //Convert the error code
00255         char aTmp[11];
00256         itoa(dwLastError,aTmp,10);
00257 
00258         //Add it again
00259         sMessage+=aTmp;
00260         sMessage+=" ";
00261         sMessage+=ErrorCodeToString(dwLastError);
00262         
00263         //Get the log
00264         CErrorLog* pLog;
00265         pLog=GetLog();
00266 
00267         //Report to the log
00268         pLog->ReportError(m_sClassName,
00269                           rMethod,
00270                           sMessage);
00271     }
00272     ERROR_UNKNOWN("ReportErrorOS")
00273 }

void CErrorHandler::ReportStaticError ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMessage,
DWORD  dwAdditionalData 
) [static, protected, inherited]

Definition at line 489 of file ErrorHandler.cpp.

00493 {
00494     if (!m_pLog)
00495         return;
00496 
00497     try
00498     {
00499         //Convert the number
00500         char aTmp[11];
00501         ltoa(dwAdditionalData,aTmp,10);
00502 
00503         //Create the new message
00504         std::string sNewMessage(rMessage);
00505         sNewMessage+="Additional data: ";
00506         sNewMessage+=aTmp;
00507 
00508         //Report to the log
00509         m_pLog->ReportError(rClass,
00510                             rMethod,
00511                             sNewMessage);
00512     }
00513     ERROR_UNKNOWN("ReportStaticError")
00514 }

void CErrorHandler::ReportStaticError ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMessage 
) [static, protected, inherited]

Definition at line 472 of file ErrorHandler.cpp.

00475 {
00476     if (!m_pLog)
00477         return;
00478 
00479     try
00480     {
00481         //Report to the log
00482         m_pLog->ReportError(rClass,
00483                             rMethod,
00484                             rMessage);
00485     }
00486     ERROR_UNKNOWN("ReportStaticError")
00487 }

void CErrorHandler::ReportStaticError ( const std::string &  rClass,
const std::string &  rMethod 
) [static, protected, inherited]

Definition at line 446 of file ErrorHandler.cpp.

00448 {
00449     if (!m_pLog)
00450         return;
00451 
00452     try
00453     {
00454 #ifdef WIN32
00455         //Get the last error
00456         DWORD dwLastError;
00457         dwLastError=GetLastError();
00458 
00459         //Report the error
00460         m_pLog->ReportError(rClass,
00461                             rMethod,
00462                             ErrorCodeToString(dwLastError));
00463 #else
00464         m_pLog->ReportError(rClass,
00465                             rMethod,
00466                             "Unknown error!");
00467 #endif
00468     }
00469     ERROR_UNKNOWN("ReportStaticError")
00470 }

long CSpoofSocket::ResolveDNS ( const std::string &  rAddress  )  [static, inherited]

Definition at line 1300 of file SpoofSocket.cpp.

01301 {
01302     try
01303     {
01304         //Resolve the DNS
01305         sockaddr_in aAddr;
01306         aAddr=InternalResolveDNS(rAddress.c_str());
01307 
01308         //Check if valid
01309         if (aAddr.sin_addr.S_un.S_addr==0)
01310             //Error
01311             return 0;
01312         else
01313             return aAddr.sin_addr.S_un.S_addr;
01314     }
01315     ERROR_HANDLER_STATIC_RETURN(CSpoofSocket_LOGNAME,"ResolveDNS",0)
01316 }

int CSpoofSocket::Send ( const std::string &  rDestinationAddress,
const char *  pBuffer,
unsigned long  ulBufferLength,
unsigned short  usDestinationPort = 0 
) [virtual, inherited]

Definition at line 759 of file SpoofSocket.cpp.

00763 {
00764     try
00765     {
00766         //Quit if not ok
00767         if (!CheckSocketValid())
00768             return GetErrorCode();
00769 
00770         return Send(inet_addr(rDestinationAddress.c_str()),
00771                     pBuffer,
00772                     ulBufferLength,
00773                     usDestinationPort);
00774     }
00775     ERROR_HANDLER_RETURN("Send",GetErrorCode())
00776 }

int CSpoofSocket::Send ( IP  aDestinationAddress,
const char *  pBuffer,
unsigned long  ulBufferLength,
unsigned short  usDestinationPort = 0 
) [virtual, inherited]

Definition at line 604 of file SpoofSocket.cpp.

00608 {
00609     try
00610     {
00611         //Quit if not ok
00612         if (!CheckSocketValid())
00613             return GetErrorCode();
00614 
00615         //Is it a valid size
00616         if (ulBufferLength &&
00617             !pBuffer)
00618             return GetErrorCode();
00619 
00620         //Define the target address
00621         sockaddr_in aTargetAddress;
00622         memset(&aTargetAddress,
00623                0,
00624                sizeof(aTargetAddress));
00625 
00626         aTargetAddress.sin_family=AF_INET;
00627         aTargetAddress.sin_addr.s_addr=aDestinationAddress;
00628         aTargetAddress.sin_port=htons(usDestinationPort);
00629 
00630         //packet send status ?
00631         int iResult;
00632 
00633         //Only if allowing raw headers !!
00634         if (m_bRaw)
00635         {
00636             //Header length
00637             unsigned char ucHeaderLength;
00638             ucHeaderLength=IpHeaderLength;
00639 
00640             //Do we have options?
00641             if (m_bOptions)
00642                 ucHeaderLength+=m_pIPOptions->GetBufferLength();
00643             
00644             //First construct the packet
00645             LPIpHeader lpHead=ConstructIPHeader(m_ucProtocol,
00646                                                 IpFragFlag_DONT_FRAG,
00647                                                 m_ucTTL,
00648                                                 (unsigned short)GetCurrentProcessId(),
00649                                                 ucHeaderLength);
00650 
00651             //Protect the header
00652             std::auto_ptr<IpHeader> pProtection(lpHead);
00653 
00654             //Set the address
00655             SetIPHeaderAddress(lpHead,
00656                                m_ulSourceAddress,
00657                                aDestinationAddress);
00658 
00659             //Now add some more options
00660             int iTotalLength;
00661             iTotalLength=ucHeaderLength+ulBufferLength;
00662 
00663             //Set the header
00664             lpHead->usTotalLength=htons(iTotalLength);
00665 
00666             //Need to construct a new packet
00667             char* pNewBuffer;
00668             pNewBuffer=new char[iTotalLength];
00669 
00670             //Protect the buffer
00671             CArray_ptr<char> pBufferProtection(pNewBuffer);
00672 
00673             //Copy two buffers
00674             memcpy(pNewBuffer,
00675                    lpHead,
00676                    IpHeaderLength);
00677 
00678             //Do we need to copy options ?
00679             if (m_bOptions)
00680                 memcpy(pNewBuffer+IpHeaderLength,
00681                        m_pIPOptions->GetBuffer(),
00682                        m_pIPOptions->GetBufferLength());
00683 
00684             //Only if not null
00685             if (pBuffer)
00686                 memcpy(pNewBuffer+ucHeaderLength,
00687                        pBuffer,
00688                        ulBufferLength);
00689             
00690             //Calculate the checksum
00691             lpHead->usChecksum=CalculateChecksum((unsigned short*)pNewBuffer,
00692                                                  ucHeaderLength);
00693 
00694             //Alert everyone this is the final header
00695             FinalIPHeader(lpHead);
00696 
00697             //Recopy the ip
00698             memcpy(pNewBuffer,
00699                    lpHead,
00700                    IpHeaderLength);
00701             
00702             //Send the data
00703             iResult=sendto(GetHandle(),
00704                            (const char*)pNewBuffer,
00705                            iTotalLength,
00706                            0,
00707                            (sockaddr*)&aTargetAddress,
00708                            sizeof(aTargetAddress));
00709 
00710             //Is all OK
00711             if (iResult==GetErrorCode() &&
00712                 GetSystemLastError()!=WSAEWOULDBLOCK)
00713                 //Set the error
00714                 SetLastError("Send - Raw");
00715         }
00716         else
00717         {
00718             //Set to no error
00719             iResult=!GetErrorCode();
00720 
00721             //Insert options
00722             /*if (m_bOptions)
00723                 iResult=setsockopt(GetHandle(),
00724                                    IPPROTO_IP,
00725                                    IP_OPTIONS,
00726                                    m_pIPOptions->GetBuffer(),
00727                                    m_pIPOptions->GetBufferLength());
00728             else
00729                 //No options
00730                 iResult=setsockopt(GetHandle(),
00731                                    IPPROTO_IP,
00732                                    IP_OPTIONS,
00733                                    NULL,
00734                                    0);*/
00735 
00736             //Check if we had an error
00737             if (iResult!=GetErrorCode())
00738                 //Use regular send !!!
00739                 iResult=sendto(GetHandle(),
00740                                (const char*)pBuffer,
00741                                ulBufferLength,
00742                                0,
00743                                (sockaddr*)&aTargetAddress,
00744                                sizeof(aTargetAddress));
00745             
00746             //Is all OK?
00747             if (iResult==GetErrorCode() &&
00748                 GetSystemLastError()!=WSAEWOULDBLOCK)
00749                 //Set the error
00750                 SetLastError("Send");
00751         }
00752         
00753         //Done
00754         return iResult;
00755     }
00756     ERROR_HANDLER_RETURN("Send",GetErrorCode())
00757 }

int CTCPSocketAsync::Send ( const char *  pBuffer,
unsigned long  ulBufferLength 
) [virtual, inherited]

Reimplemented from CTCPSocket.

Definition at line 425 of file TCPSocketAsync.cpp.

00427 {
00428     try
00429     {
00430         //Send the data
00431         int iResult;
00432         iResult=SendNoAdd(pBuffer,
00433                           ulBufferLength);
00434 
00435         //Did we succeed ?
00436         if (iResult==GetErrorCode())
00437             //Is it blocked send ?
00438             if (WSAGetLastError()==WSAEWOULDBLOCK &&
00439                 GetBlockedBuffer())
00440             {
00441                 //Add to the buffer, if we have one
00442                 GetBlockedBuffer()->AddRecord(CBlockedBuffer::CBlockedData(pBuffer,
00443                                                                            ulBufferLength));
00444 
00445                 //We have not error
00446                 iResult=0;
00447             }
00448             //Blocking error (not really an error)
00449             else if (WSAGetLastError()==WSAEWOULDBLOCK)
00450                 return 0;
00451             else
00452                 //Set the error code
00453                 SetLastError("Send");
00454 
00455         //Done
00456         return iResult;
00457     }
00458     ERROR_HANDLER_RETURN("Send",GetErrorCode())
00459 }

BOOL CTCPSocketAsync::SendBlockedBuffer ( const CBlockedBuffer::CBlockedData rData  )  [protected, virtual, inherited]

Reimplemented from CAsyncSocket.

Definition at line 414 of file TCPSocketAsync.cpp.

00415 {
00416     try
00417     {
00418         //Try to send it
00419         return SendNoAdd(rData.GetData(),
00420                          rData.GetDataSize())!=GetErrorCode();
00421     }
00422     ERROR_HANDLER_RETURN("SendBlockedBuffer",FALSE)
00423 }

int CTCPSocketAsync::SendNoAdd ( const char *  pBuffer,
unsigned long  ulBufferLength 
) [protected, virtual, inherited]

Definition at line 461 of file TCPSocketAsync.cpp.

00463 {
00464     try
00465     {
00466         //Quit if not ok
00467         if (!CheckSocketValid())
00468             return FALSE;
00469 
00470         //Send the data
00471         int iResult;
00472 
00473         //And send it
00474         iResult=send(GetHandle(),
00475                      pBuffer,
00476                      ulBufferLength,
00477                      NULL);
00478 
00479         //And exit
00480         return iResult;
00481     }
00482     ERROR_HANDLER_RETURN("SendNoAdd",GetErrorCode())
00483 }

int CTCPSocket::SendRaw ( unsigned short  usSourcePort,
const std::string &  rDestinationAddress,
unsigned short  usDestinationPort,
const char *  pBuffer,
unsigned long  ulBufferLength,
unsigned char  ucFlags = 0 
) [protected, virtual, inherited]

Reimplemented in CTCPCrafter.

Definition at line 608 of file TCPSocket.cpp.

00614 {
00615     try
00616     {
00617         //Quit if not ok
00618         if (!CheckSocketValid())
00619             return FALSE;
00620 
00621         return SendRaw(usSourcePort,
00622                        StringToLong(rDestinationAddress),
00623                        usDestinationPort,
00624                        pBuffer,
00625                        ulBufferLength,
00626                        ucFlags);
00627     }
00628     ERROR_HANDLER_RETURN("SendRaw",GetErrorCode())
00629 }

int CTCPSocket::SendRaw ( unsigned short  usSourcePort,
IP  aDestinationAddress,
unsigned short  usDestinationPort,
const char *  pBuffer,
unsigned long  ulBufferLength,
unsigned char  ucFlags = 0 
) [protected, virtual, inherited]

Reimplemented in CTCPCrafter.

Definition at line 631 of file TCPSocket.cpp.

00637 {
00638     try
00639     {
00640         //Quit if not ok
00641         if (!CheckSocketValid())
00642             return FALSE;
00643 
00644         if (IsRaw())
00645         {
00646             //Let's try our first attack
00647             LPTCPHeader lpHead;
00648 
00649             //Header length
00650             int iHeaderLength;
00651             iHeaderLength=TCPHeaderLength;
00652 
00653             //If we have TCP options
00654             if (m_bOptions)
00655                 iHeaderLength+=m_pTCPOptions->GetBufferLength();
00656 
00657             //Create the header
00658             lpHead=ConstructTCPHeader(usSourcePort,
00659                                       usDestinationPort,
00660                                       iHeaderLength);
00661 
00662             //Protect the header
00663             std::auto_ptr<TCPHeader> pProtection(lpHead);
00664 
00665             //Set the flags
00666             if (ucFlags)
00667                 //Set the flags
00668                 SetHeaderFlag(lpHead,ucFlags);
00669             
00670             //Result 
00671             int iResult;
00672 
00673             //Construct diffrently if we have options
00674             if (m_bOptions)
00675             {
00676                 //Allocate the data
00677                 char* pOptionBuffer;
00678                 pOptionBuffer=new char[iHeaderLength+ulBufferLength];
00679 
00680                 //Protect the buffer
00681                 CArray_ptr<char> pBufferProtection(pOptionBuffer);
00682 
00683                 //Copy header
00684                 memcpy(pOptionBuffer,
00685                        lpHead,
00686                        TCPHeaderLength);
00687             
00688                 //Copy options
00689                 memcpy(pOptionBuffer+TCPHeaderLength,
00690                        m_pTCPOptions->GetBuffer(),
00691                        m_pTCPOptions->GetBufferLength());
00692 
00693                 //Do we have the buffer
00694                 if (ulBufferLength)
00695                     //Copy the data
00696                     memcpy(pOptionBuffer+
00697                              TCPHeaderLength+
00698                              m_pTCPOptions->GetBufferLength(),
00699                            pBuffer,
00700                            ulBufferLength);
00701 
00702                 //Calculate the total length
00703                 int iTotalLength;
00704                 iTotalLength=iHeaderLength+ulBufferLength;
00705 
00706                 //Change the header
00707                 lpHead->ucDataOffset=(iTotalLength >> 2) << 4;
00708 
00709                 //Checksum it
00710                 lpHead->usChecksum=CalculatePseudoChecksum(pOptionBuffer,
00711                                                            iTotalLength,
00712                                                            aDestinationAddress,
00713                                                            iTotalLength);
00714                 
00715                 //Last change to the header
00716                 FinalTCPHeader(lpHead);
00717 
00718                 //Recopy header
00719                 memcpy(pOptionBuffer,
00720                        lpHead,
00721                        TCPHeaderLength);
00722 
00723                 //Send the data
00724                 iResult=CSpoofSocket::Send(aDestinationAddress,
00725                                            pOptionBuffer,
00726                                            iHeaderLength,
00727                                            usDestinationPort);
00728             }
00729             else
00730             {
00731                 //Our total length
00732                 unsigned long ulTotalLength;
00733                 ulTotalLength=iHeaderLength+ulBufferLength;
00734 
00735                 //Allocate the buffer
00736                 char* pNewBuffer;
00737                 pNewBuffer=new char[ulTotalLength];
00738 
00739                 //Protect the buffer
00740                 CArray_ptr<char> pBufferProtection(pNewBuffer);
00741 
00742                 //Copy the header
00743                 memcpy(pNewBuffer,
00744                        lpHead,
00745                        ulTotalLength);
00746 
00747                 //Copy the data
00748                 if (ulBufferLength)
00749                     //Copy the data
00750                     memcpy(pNewBuffer+iHeaderLength,
00751                            pBuffer,
00752                            ulBufferLength);
00753 
00754                 //Calculate the checksum
00755                 lpHead->usChecksum=CalculatePseudoChecksum(pNewBuffer,
00756                                                            ulTotalLength,
00757                                                            aDestinationAddress,
00758                                                            ulTotalLength);
00759 
00760                 //Last change to the header
00761                 FinalTCPHeader(lpHead);
00762 
00763                 //Copy the header
00764                 memcpy(pNewBuffer,
00765                        lpHead,
00766                        iHeaderLength);
00767 
00768                 //Send the data
00769                 iResult=CSpoofSocket::Send(aDestinationAddress,
00770                                            pNewBuffer,
00771                                            ulTotalLength,
00772                                            usDestinationPort);
00773             }
00774 
00775             //Set the last error
00776             SetLastError("Connect");
00777 
00778             //Exit
00779             return iResult;
00780         }
00781         else
00782         {
00783             //Report it
00784             ReportError("SendRaw","Packet not in raw mode!");
00785 
00786             //Exit
00787             return GetErrorCode();
00788         }
00789     }
00790     ERROR_HANDLER_RETURN("SendRaw",GetErrorCode())
00791 }

int CSpoofSocket::SendRawBuffer ( IP  aDestinationAddress,
const char *  pBuffer,
unsigned long  ulBufferLength,
unsigned short  usDestinationPort 
) [virtual, inherited]

Definition at line 563 of file SpoofSocket.cpp.

00567 {
00568     try
00569     {
00570         //Quit if not ok
00571         //Make things the fastest
00572         if (m_aSpoofSocket==INVALID_SOCKET ||
00573             !m_bRaw)
00574             return FALSE;
00575 
00576         //Define the target address
00577         sockaddr_in m_TargetAddress;
00578 
00579         m_TargetAddress.sin_family=AF_INET;
00580         m_TargetAddress.sin_addr.s_addr=aDestinationAddress;
00581         m_TargetAddress.sin_port=htons(usDestinationPort);
00582         memset(&m_TargetAddress.sin_zero,0,sizeof(m_TargetAddress.sin_zero));
00583 
00584         //And send the data
00585         //Send the data
00586         int iResult;
00587         iResult=sendto(GetHandle(),
00588                        pBuffer,
00589                        ulBufferLength,
00590                        0,
00591                        (sockaddr*)&m_TargetAddress,
00592                        sizeof(m_TargetAddress));
00593 
00594         if (iResult==GetErrorCode())
00595             //Set the error
00596             SetLastError("SendRawBuffer");
00597 
00598         //Done
00599         return iResult;
00600     }
00601     ERROR_HANDLER_RETURN("SendRawBuffer",GetErrorCode())
00602 }

BOOL CTCPSocketAsync::SetAsync (  )  [protected, virtual, inherited]

Implements CAsyncSocket.

Definition at line 269 of file TCPSocketAsync.cpp.

00270 {
00271     try
00272     {
00273         //Quit if not ok
00274         if (!CheckSocketValid())
00275             return FALSE;
00276 
00277         //Set event to read / write / close / oob
00278         int iResult;
00279         iResult=InternalWSAAsyncSelect(WM_SOCKET_GENERAL,
00280                                        FD_WRITE | FD_READ | FD_CLOSE | FD_OOB);
00281 
00282         //What happend
00283         if (iResult)
00284         {
00285             //Report it
00286             SetLastError("SetAsync");
00287 
00288             //Exit
00289             return FALSE;
00290         }
00291         
00292         //Done
00293         return TRUE;
00294     }
00295     ERROR_HANDLER_RETURN("SetAsync",FALSE)
00296 }

BOOL CSpoofSocket::SetBroadcast ( BOOL  bBroadcast  )  [inherited]

Definition at line 1522 of file SpoofSocket.cpp.

01523 {
01524     try
01525     {
01526         //Quit if not ok
01527         if (!CheckSocketValid())
01528             return FALSE;
01529 
01530         //Set broadcast option
01531         if(setsockopt(GetHandle(),
01532                       SOL_SOCKET,
01533                       SO_BROADCAST,
01534                       (char*)&bBroadcast,
01535                       sizeof(bBroadcast))==GetErrorCode())
01536         {
01537             //Check for options error
01538             SetLastError("SetBroadcast");
01539 
01540             //Exit
01541             return FALSE;
01542         }   
01543 
01544         return TRUE;
01545     }
01546     ERROR_HANDLER_RETURN("SetBroadcast",FALSE)
01547 }

void CSpoofSocket::SetConnectedTo ( const sockaddr_in &  rAddress  )  [protected, inherited]

Definition at line 1606 of file SpoofSocket.cpp.

01607 {
01608     m_aConnectedTo=rAddress;
01609 }

void CTCPSocket::SetConnectionStatus ( BOOL  bConnected  )  [protected, inherited]

Definition at line 793 of file TCPSocket.cpp.

00794 {
00795     m_bConnected=bConnected;
00796 }

BOOL CTCPSocketAsync::SetConnectionTimeout ( unsigned long  ulMS  )  [inherited]

Definition at line 499 of file TCPSocketAsync.cpp.

00500 {
00501     try
00502     {
00503         //Do we have a timeout ?
00504         if (HasSystemTimer())
00505             if (!KillSystemTimer())
00506             {
00507                 //Report it
00508                 ReportError("SetConnectionTimeout","Failed to kill previous timer!");
00509 
00510                 //Exit
00511                 return FALSE;
00512             }
00513 
00514         //Create the timer
00515         m_ulTimeout=ulMS;
00516 
00517         //Done
00518         return TRUE;
00519     }
00520     ERROR_HANDLER_RETURN("SetConnectionTimeout",FALSE)
00521 }

void CAsyncSocket::SetInstance ( HINSTANCE  hInst  )  [static, inherited]

Definition at line 275 of file AsyncSocket.cpp.

00276 {
00277     m_hInstance=hInst;
00278 }

void CSpoofSocket::SetIPHeaderAddress ( LPIpHeader  lpHead,
IP  aSourceAddress,
IP  aDestinationAddress 
) const [protected, virtual, inherited]

Definition at line 791 of file SpoofSocket.cpp.

00794 {
00795     try
00796     {
00797         //We need to place the header
00798         //If source is NULL then we need to use default source
00799         if (!aSourceAddress || !aDestinationAddress)
00800         {
00801             //Report it
00802             ReportError("SetIPHeaderAddress","Recieved empty source or destination address!");
00803 
00804             //Exit
00805             return;
00806         }
00807 
00808         //Place source address
00809         lpHead->ulSourceAddress=aSourceAddress;
00810 
00811         //Place destination address
00812         lpHead->ulDestinationAddress=aDestinationAddress;
00813 
00814         //Done
00815     }
00816     ERROR_HANDLER("SetIPHeaderAddress")
00817 }

void CSpoofBase::SetLastError ( const std::string &  rMethod,
int  iErrorCode 
) const [protected, inherited]

Definition at line 122 of file SpoofBase.cpp.

00124 {
00125     try
00126     {
00127         //First set the error
00128         m_iLastError=iErrorCode;
00129 
00130         //Check if there is an error
00131         if (m_iLastError)
00132             ReportError(rMethod,
00133                         m_iLastError);
00134     }
00135     ERROR_HANDLER("SetLastError")
00136 }

void CSpoofBase::SetLastError ( const std::string &  rMethod  )  const [protected, inherited]

Definition at line 103 of file SpoofBase.cpp.

00104 {
00105     try
00106     {
00107 #ifdef WIN32
00108         //First set the error
00109         m_iLastError=WSAGetLastError();
00110 #else
00111         m_iLastError=errno();
00112 #endif
00113 
00114         //Check if there is an error
00115         if (m_iLastError)
00116             ReportError(rMethod,
00117                         m_iLastError);
00118     }
00119     ERROR_HANDLER("SetLastError")
00120 }

void CErrorHandler::SetLocalLog ( CErrorLog pLog  )  [inherited]

Definition at line 441 of file ErrorHandler.cpp.

00442 {
00443     m_pLocalLog=pLog;
00444 }

void CErrorHandler::SetLog ( CErrorLog pLog  )  [static, inherited]

Definition at line 305 of file ErrorHandler.cpp.

00306 {
00307     //Save the new log
00308     m_pLog=pLog;
00309 }

BOOL CTCPSocket::SetNagle ( BOOL  bNagle  )  [inherited]

Definition at line 808 of file TCPSocket.cpp.

00809 {
00810     try
00811     {
00812         //Quit if not ok
00813         if (!CheckSocketValid())
00814             return FALSE;
00815 
00816         //Invert the flag (convert to true bool)
00817         if (bNagle)
00818             bNagle=FALSE;
00819         else
00820             bNagle=TRUE;
00821 
00822         //Try to set the option
00823         if (setsockopt(GetHandle(),
00824                        IPPROTO_TCP,
00825                        TCP_NODELAY,
00826                        (const char*)&bNagle,
00827                        sizeof(bNagle))==GetErrorCode())
00828         {
00829             //Report it
00830             ReportError("SetNagle","Failed to set nagle");
00831 
00832             //Set it
00833             SetLastError("SetNagle");
00834         
00835             //Exit
00836             return FALSE;
00837         }
00838 
00839         //Done
00840         return TRUE;
00841     }
00842     ERROR_HANDLER_RETURN("SetNagle",FALSE)
00843 }

void CErrorHandler::SetName ( const std::string &  rName  )  const [protected, inherited]

Definition at line 116 of file ErrorHandler.cpp.

00117 {
00118     //Save the class name
00119     m_sClassName=rName;
00120 }

void CSpoofSocket::SetOptions ( BOOL  bOptions  )  [inherited]

Definition at line 1068 of file SpoofSocket.cpp.

01069 {
01070     try
01071     {
01072         //Do we want options, normaly not
01073         m_bOptions=bOptions;
01074 
01075         //Do we have older options?
01076         if (m_pIPOptions)
01077         {
01078             delete m_pIPOptions;
01079             m_pIPOptions=NULL;
01080         }
01081 
01082         //Do we need to reallocate the options
01083         if (bOptions)
01084             m_pIPOptions=new CIPOptions;
01085     }
01086     ERROR_HANDLER("SetOptions")
01087 }

void CSpoofSocket::SetProtocol ( unsigned char  iProtocol  )  [protected, inherited]

Definition at line 974 of file SpoofSocket.cpp.

00975 {
00976     m_ucProtocol=ucProtocol;
00977 }

BOOL CSpoofSocket::SetReceiveTimeout ( unsigned long  ulMS  )  [inherited]

Definition at line 1569 of file SpoofSocket.cpp.

01570 {
01571     try
01572     {
01573         //Quit if not ok
01574         if (!CheckSocketValid())
01575             return FALSE;
01576 
01577         //Set it
01578         if(setsockopt(GetHandle(),
01579                       SOL_SOCKET,
01580                       SO_RCVTIMEO,
01581                       (char*)&ulMS,
01582                       sizeof(ulMS))==GetErrorCode())
01583         {
01584             //Check for options error
01585             SetLastError("SetReceiveTimeout");
01586 
01587             //Exit
01588             return FALSE;
01589         }
01590         else
01591             return TRUE;
01592     }
01593     ERROR_HANDLER_RETURN("SetReceiveTimeout",FALSE)
01594 }

void CSpoofSocket::SetSourceAddress ( const std::string &  rSourceAddress  )  [virtual, inherited]

Definition at line 984 of file SpoofSocket.cpp.

00985 {
00986     try
00987     {
00988         //Set the source address, in case we want to spoof it
00989         if (rSourceAddress.empty())
00990             m_ulSourceAddress=0;
00991         else
00992             m_ulSourceAddress=inet_addr(rSourceAddress.c_str());
00993     }
00994     ERROR_HANDLER("SetSourceAddress")
00995 }

void CSpoofSocket::SetSourceAddress ( IP  aSourceAddress  )  [virtual, inherited]

Definition at line 979 of file SpoofSocket.cpp.

00980 {
00981     m_ulSourceAddress=aSourceAddress;
00982 }

BOOL CAsyncSocket::SetSystemTimeout ( int  iMS  )  [protected, inherited]

Definition at line 1092 of file AsyncSocket.cpp.

01093 {
01094     try
01095     {
01096         //Do we have a timeout
01097         if (m_aTimerID.iTimerID)
01098         {
01099             //Report it
01100             ReportError("SetSystemTimeout","Please kill previous timer!");
01101 
01102             //Exit
01103             return FALSE;
01104         }
01105 
01106         //Create the timer
01107         m_aTimerID=GetThreadManager()->RegisterTimeout(iMS,
01108                                                        SystemTimerProc,
01109                                                        this,
01110                                                        TRUE,
01111                                                        GetWindowHandle(),
01112                                                        &m_aTimerID);
01113 
01114         //Do we have it
01115         if (!m_aTimerID.iTimerID)
01116         {
01117             //Report it
01118             ReportError("SetSystemTimeout","Failed creating the timer!");
01119 
01120             //Exit
01121             return FALSE;
01122         }
01123         else
01124             return TRUE;
01125     }
01126     ERROR_HANDLER_RETURN("SetSystemTimeout",FALSE)
01127 }

void CTCPSocket::SetTCPOptions ( BOOL  bOptions  )  [inherited]

Definition at line 405 of file TCPSocket.cpp.

00406 {
00407     try
00408     {
00409         //Do we want options, normaly not
00410         m_bOptions=bOptions;
00411 
00412         //Do we need to delete old options
00413         if (m_pTCPOptions)
00414         {
00415             delete m_pTCPOptions;
00416             m_pTCPOptions=NULL;
00417         }
00418 
00419         if (bOptions)
00420             m_pTCPOptions=new CTCPOptions;
00421     }
00422     ERROR_HANDLER("SetTCPOptions")
00423 }

BOOL CAsyncSocket::SetTimeout ( int  iMs  )  [inherited]

Definition at line 322 of file AsyncSocket.cpp.

00323 {
00324     try
00325     {
00326         //Get the window handle
00327         HWND hWindowHandle;
00328         hWindowHandle=GetWindowHandle();
00329 
00330         if (!hWindowHandle)
00331             return FALSE;
00332 
00333         //Set the timer
00334         m_bTimeout=SetTimer(hWindowHandle,
00335                             GetAsyncHandle(),
00336                             iMs,
00337                             NULL);
00338 
00339         return m_bTimeout;
00340     }
00341     ERROR_HANDLER_RETURN("SetTimeout",FALSE)
00342 }

void CSpoofSocket::SetTTL ( unsigned char  ucTTL  )  [inherited]

Definition at line 1047 of file SpoofSocket.cpp.

01048 {
01049     try
01050     {
01051         //Quit if not ok
01052         if (!CheckSocketValid())
01053             return;
01054 
01055         if (m_bRaw)
01056             //Set the ttl
01057             m_ucTTL=ucTTL;
01058         else if(setsockopt(GetHandle(),
01059                            IPPROTO_IP,
01060                            IP_TTL,
01061                            (const char*)&ucTTL,
01062                            sizeof(ucTTL)))
01063             SetLastError("SetTTL");
01064     }
01065     ERROR_HANDLER("SetTTL")
01066 }

void CWhoisSocket::SetWhoisTimeout ( DWORD  dwMS  ) 

Definition at line 809 of file WhoisSocket.cpp.

00810 {
00811     try
00812     {
00813         //Set it
00814         m_dwTimeout=dwMS;
00815 
00816         //Set it on the receive
00817         SetReceiveTimeout(dwMS);
00818     }
00819     ERROR_HANDLER("SetWhoisTimeout")
00820 }

void CAsyncSocket::Shutdown (  )  [static, inherited]

Definition at line 371 of file AsyncSocket.cpp.

00372 {
00373     try
00374     {
00375         //Only if initialized
00376         if (!m_bInitialized)
00377             return;
00378 
00379         if (!m_pCSection)
00380         {
00381             //Report it
00382             ReportStaticError(CAsyncSocket_Class,"Shutdown","Critical section not initialized");
00383 
00384             //Exit
00385             return;
00386         }
00387 
00388         //Enter the CS
00389         CCriticalAutoRelease aRelease(m_pCSection);
00390 
00391         //Indicate we're shutting down
00392         m_bShuttingDown=TRUE;
00393 
00394         //Our vector of sockets
00395         typedef std::vector<CAsyncSocket*> SocketVector;
00396         SocketVector aVector;
00397 
00398         //Clear the map
00399         SocketMap::iterator aIterator;
00400         aIterator=m_aSocketMap.begin();
00401 
00402         //While not end of the map
00403         while (aIterator!=m_aSocketMap.end())
00404         {
00405             //Add the socket
00406             aVector.push_back(aIterator->second);
00407 
00408             //Next data
00409             ++aIterator;
00410         }
00411 
00412         //Exit the CS
00413         aRelease.Exit();
00414 
00415         //Iterate the vector
00416         while (!aVector.empty())
00417         {
00418             //Get the socket
00419             CAsyncSocket* pSocket;
00420             pSocket=aVector.back();
00421 
00422             //Remove the socket
00423             aVector.pop_back();
00424 
00425             //Try to delete it
00426             try
00427             {
00428                 delete pSocket;
00429             }
00430             ERROR_HANDLER_STATIC(CAsyncSocket_Class,"Shutdown - Deletion")
00431         }
00432 
00433         //Wait for clean up
00434         Sleep(1000);
00435 
00436         //Delete the thread manager
00437         if (m_pThreadManager)
00438         {
00439             delete m_pThreadManager;
00440             m_pThreadManager=NULL;
00441         }
00442 
00443         //Remove the handlers
00444         RemoveHandlers();
00445 
00446         //Delete the CS
00447         delete m_pCSection;
00448         m_pCSection=NULL;
00449     }
00450     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"Shutdown")
00451 }

BOOL CSpoofSocket::Shutdown ( SocketShutdown  eHow  )  [inherited]

Definition at line 1355 of file SpoofSocket.cpp.

01356 {
01357     if (!CheckSocketValid())
01358         return FALSE;
01359 
01360     try
01361     {
01362         int iHow;
01363 
01364         //Convert the how to a real flag
01365         if (eHow==ssReceive)
01366             iHow=SD_RECEIVE;
01367         else if (eHow==ssSend)
01368             iHow=SD_SEND;
01369         else
01370             iHow=SD_BOTH;
01371 
01372         //Do it
01373         if (shutdown(GetHandle(),iHow))
01374         {
01375             //Report it
01376             SetLastError("Shutdown");
01377 
01378             //Exit
01379             return FALSE;
01380         }
01381 
01382         //Done
01383         return TRUE;
01384     }
01385     ERROR_HANDLER_RETURN("Shutdown",FALSE)
01386 }

BOOL CSpoofBase::ShutdownSockets (  )  [static, inherited]

Definition at line 363 of file SpoofBase.cpp.

00364 {
00365     //Only if initialized
00366     if (!m_bInitialized)
00367         return TRUE;
00368 
00369     try
00370     {
00371         //Do we have a thread?
00372         if (m_pThread)
00373         {
00374             //Delete it
00375             delete m_pThread;
00376             m_pThread=NULL;
00377         }
00378 
00379         //Delete the CS
00380         delete m_pCSection;
00381         m_pCSection=NULL;
00382 
00383         //Notify shutdown class
00384         if (m_pShutdownClass)
00385         {
00386             m_pShutdownClass->NotifyShutdown();
00387             delete m_pShutdownClass;
00388         }
00389 
00390         if (WSACleanup()==GetErrorCode())
00391             return FALSE;
00392 
00393         //Not initialized anymore
00394         m_bInitialized=FALSE;
00395 
00396         //Done
00397         return TRUE;
00398     }
00399     ERROR_HANDLER_STATIC_RETURN(CSpoofBase_Class,"ShutdownSockets",FALSE)
00400 }

void CAsyncSocket::SimpleMessageMap ( LPMapProc  pProc,
BOOL  bStopWhenTRUE,
DWORD  dwSleep 
) [static, inherited]

Definition at line 1002 of file AsyncSocket.cpp.

01005 {
01006     try
01007     {
01008         //Check if we have the proc
01009         if (!pProc)
01010         {
01011             //Report it
01012             ReportStaticError(CAsyncSocket_Class,"SimpleMessageMap","Recieved null proc!");
01013 
01014             //Exit
01015             return;
01016         }
01017 
01018         //If there is no message map, then receive won't work
01019         MSG msg;
01020 
01021         //Set the message map to zeros
01022         memset(&msg,
01023                0,
01024                sizeof(msg));
01025 
01026         //Stop flag
01027         BOOL bStop;
01028         bStop=FALSE;
01029 
01030         //Start the loop
01031         while (!bStop &&
01032                (*pProc)()!=bStopWhenTRUE)
01033         {
01034             while (!(bStop=(*pProc)()==bStopWhenTRUE) &&
01035                    PeekMessage(&msg, 
01036                                NULL, 
01037                                0, 
01038                                0, 
01039                                PM_REMOVE))
01040             {
01041                 TranslateMessage(&msg);
01042                 DispatchMessage(&msg); 
01043             }
01044 
01045             //Do we need to sleep?
01046             if (!bStop)
01047                 //No messages
01048                 Sleep(dwSleep);
01049         }
01050     }
01051     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"SimpleMessageMap")
01052 }

void CAsyncSocket::SimpleMessageMap ( DWORD  dwRunTimeMS  )  [static, inherited]

Definition at line 966 of file AsyncSocket.cpp.

00967 {
00968     try
00969     {
00970         //If there is no message map, then receive won't work
00971         MSG msg;
00972 
00973         //Set the message map to zeros
00974         memset(&msg,
00975                0,
00976                sizeof(msg));
00977 
00978         //Start loop
00979         DWORD dwLoopStart;
00980         dwLoopStart=GetTickCount();
00981 
00982         //Until a key was hit
00983         while (GetTickCount()-dwLoopStart<dwRunTimeMS)
00984         {
00985             while (PeekMessage(&msg, 
00986                                NULL, 
00987                                0, 
00988                                0, 
00989                                PM_REMOVE))
00990             {
00991                 TranslateMessage(&msg);
00992                 DispatchMessage(&msg); 
00993             }
00994 
00995             //Sleep so wont be hanged
00996             Sleep(1);
00997         }
00998     }
00999     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"SimpleMessageMap")
01000 }

void CAsyncSocket::SimpleMessageMap (  )  [static, inherited]

Definition at line 941 of file AsyncSocket.cpp.

00942 {
00943     try
00944     {
00945         //If there is no message map, then receive won't work
00946         MSG msg;
00947 
00948         //Set the message map to zeros
00949         memset(&msg,
00950                0,
00951                sizeof(msg));
00952 
00953         while (GetMessage(&msg,
00954                           NULL,
00955                           0,
00956                           0))
00957         {
00958             //Dispatch the message
00959             TranslateMessage(&msg);
00960             DispatchMessage(&msg);
00961         }
00962     }
00963     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"SimpleMessageMap")
00964 }

char CAsyncSocket::SimpleMessageMapKey ( DWORD  dwSleep  )  [static, inherited]

Definition at line 1054 of file AsyncSocket.cpp.

01055 {
01056     try
01057     {
01058         //If there is no message map, then receive won't work
01059         MSG msg;
01060 
01061         //Set the message map to zeros
01062         memset(&msg,
01063                0,
01064                sizeof(msg));
01065 
01066         //Until a key was hit
01067         while (!kbhit())
01068         {
01069             while (!kbhit() &&
01070                    PeekMessage(&msg, 
01071                                NULL, 
01072                                0, 
01073                                0, 
01074                                PM_REMOVE))
01075             {
01076                 TranslateMessage(&msg);
01077                 DispatchMessage(&msg); 
01078             }
01079 
01080             //Do we need to sleep
01081             if (!kbhit())
01082                 //Sleep so wont be hanged
01083                 Sleep(dwSleep);
01084         }
01085         
01086         //Return the char
01087         return getch();
01088     }
01089     ERROR_HANDLER_STATIC_RETURN(CAsyncSocket_Class,"SimpleMessageMapKey",0)
01090 }

BOOL CSpoofSocket::Sniff ( BOOL  bSniff  )  [virtual, inherited]

Reimplemented in CSniffSocket.

Definition at line 1318 of file SpoofSocket.cpp.

01319 {
01320     //Start sniffing
01321     if (!ValidSocket())
01322         return FALSE;
01323 
01324     try
01325     {
01326 #ifdef WIN32
01327         unsigned long ulBytes;
01328         if (WSAIoctl(GetHandle(),SIO_RCVALL,&bSniff,sizeof(bSniff),NULL,0,&ulBytes,NULL,NULL))
01329         {
01330             //Error
01331             SetLastError("Sniff");
01332 
01333             //Exit
01334             return FALSE;
01335         }
01336 
01337         //Set sniffer status
01338         m_bSniffing=bSniff;
01339 
01340         //Done
01341         return TRUE;
01342 #else
01343         return FALSE;
01344 #endif
01345     }
01346     ERROR_HANDLER_RETURN("Sniff",FALSE)
01347 }

void CAsyncSocket::SocketClosing (  )  [protected, inherited]

Definition at line 679 of file AsyncSocket.cpp.

00680 {
00681     try
00682     {
00683         //Are we valid
00684         if (m_bClosing ||
00685             GetAsyncHandle()==INVALID_SOCKET)
00686             return;
00687 
00688         //Indicate we are closing
00689         m_bClosing=TRUE;
00690 
00691         //Do we have a regular timer
00692         if (m_bTimeout)
00693             KillTimer();
00694 
00695         //Do we have a system timer ?
00696         if (m_aTimerID.iTimerID)
00697             KillSystemTimer();
00698 
00699         //Kill all the messages
00700         m_iMsg=0;
00701         m_lEvent=0;
00702 
00703         //Set it
00704         if (WSAAsyncSelect(GetAsyncHandle(),
00705                            GetWindowHandle(),
00706                            0,
00707                            0))
00708             SetLastError("SocketClosing");
00709     }
00710     ERROR_HANDLER("SocketClosing")
00711 }

void CAsyncSocket::SocketCreated (  )  [protected, virtual, inherited]

Definition at line 1272 of file AsyncSocket.cpp.

01273 {
01274     try
01275     {
01276         //No timer
01277         memset(&m_aTimerID,
01278                0,
01279                sizeof(m_aTimerID));
01280 
01281         //No delete timer
01282         memset(&m_aDeleteTimerID,
01283                0,
01284                sizeof(m_aDeleteTimerID));
01285 
01286         //Set values for new socket
01287         m_iSocketID=0;
01288         m_bBlocking=FALSE;
01289         m_bFreeze=FALSE;
01290         m_lEvent=0;
01291         m_hLocalWindowHandle=0;
01292         m_bList=FALSE;
01293         m_bClosing=FALSE;
01294     }
01295     ERROR_HANDLER("SocketCreated")
01296 }

unsigned long CSpoofBase::StringToLong ( const std::string &  rAddress  )  [static, inherited]

Definition at line 473 of file SpoofBase.cpp.

00474 {
00475     return inet_addr(rAddress.c_str());
00476 }

BOOL CSpoofSocket::ValidAddress ( const std::string &  rAddress  )  [static, inherited]

Definition at line 1267 of file SpoofSocket.cpp.

01268 {
01269     try
01270     {
01271         return inet_addr(rAddress.c_str())!=INADDR_NONE;
01272     }
01273     ERROR_HANDLER_STATIC_RETURN(CSpoofSocket_LOGNAME,"ValidAddress",FALSE)
01274 }

BOOL CSpoofSocket::ValidSocket (  )  const [protected, inherited]

Definition at line 819 of file SpoofSocket.cpp.

00820 {
00821     return m_aSpoofSocket!=INVALID_SOCKET;
00822 }

void CWhoisSocket::WhoisDone ( BOOL  bError  )  [protected, virtual]

Definition at line 259 of file WhoisSocket.cpp.

00260 {
00261 }

BOOL CWhoisSocket::WhoisIP ( IP  aAddress,
const std::string &  rWhoisServer 
)

Definition at line 795 of file WhoisSocket.cpp.

00797 {
00798     try
00799     {
00800         //IP trace
00801         m_bURL=FALSE;
00802 
00803         //Trace it
00804         return WhoisURL(LongToStdString(aAddress),rWhoisServer);
00805     }
00806     ERROR_HANDLER_RETURN("WhoisIP",FALSE)
00807 }

BOOL CWhoisSocket::WhoisIP ( IP  aAddress  ) 

Definition at line 744 of file WhoisSocket.cpp.

00745 {
00746     try
00747     {
00748         //No server yet
00749         m_aServer=wsNone;
00750 
00751         //Are we async
00752         if (!m_bAsync)
00753         {
00754             //Try to get the data
00755             for (int iCounter=wsRipe;
00756                  iCounter>wsNone;
00757                  --iCounter)
00758             {
00759                 //Try to get the data
00760                 if (!WhoisIP(aAddress,m_aIPWhois[iCounter]))
00761                 {
00762                     //Error
00763                     ReportError("WhoisIP","Failed getting data from server!");
00764 
00765                     //Exit
00766                     return FALSE;
00767                 }
00768 
00769                 //Try to analyze it
00770                 if (m_sWhoisData.find(m_aWhoisNotFound[iCounter])==std::string::npos)
00771                 {
00772                     //We have it
00773                     m_aServer=(WhoisServer)iCounter;
00774 
00775                     //Exit
00776                     return TRUE;
00777                 }
00778             }
00779 
00780             //Didn't found it
00781             return FALSE;
00782         }
00783         else
00784         {
00785             //Set the current server
00786             m_aProgress=wsRipe;
00787 
00788             //Connect
00789             return WhoisIP(aAddress,m_aIPWhois[m_aProgress]);
00790         }
00791     }
00792     ERROR_HANDLER_RETURN("WhoisIP",FALSE)
00793 }

BOOL CWhoisSocket::WhoisIP ( const std::string &  rIP  ) 

Definition at line 734 of file WhoisSocket.cpp.

00735 {
00736     try
00737     {
00738         //Convert it and send
00739         return WhoisIP(StringToLong(rIP));
00740     }
00741     ERROR_HANDLER_RETURN("WhoisIP",FALSE)
00742 }

BOOL CWhoisSocket::WhoisURL ( const std::string &  rURL,
const std::string &  rWhoisServer 
)

Definition at line 523 of file WhoisSocket.cpp.

00525 {
00526     try
00527     {
00528         //Try to resolve the URL
00529         IP aAddress;
00530         aAddress=ResolveDNS(rWhoisServer.c_str());
00531 
00532         //Do we have it
00533         if (!aAddress)
00534         {
00535             //Report it
00536             ReportError("WhoisURL","Failed to resolve whois server!");
00537 
00538             //Exit
00539             return FALSE;
00540         }
00541 
00542         //Set some data
00543         m_bDone=FALSE;
00544         m_bError=FALSE;
00545         m_sWhoisData="";
00546         m_sDataToSend=rURL;
00547         m_sAdditionalWhoisServer="";
00548         m_bAdditionalServer=rWhoisServer=="whois.crsnic.net";
00549 
00550         //Try to connect
00551         if (!Connect(aAddress,43))
00552         {
00553             //Report it
00554             ReportError("WhoisURL","Failed to connect!");
00555 
00556             //Not done
00557             m_bDone=TRUE;
00558 
00559             //We have errors
00560             m_bError=TRUE;
00561 
00562             //Exit
00563             return FALSE;
00564         }
00565 
00566         //Are we async ?
00567         if (!m_bAsync)
00568             if (!SendURL(rURL))
00569             {
00570                 //Report it
00571                 ReportError("WhoisURL","Failed to send data!");
00572 
00573                 //Not done
00574                 m_bDone=TRUE;
00575 
00576                 //We have errors
00577                 m_bError=TRUE;
00578 
00579                 //Exit
00580                 return FALSE;
00581             }
00582             else
00583                 return ReceiveWhois();
00584         else
00585             return TRUE;
00586     }
00587     ERROR_HANDLER_RETURN("WhoisURL",FALSE)
00588 }

BOOL CWhoisSocket::WhoisURL ( const std::string &  rURL  ) 

Definition at line 497 of file WhoisSocket.cpp.

00498 {
00499     try
00500     {
00501         //Get the host to connect to
00502         std::string sHost;
00503         sHost=GetWhoisServer(rURL);
00504 
00505         //URL trace
00506         m_bURL=TRUE;
00507 
00508         //Is it valid
00509         if (!sHost.length())
00510         {
00511             //Report it
00512             ReportError("WhoisURL","Failed to find host to connect to!");
00513 
00514             //Exit
00515             return FALSE;
00516         }
00517         else
00518             return WhoisURL(rURL,sHost);
00519     }
00520     ERROR_HANDLER_RETURN("WhoisURL",FALSE)
00521 }

void CErrorHandler::WriteMessage ( const std::string &  rMethod,
const std::string &  rMessage,
DWORD  dwAdditionalData,
LogPriority  aPriority = lpMessage 
) [protected, inherited]

Definition at line 355 of file ErrorHandler.cpp.

00359 {
00360     if (!GetLog())
00361         return;
00362 
00363     try
00364     {
00365         //Convert the number
00366         char aTmp[11];
00367         ltoa(dwAdditionalData,aTmp,10);
00368 
00369         //Create the new message
00370         std::string sNewMessage(rMessage);
00371         sNewMessage+="Additional data: ";
00372         sNewMessage+=aTmp;
00373 
00374         //Delegate the call
00375         GetLog()->WriteMessage(m_sClassName,
00376                                rMethod,
00377                                sNewMessage,
00378                                aPriority);
00379     }
00380     ERROR_UNKNOWN("WriteMessage")
00381 }

void CErrorHandler::WriteMessage ( const std::string &  rMethod,
const std::string &  rMessage,
LogPriority  aPriority = lpMessage 
) [protected, inherited]

Definition at line 337 of file ErrorHandler.cpp.

00340 {
00341     if (!GetLog())
00342         return;
00343 
00344     try
00345     {
00346         //Delegate the call
00347         GetLog()->WriteMessage(m_sClassName,
00348                                rMethod,
00349                                rMessage,
00350                                aPriority);
00351     }
00352     ERROR_UNKNOWN("WriteMessage")
00353 }

void CErrorHandler::WriteStaticMessage ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMessage,
DWORD  dwAdditionalData,
LogPriority  aPriority = lpMessage 
) [static, protected, inherited]

Definition at line 403 of file ErrorHandler.cpp.

00408 {
00409     if (!m_pLog)
00410         return;
00411 
00412     try
00413     {
00414         //Convert the number
00415         char aTmp[11];
00416         ltoa(dwAdditionalData,aTmp,10);
00417 
00418         //Create the new message
00419         std::string sNewMessage(rMessage);
00420         sNewMessage+="Additional data: ";
00421         sNewMessage+=aTmp;
00422 
00423         //Delegate the call
00424         m_pLog->WriteMessage(rClass,
00425                              rMethod,
00426                              sNewMessage,
00427                              aPriority);
00428     }
00429     ERROR_UNKNOWN("WriteStaticMessage")
00430 }

void CErrorHandler::WriteStaticMessage ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMessage,
LogPriority  aPriority = lpMessage 
) [static, protected, inherited]

Definition at line 383 of file ErrorHandler.cpp.

00388 {
00389     if (!m_pLog)
00390         return;
00391 
00392     try
00393     {
00394         //Delegate the call
00395         m_pLog->WriteMessage(rClass,
00396                              rMethod,
00397                              rMessage,
00398                              aPriority);
00399     }
00400     ERROR_UNKNOWN("WriteStaticMessage")
00401 }


Friends And Related Function Documentation

friend class CIPCrafter [friend, inherited]

Definition at line 452 of file SpoofSocket.h.


Member Data Documentation

CGenericCriticalSection * CSpoofBase::m_pCSection = NULL [static, protected, inherited]

Definition at line 124 of file SpoofBase.h.


The documentation for this class was generated from the following files: