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


CICMPCrafter Class Reference

#include <ICMPCrafter.h>

Inheritance diagram for CICMPCrafter:
Collaboration diagram for CICMPCrafter:

List of all members.


Public Types

enum  _SocketShutdown { ssReceive, ssSend, ssBoth }
typedef enum
CSpoofSocket::_SocketShutdown 
SocketShutdown

Public Member Functions

char * GetInformation (BOOL bReply, unsigned short usIdentifier, unsigned short usSequence, unsigned short &usTotalSize) const
char * GetTimestamp (BOOL bReply, unsigned short usIdentifier, unsigned short usSequence, unsigned long ulOriginateTimestamp, unsigned long ulReceiveTimestamp, unsigned long ulTransmitTimestamp, unsigned short &usTotalSize) const
char * GetEcho (BOOL bReply, unsigned short usIdentifier, unsigned short usSequence, unsigned long ulData, unsigned short &usTotalSize) const
char * GetRedirect (unsigned char cType, IP aGatewayAddress, unsigned short &usTotalSize) const
char * GetQuench (unsigned short &usTotalSize) const
char * GetParameter (unsigned char cError, unsigned short &usTotalSize) const
char * GetTime (unsigned char cType, unsigned short &usTotalSize) const
char * GetUnreachable (unsigned char cType, unsigned short &usTotalSize) const
void SetDestinationAddress (IP aDestinationAddress)
void SetDestinationAddress (const std::string &rDestinationAddress)
void SetICMPUseDefaultChecksum (BOOL bDefault)
void SetICMPChecksum (unsigned short usChecksum)
 CICMPCrafter ()
virtual ~CICMPCrafter ()
char * GetCraftedPacket (const CSpoofSocket *pSocket, unsigned long ulDestinationAddress, const char *pBuffer, unsigned short usBufferSize, unsigned short &usTotalSize) const
void SetUseDefaultChecksum (BOOL bDefault)
void SetChecksum (unsigned short usChecksum)
void SetDefault ()
void SetTypeOfService (unsigned char ucTypeOfService)
void SetHeaderLength (unsigned char ucHeaderLength)
void SetIdentification (unsigned short usIdentification)
void SetFragmentationFlags (unsigned short usFragmentationFlags)
void SetSendBuffer (const char *pBuffer, unsigned short usSendSize)
const LPIpHeader GetLastICMPIPHeader () const
const LPICMPHeader GetLastICMPICMPHeader () const
unsigned long GetLastDataSize ()
const char * GetLastData () const
const LPIpHeader GetLastIPHeader () const
const LPICMPHeader GetLastICMPHeader () const
BOOL SendInformation (const std::string &rDestinationAddress, BOOL bReply, unsigned short usIdentifier, unsigned short usSequence)
BOOL SendInformation (IP aDestinationAddress, BOOL bReply, unsigned short usIdentifier, unsigned short usSequence)
BOOL SendTimestamp (const std::string &rDestinationAddress, BOOL bReply, unsigned short usIdentifier, unsigned short usSequence, unsigned long ulOriginateTimestamp, unsigned long ulReceiveTimestamp, unsigned long ulTransmitTimestamp)
BOOL SendTimestamp (IP aDestinationAddress, BOOL bReply, unsigned short usIdentifier, unsigned short usSequence, unsigned long ulOriginateTimestamp, unsigned long ulReceiveTimestamp, unsigned long ulTransmitTimestamp)
BOOL SendEcho (const std::string &rDestinationAddress, BOOL bReply, unsigned short usIdentifier, unsigned short usSequence, unsigned long ulData)
BOOL SendEcho (IP aDestinationAddress, BOOL bReply, unsigned short usIdentifier, unsigned short usSequence, unsigned long ulData)
BOOL SendRedirect (const std::string &rDestinationAddress, unsigned char ucType, const std::string &rGatewayAddress)
BOOL SendRedirect (IP aDestinationAddress, unsigned char ucType, IP aGatewayAddress)
BOOL SendQuench (const std::string &rDestinationAddress)
BOOL SendQuench (IP aDestinationAddress)
BOOL SendParameter (const std::string &rDestinationAddress, unsigned char ucError)
BOOL SendParameter (IP aDestinationAddress, unsigned char ucError)
BOOL SendTime (const std::string &rDestinationAddress, unsigned char ucType)
BOOL SendTime (IP aDestinationAddress, unsigned char ucType)
BOOL SendUnreachable (const std::string &rDestinationAddress, unsigned char ucType)
BOOL SendUnreachable (IP aDestinationAddress, unsigned char ucType)
virtual BOOL Create ()
BOOL Create (int iProtocol)
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)
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)
virtual int Receive (char *pBuffer, unsigned long ulBufferLength)
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 Close ()
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)

Static Public Member Functions

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)

Protected Member Functions

virtual void FinalICMPHeader (LPICMPHeader lpHead) const
virtual LPIpHeader ConstructIPHeader (unsigned char ucProtocol, unsigned short usFragmentationFlags, unsigned char ucTTL, unsigned short usIdentification, unsigned char ucHeaderLength) const
virtual void FinalIPHeader (LPIpHeader lpHead) const
LPIpHeader ConstructCraftedIPHeader (unsigned char ucProtocol, unsigned short usFragmentationFlags, unsigned char ucTTL, unsigned short usIdentification, unsigned char ucHeaderLength) const
const char * GetSendBuffer () const
int GetBufferSize () const
BOOL SendICMP (LPICMPHeader lpHead, const std::string &rDestinationAddress)
BOOL SendICMP (LPICMPHeader lpHead, IP aDestinationAddress)
virtual LPICMPHeader ConstructICMP () const
virtual BOOL ProccessICMP (const char *pBuffer)
void SetConnectedTo (const sockaddr_in &rAddress)
IP GetSourceAddress () const
unsigned char GetTTL () const
unsigned char GetProtocol () const
BOOL HasOptions () 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 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

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)

Protected Attributes

unsigned short m_usFragmentationFlags
unsigned short m_usIdentification
unsigned char m_ucHeaderLength
unsigned char m_ucTypeOfService
BOOL m_DefaultChecksum

Static Protected Attributes

static CGenericCriticalSectionm_pCSection = NULL

Friends

class CIPCrafter

Detailed Description

Definition at line 48 of file ICMPCrafter.h.


Member Typedef Documentation


Member Enumeration Documentation

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;


Constructor & Destructor Documentation

CICMPCrafter::CICMPCrafter (  ) 

Definition at line 54 of file ICMPCrafter.cpp.

00054                            : CIPCrafter(),
00055                                CICMPSocket(TRUE)
00056 {
00057     try
00058     {
00059         //Set our name
00060         SetName(CICMPCrafter_Class);
00061 
00062         //Set the protocol
00063         SetProtocol(IPPROTO_ICMP);
00064 
00065         //Data initialization
00066         m_bDefaultChecksum=FALSE;
00067         m_usChecksum=0;
00068     }
00069     ERROR_HANDLER("CICMPCrafter")
00070 }   

CICMPCrafter::~CICMPCrafter (  )  [virtual]

Definition at line 72 of file ICMPCrafter.cpp.

00073 {
00074 }


Member Function Documentation

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 }

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 CSpoofSocket::Close (  )  [virtual, inherited]

Reimplemented in CICMPSocketAsync, CTCPSocket, CTCPSocketAsync, and CUDPSocketAsync.

Definition at line 945 of file SpoofSocket.cpp.

00946 {
00947     try
00948     {
00949         //Close the socket
00950         //Quit if not ok
00951         if (!ValidSocket())
00952             return FALSE;
00953 
00954         //Close it
00955         if (closesocket(GetHandle())==GetErrorCode())
00956         {
00957             //Error in closing ?
00958             SetLastError("Close");
00959 
00960             //Exit
00961             return FALSE;
00962         }
00963 
00964         //Set the socket to invalid
00965         m_aSpoofSocket=INVALID_SOCKET;
00966 
00967         //Done
00968         return TRUE;
00969     }
00970     ERROR_HANDLER_RETURN("Close",FALSE)
00971 }

LPIpHeader CIPCrafter::ConstructCraftedIPHeader ( unsigned char  ucProtocol,
unsigned short  usFragmentationFlags,
unsigned char  ucTTL,
unsigned short  usIdentification,
unsigned char  ucHeaderLength 
) const [protected, inherited]

Definition at line 115 of file IPCrafter.cpp.

00120 {
00121     try
00122     {
00123         //Get the original header
00124         LPIpHeader lpHead;
00125 
00126         //Check what header length to pass
00127         unsigned char ucLength;
00128 
00129         if (m_ucHeaderLength==IPCRAFTER_DEFAULT_HEADER_SIZE)
00130             ucLength=ucHeaderLength;
00131         else
00132             ucLength=m_ucHeaderLength;
00133 
00134         //Get the header
00135         lpHead=CSpoofSocket::ConstructStaticIPHeader(ucProtocol,
00136                                                      m_usFragmentationFlags,
00137                                                      ucTTL,
00138                                                      m_usIdentification,
00139                                                      ucLength);
00140 
00141         //Check we have it
00142         if (!lpHead)
00143             return NULL;
00144 
00145         //Set the type of service
00146         //Precedence
00147         lpHead->ucTypeOfService=m_ucTypeOfService;
00148 
00149         //Done
00150         return lpHead;
00151     }
00152     ERROR_HANDLER_RETURN("ConstructCraftedIPHeader",NULL)
00153 }

LPICMPHeader CICMPSocket::ConstructICMP (  )  const [protected, virtual, inherited]

Definition at line 121 of file ICMPSocket.cpp.

00122 {
00123     try
00124     {
00125         //Constructs a basic ICMP header
00126         LPICMPHeader lpHead;
00127         lpHead=new ICMPHeader;
00128 
00129         //Set all as zeros
00130         memset(lpHead,
00131                0,
00132                ICMPHeaderLength);
00133 
00134         //Set the timestamp
00135         lpHead->ulICMP_Originate_Timestamp=GetTickCount();
00136 
00137         //Return it
00138         return lpHead;
00139     }
00140     ERROR_HANDLER_RETURN("ConstructICMP",FALSE)
00141 }

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

Reimplemented from CSpoofSocket.

Definition at line 76 of file ICMPCrafter.cpp.

00081 {
00082     return ConstructCraftedIPHeader(ucProtocol,
00083                                     usFragmentationFlags,
00084                                     ucTTL,
00085                                     usIdentification,
00086                                     ucHeaderLength);
00087 }

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 }

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 CICMPSocket::Create (  )  [virtual, inherited]

Reimplemented in CICMPSocketAsync.

Definition at line 85 of file ICMPSocket.cpp.

00086 {
00087     try
00088     {
00089         //Set our protocol
00090         SetProtocol(IPPROTO_ICMP);
00091 
00092         //Create the socket
00093         return CSpoofSocket::Create(IPPROTO_ICMP);
00094     }
00095     ERROR_HANDLER_RETURN("Create",FALSE)
00096 }

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 CICMPCrafter::FinalICMPHeader ( LPICMPHeader  lpHead  )  const [protected, virtual]

Reimplemented from CICMPSocket.

Definition at line 110 of file ICMPCrafter.cpp.

00111 {
00112     if (!m_bDefaultChecksum)
00113         lpHead->usICMPChecksum=htons(m_usChecksum);
00114 }

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

Reimplemented from CSpoofSocket.

Definition at line 89 of file ICMPCrafter.cpp.

00090 {
00091     try
00092     {
00093         //Check if we need to modify the header
00094         if (!m_DefaultChecksum)
00095             lpHead->usChecksum=htons(m_usChecksum);
00096     }
00097     ERROR_HANDLER("FinalIPHeader")
00098 }

int CICMPSocket::GetBufferSize (  )  const [protected, inherited]

Definition at line 815 of file ICMPSocket.cpp.

00816 {
00817     return m_usBufferSendSize;
00818 }

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 }

char * CIPCrafter::GetCraftedPacket ( const CSpoofSocket pSocket,
unsigned long  ulDestinationAddress,
const char *  pBuffer,
unsigned short  usBufferSize,
unsigned short &  usTotalSize 
) const [inherited]

Definition at line 155 of file IPCrafter.cpp.

00160 {
00161     try
00162     {
00163         //Check if the length is too big
00164         if (IpHeaderLength+(long)usBufferSize>65535)
00165         {
00166             //Report it
00167             ReportError("GetCraftedPacket","Packet can't be greater then 65k!");
00168 
00169             //Exit
00170             return NULL;
00171         }
00172 
00173         //Header length
00174         unsigned char ucHeaderLength=IpHeaderLength;
00175 
00176         if (pSocket->HasOptions())
00177             ucHeaderLength+=pSocket->GetOptions()->GetBufferLength();
00178         
00179         //First construct the packet
00180         LPIpHeader lpHead=pSocket->ConstructIPHeader(pSocket->GetProtocol(),
00181                                                      IpFragFlag_DONT_FRAG,
00182                                                      pSocket->GetTTL(),
00183                                                      (unsigned short)GetCurrentProcessId(),
00184                                                      ucHeaderLength);
00185 
00186         //Set the address
00187         pSocket->SetIPHeaderAddress(lpHead,
00188                                     pSocket->GetSourceAddress(),
00189                                     ulDestinationAddress);
00190 
00191         //Now add some more options
00192         unsigned short usTotalLength;
00193         usTotalLength=ucHeaderLength+usBufferSize;
00194 
00195         //Set the header
00196         lpHead->usTotalLength=htons(usTotalLength);
00197 
00198         //Need to construct a new packet
00199         char* pNewBuf;
00200         pNewBuf=new char[usTotalLength];
00201 
00202         //Copy two buffers
00203         memcpy(pNewBuf,
00204                lpHead,
00205                IpHeaderLength);
00206 
00207         //Do we need to copy options ?
00208         if (pSocket->HasOptions())
00209             memcpy(pNewBuf+IpHeaderLength,
00210                    pSocket->GetOptions()->GetBuffer(),
00211                    pSocket->GetOptions()->GetBufferLength());
00212 
00213         //Only if not null
00214         if (pBuffer)
00215             memcpy(pNewBuf+ucHeaderLength,
00216                    pBuffer,
00217                    usBufferSize);
00218         
00219         //Calculate the checksum
00220         lpHead->usChecksum=pSocket->CalculateChecksum((unsigned short*)pNewBuf,
00221                                                       ucHeaderLength);
00222 
00223         //Alert everyone this is the final header
00224         pSocket->FinalIPHeader(lpHead);
00225 
00226         //Recopy the ip
00227         memcpy(pNewBuf,
00228                lpHead,
00229                IpHeaderLength);
00230             
00231         //Set the total size
00232         usTotalSize=usTotalLength;
00233 
00234         //Return to the user
00235         return pNewBuf;
00236     }
00237     ERROR_HANDLER_RETURN("GetCraftedPacket",NULL)
00238 }

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 }

char * CICMPCrafter::GetEcho ( BOOL  bReply,
unsigned short  usIdentifier,
unsigned short  usSequence,
unsigned long  ulData,
unsigned short &  usTotalSize 
) const

Definition at line 220 of file ICMPCrafter.cpp.

00225 {
00226     try
00227     {
00228         //Create the header
00229         LPICMPHeader lpHead;
00230         lpHead=ConstructICMP();
00231         
00232         if (!lpHead)
00233         {
00234             ReportError("SendEcho","Failed to construct ICMP header!");
00235             return FALSE;
00236         }
00237 
00238         //Protect it
00239         std::auto_ptr<ICMPHeader> pProtection(lpHead);
00240 
00241         //Check if echo or reply
00242         if (bReply)
00243             lpHead->ucICMPType=ICMP_Echo_Reply;
00244         else
00245             lpHead->ucICMPType=ICMP_Echo;
00246 
00247         lpHead->ucICMPCode=0;
00248         lpHead->sICMP.sUS.us1=htons(usIdentifier);
00249         lpHead->sICMP.sUS.us2=htons(usSequence);
00250         lpHead->ulICMP_Originate_Timestamp=htonl(ulData);
00251 
00252         //And the checksum
00253         lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,ICMPHeaderLength);
00254 
00255         //Create the packet
00256         return CreateFinal(lpHead,
00257                            usTotalSize);
00258     }
00259     ERROR_HANDLER_RETURN("GetEcho",NULL)
00260 }

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 }

char * CICMPCrafter::GetInformation ( BOOL  bReply,
unsigned short  usIdentifier,
unsigned short  usSequence,
unsigned short &  usTotalSize 
) const

Definition at line 308 of file ICMPCrafter.cpp.

00312 {
00313     try
00314     {
00315         //Create the header
00316         LPICMPHeader lpHead;
00317         lpHead=ConstructICMP();
00318 
00319         if (!lpHead)
00320         {
00321             ReportError("GetInformation","Failed to construct ICMP header!");
00322             return FALSE;
00323         }
00324 
00325         //Protect it
00326         std::auto_ptr<ICMPHeader> pProtection(lpHead);
00327 
00328         //Check if echo or reply
00329         if (bReply)
00330             lpHead->ucICMPType=ICMP_Information_Reply;
00331         else
00332             lpHead->ucICMPType=ICMP_Information;
00333 
00334         lpHead->ucICMPCode=0;
00335         lpHead->sICMP.sUS.us1=htons(usIdentifier);
00336         lpHead->sICMP.sUS.us2=htons(usSequence);
00337         
00338         //And the checksum
00339         //Using only first 8 bytes
00340         lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,ICMP_Information_SIZE);
00341 
00342         //Create the packet
00343         return CreateFinal(lpHead,
00344                            usTotalSize);
00345     }
00346     ERROR_HANDLER_RETURN("GetInformation",NULL)
00347 }

const char * CICMPSocket::GetLastData (  )  const [inherited]

Definition at line 820 of file ICMPSocket.cpp.

00821 {
00822     return m_pICMPReceiveData;
00823 }

unsigned long CICMPSocket::GetLastDataSize (  )  [inherited]

Definition at line 699 of file ICMPSocket.cpp.

00700 {
00701     return m_usDataSize;
00702 }

int CSpoofBase::GetLastError (  )  const [inherited]

Definition at line 138 of file SpoofBase.cpp.

00139 {
00140     return m_iLastError;
00141 }

const LPICMPHeader CICMPSocket::GetLastICMPHeader (  )  const [inherited]

Definition at line 688 of file ICMPSocket.cpp.

00689 {
00690     //Return the last header proccessed
00691     return m_pICMPHeader;
00692 }

const LPICMPHeader CICMPSocket::GetLastICMPICMPHeader (  )  const [inherited]

Definition at line 735 of file ICMPSocket.cpp.

00736 {
00737     return m_pICMPICMPHeader;
00738 }

const LPIpHeader CICMPSocket::GetLastICMPIPHeader (  )  const [inherited]

Definition at line 729 of file ICMPSocket.cpp.

00730 {
00731     //Get the IP header received via the icmp
00732     return m_pICMPIPHeader;
00733 }

const LPIpHeader CICMPSocket::GetLastIPHeader (  )  const [inherited]

Definition at line 694 of file ICMPSocket.cpp.

00695 {
00696     return m_pIPHeader;
00697 }

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 }

char * CICMPCrafter::GetParameter ( unsigned char  cError,
unsigned short &  usTotalSize 
) const

Definition at line 142 of file ICMPCrafter.cpp.

00144 {
00145     try
00146     {
00147         //Consturct the packet
00148         LPICMPHeader lpHead;
00149         lpHead=ConstructICMP();
00150 
00151         if (!lpHead)
00152         {
00153             ReportError("GetParameter","Failed to construct ICMP header!");
00154             return FALSE;
00155         }
00156 
00157         //Protect it
00158         std::auto_ptr<ICMPHeader> pProtection(lpHead);
00159 
00160         //Set the values
00161         lpHead->ucICMPType=ICMP_Parameter;
00162         lpHead->ucICMPCode=ICMP_Parameter_ERROR;
00163         lpHead->sICMP.sUC.uc1=cError;
00164 
00165         //And the checksum
00166         lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,ICMPHeaderLength);
00167 
00168         //Create the packet
00169         return CreateFinal(lpHead,
00170                            usTotalSize);
00171     }
00172     ERROR_HANDLER_RETURN("GetParameter",NULL)
00173 }

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 }

char * CICMPCrafter::GetQuench ( unsigned short &  usTotalSize  )  const

Definition at line 175 of file ICMPCrafter.cpp.

00176 {
00177     try
00178     {
00179         return CreateFinal(ICMP_Quench,
00180                            0,
00181                            usTotalSize);
00182     }
00183     ERROR_HANDLER_RETURN("GetQuench",NULL)
00184 }

char * CICMPCrafter::GetRedirect ( unsigned char  cType,
IP  aGatewayAddress,
unsigned short &  usTotalSize 
) const

Definition at line 186 of file ICMPCrafter.cpp.

00189 {
00190     try
00191     {
00192         //Construct the header
00193         LPICMPHeader lpHead;
00194         lpHead=ConstructICMP();
00195 
00196         if (!lpHead)
00197         {
00198             ReportError("GetRedirect","Failed to construct ICMP header!");
00199             return FALSE;
00200         }
00201 
00202         //Protect it
00203         std::auto_ptr<ICMPHeader> pProtection(lpHead);
00204 
00205         //Set the values
00206         lpHead->ucICMPType=ICMP_Redirect;
00207         lpHead->ucICMPCode=cType;
00208         lpHead->sICMP.sUL=aGatewayAddress;
00209 
00210         //And the checksum
00211         lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,ICMPHeaderLength);
00212 
00213         //Create the packet
00214         return CreateFinal(lpHead,
00215                            usTotalSize);
00216     }
00217     ERROR_HANDLER_RETURN("GetRedirect",NULL)
00218 }

const char * CICMPSocket::GetSendBuffer (  )  const [protected, inherited]

Definition at line 810 of file ICMPSocket.cpp.

00811 {
00812     return m_pSendBuffer;
00813 }

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 }

char * CICMPCrafter::GetTime ( unsigned char  cType,
unsigned short &  usTotalSize 
) const

Definition at line 130 of file ICMPCrafter.cpp.

00132 {
00133     try
00134     {
00135         return CreateFinal(ICMP_Time,
00136                            cType,
00137                            usTotalSize);
00138     }
00139     ERROR_HANDLER_RETURN("GetTime",NULL)
00140 }

char * CICMPCrafter::GetTimestamp ( BOOL  bReply,
unsigned short  usIdentifier,
unsigned short  usSequence,
unsigned long  ulOriginateTimestamp,
unsigned long  ulReceiveTimestamp,
unsigned long  ulTransmitTimestamp,
unsigned short &  usTotalSize 
) const

Definition at line 262 of file ICMPCrafter.cpp.

00269 {
00270     try
00271     {
00272         //Create the header
00273         LPICMPHeader lpHead;
00274         lpHead=ConstructICMP();
00275 
00276         if (!lpHead)
00277         {
00278             ReportError("GetTimestamp","Failed to construct ICMP header!");
00279             return FALSE;
00280         }
00281 
00282         //Protect it
00283         std::auto_ptr<ICMPHeader> pProtection(lpHead);
00284 
00285         //Check if echo or reply
00286         if (bReply)
00287             lpHead->ucICMPType=ICMP_Timestamp_Reply;
00288         else
00289             lpHead->ucICMPType=ICMP_Timestamp;
00290 
00291         lpHead->ucICMPCode=0;
00292         lpHead->sICMP.sUS.us1=htons(usIdentifier);
00293         lpHead->sICMP.sUS.us2=htons(usSequence);
00294         lpHead->ulICMP_Originate_Timestamp=htonl(ulOriginateTimestamp);
00295         lpHead->ulICMP_Receive_Timestamp=htonl(ulReceiveTimestamp);
00296         lpHead->ulICMP_Transmit_Timestamp=htonl(ulTransmitTimestamp);
00297 
00298         //And the checksum
00299         lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,ICMPHeaderLength);
00300 
00301         //Create the packet
00302         return CreateFinal(lpHead,
00303                            usTotalSize);
00304     }
00305     ERROR_HANDLER_RETURN("GetTimestamp",NULL)
00306 }

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

Reimplemented in CPingSocket.

Definition at line 1549 of file SpoofSocket.cpp.

01550 {
01551     return m_ucTTL;
01552 }

char * CICMPCrafter::GetUnreachable ( unsigned char  cType,
unsigned short &  usTotalSize 
) const

Definition at line 349 of file ICMPCrafter.cpp.

00351 {
00352     try
00353     {
00354         return CreateFinal(ICMP_Unreachable,
00355                            cType,
00356                            usTotalSize);
00357     }
00358     ERROR_HANDLER_RETURN("GetUnreachable",FALSE)
00359 }

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

Definition at line 1559 of file SpoofSocket.cpp.

01560 {
01561     return m_bOptions;
01562 }

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 }

BOOL CSpoofSocket::IsCreated (  )  const [inherited]

Definition at line 1517 of file SpoofSocket.cpp.

01518 {
01519     return ValidSocket();
01520 }

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

Definition at line 468 of file SpoofBase.cpp.

00469 {
00470     return m_bInitialized;
00471 }

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 }

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 }

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 CICMPSocket::ProccessICMP ( const char *  pBuffer  )  [protected, virtual, inherited]

Definition at line 533 of file ICMPSocket.cpp.

00534 {
00535     try
00536     {
00537         //Here we proccess the input we received
00538         //Do we have previous data?
00539         if (m_pICMPReceiveData)
00540         {
00541             //Delete it
00542             delete [] m_pICMPReceiveData;
00543             m_pICMPReceiveData=NULL;
00544         }
00545 
00546         //No user data
00547         m_usDataSize=0;
00548 
00549         //Initialize members
00550         if (!m_pIPHeader)
00551             m_pIPHeader=new IpHeader;
00552 
00553         if (!m_pICMPHeader)
00554             m_pICMPHeader=new ICMPHeader;
00555 
00556         //Create an IP header
00557         LPIpHeader lpHead;
00558         lpHead=m_pIPHeader;
00559 
00560         //Copy to buffer
00561         memcpy(lpHead,
00562                pBuffer,
00563                IpHeaderLength);
00564 
00565         //Let's check for options
00566         unsigned char ucHeaderSize;
00567         ucHeaderSize=(lpHead->ucHeaderLength_Version & 15) << 2;
00568 
00569         //Now check for total packet size
00570         unsigned short ucPacketSize;
00571         ucPacketSize=htons(lpHead->usTotalLength);
00572 
00573         //Copy data to icmp
00574         memset(m_pICMPHeader,
00575                0,
00576                ICMPHeaderLength);
00577 
00578         //How much to copy ?
00579         unsigned short ucCopy;
00580         ucCopy=ucPacketSize-ucHeaderSize;
00581         
00582         //Save the datasize
00583         m_usDataSize=ucCopy;
00584 
00585         if (ucCopy>ICMPHeaderLength)
00586             ucCopy=ICMPHeaderLength;
00587 
00588         //Copy the ICMP header
00589         memcpy(m_pICMPHeader,
00590                pBuffer+ucHeaderSize,
00591                ucCopy);
00592 
00593         //Now save the original IP
00594         if (!m_pICMPIPHeader)
00595             m_pICMPIPHeader=new IpHeader;
00596 
00597         //Copy the data
00598         memcpy(m_pICMPIPHeader,
00599                pBuffer+ucHeaderSize+ICMP_DATA_SIZE,
00600                IpHeaderLength);
00601 
00602         //Get this header size
00603         unsigned char ucNewHeaderSize;
00604         ucNewHeaderSize=(m_pICMPIPHeader->ucHeaderLength_Version & 15) << 2;
00605 
00606         //Do we have ICMP buffer
00607         if (!(m_pICMPHeader->ucICMPType!=ICMP_Echo &&
00608               m_pICMPHeader->ucICMPType!=ICMP_Echo_Reply &&
00609               m_pICMPHeader->ucICMPType!=ICMP_Timestamp &&
00610               m_pICMPHeader->ucICMPType!=ICMP_Timestamp_Reply &&
00611               m_pICMPHeader->ucICMPType!=ICMP_Information &&
00612               m_pICMPHeader->ucICMPType!=ICMP_Information_Reply &&
00613               m_pICMPHeader->ucICMPType!=ICMP_Time))
00614         {
00615             
00616             //Copy rest of data
00617             if (!m_pICMPICMPHeader)
00618                 m_pICMPICMPHeader=new ICMPHeader;
00619 
00620             memcpy(m_pICMPICMPHeader,
00621                    pBuffer+ucHeaderSize+ICMP_DATA_SIZE+ucNewHeaderSize,
00622                    ICMP_DATA_SIZE);
00623 
00624             //Reverse it
00625             ReverseHeader(m_pICMPICMPHeader);
00626 
00627             //Do we have data to copy
00628             unsigned short usRemainingSize;
00629             usRemainingSize=ucHeaderSize+
00630                             ICMP_DATA_SIZE+
00631                             ucNewHeaderSize+
00632                             ICMP_DATA_SIZE;
00633 
00634             //Anything left?
00635             if (usRemainingSize<ucPacketSize)
00636             {
00637                 //Set the size
00638                 m_usDataSize=ucPacketSize-usRemainingSize;
00639 
00640                 //Allocate some data
00641                 m_pICMPReceiveData=new char[m_usDataSize];
00642 
00643                 //Copy it
00644                 memcpy(m_pICMPReceiveData,
00645                        pBuffer+usRemainingSize,
00646                        m_usDataSize);
00647             }
00648         }
00649         else
00650         {
00651             //Reset the ICMP
00652             if (m_pICMPICMPHeader)
00653                 memset(m_pICMPICMPHeader,
00654                        0,
00655                        ICMPHeaderLength);
00656 
00657             //Do we have data to copy
00658             unsigned short usRemainingSize;
00659             usRemainingSize=ucHeaderSize+
00660                             ICMP_DATA_SIZE+
00661                             ucNewHeaderSize;
00662 
00663             //Anything left?
00664             if (usRemainingSize<ucPacketSize)
00665             {
00666                 //Set the size
00667                 m_usDataSize=ucPacketSize-usRemainingSize;
00668 
00669                 //Allocate some data
00670                 m_pICMPReceiveData=new char[m_usDataSize];
00671 
00672                 //Copy it
00673                 memcpy(m_pICMPReceiveData,
00674                        pBuffer+usRemainingSize,
00675                        m_usDataSize);
00676             }
00677         }
00678 
00679         //Now I need to reverse the header
00680         ReverseHeader(m_pICMPHeader);
00681 
00682         //Done
00683         return TRUE;
00684     }
00685     ERROR_HANDLER_RETURN("ProccessICMP",FALSE)
00686 }

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

Reimplemented in CTCPSocketAsync, and CUDPSocket.

Definition at line 1210 of file SpoofSocket.cpp.

01212 {
01213     try
01214     {
01215         if (!ValidSocket() ||
01216             !pBuffer ||
01217             !ulBufferLength)
01218             return GetErrorCode();
01219 
01220         //Receive data
01221         int iResult;
01222 
01223         //Receive
01224         if (m_ucProtocol!=IPPROTO_TCP && 
01225             !m_bSniffing)
01226         {
01227             //Get the remote address
01228             sockaddr saConnected;
01229 
01230             int iTmp;
01231             iTmp=sizeof(saConnected);
01232 
01233             //Accept it
01234             iResult=recvfrom(GetHandle(),
01235                              pBuffer,
01236                              ulBufferLength,
01237                              NULL,
01238                              &saConnected,
01239                              &iTmp);
01240 
01241             //If OK set it
01242             if (iResult!=GetErrorCode())
01243                 //Take the connected to data
01244                 memcpy(&m_aConnectedTo,
01245                        &saConnected,
01246                        sizeof(saConnected));
01247         }
01248         else
01249             //Do a regular receive
01250             iResult=recv(GetHandle(),
01251                          pBuffer,
01252                          ulBufferLength,
01253                          NULL);
01254 
01255         //Check if error
01256         if (iResult==GetErrorCode() &&
01257             GetSystemLastError()!=WSAEWOULDBLOCK)
01258             //Error
01259             SetLastError("Receive");
01260 
01261         //Number of bytes received
01262         return iResult;
01263     }
01264     ERROR_HANDLER_RETURN("Receive",GetErrorCode())
01265 }

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 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 }

BOOL CICMPSocket::SendEcho ( IP  aDestinationAddress,
BOOL  bReply,
unsigned short  usIdentifier,
unsigned short  usSequence,
unsigned long  ulData 
) [inherited]

Definition at line 347 of file ICMPSocket.cpp.

00352 {
00353     try
00354     {
00355         //Create the header
00356         LPICMPHeader lpHead;
00357         lpHead=ConstructICMP();
00358         
00359         if (!lpHead)
00360         {
00361             //Report it
00362             ReportError("SendEcho","Failed to construct ICMP header!");
00363 
00364             //Exit
00365             return FALSE;
00366         }
00367 
00368         //Protect it
00369         std::auto_ptr<ICMPHeader> pProtection(lpHead);
00370 
00371         //Check if echo or reply
00372         if (bReply)
00373             lpHead->ucICMPType=ICMP_Echo_Reply;
00374         else
00375             lpHead->ucICMPType=ICMP_Echo;
00376 
00377         lpHead->ucICMPCode=0;
00378         lpHead->sICMP.sUS.us1=htons(usIdentifier);
00379         lpHead->sICMP.sUS.us2=htons(usSequence);
00380         lpHead->ulICMP_Originate_Timestamp=htonl(ulData);
00381 
00382         //And the checksum
00383         lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,ICMPHeaderLength);
00384 
00385         //Send it
00386         BOOL bSend;
00387         bSend=CSpoofSocket::Send(aDestinationAddress,
00388                                  (char*)lpHead,
00389                                  ICMPHeaderLength);
00390         
00391         //Exit
00392         return bSend;
00393     }
00394     ERROR_HANDLER_RETURN("SendEcho",FALSE)
00395 }

BOOL CICMPSocket::SendEcho ( const std::string &  rDestinationAddress,
BOOL  bReply,
unsigned short  usIdentifier,
unsigned short  usSequence,
unsigned long  ulData 
) [inherited]

Definition at line 330 of file ICMPSocket.cpp.

00335 {
00336     try
00337     {
00338         return SendEcho(StringToLong(rDestinationAddress),
00339                         bReply,
00340                         usIdentifier,
00341                         usSequence,
00342                         ulData);
00343     }
00344     ERROR_HANDLER_RETURN("SendEcho",FALSE)
00345 }

BOOL CICMPSocket::SendICMP ( LPICMPHeader  lpHead,
IP  aDestinationAddress 
) [protected, inherited]

Definition at line 751 of file ICMPSocket.cpp.

00753 {
00754     try
00755     {
00756         //Our buffer to send
00757         char* pSendBuffer;
00758         
00759         //Size of the buffer to send
00760         int iSendSize;
00761         iSendSize=ICMPHeaderLength;
00762 
00763         //Do we have an external buffer ?
00764         if (!m_pSendBuffer)         
00765             pSendBuffer=(char*)lpHead;
00766         else
00767         {
00768             iSendSize+=m_usBufferSendSize;
00769             pSendBuffer=new char[m_usBufferSendSize];
00770 
00771             //Copy the data
00772             memcpy(pSendBuffer,
00773                    (char*)lpHead,
00774                    ICMPHeaderLength);
00775             memcpy(pSendBuffer+ICMPHeaderLength,
00776                    m_pSendBuffer,
00777                    m_usBufferSendSize);
00778         }
00779 
00780         //Send to modify before send
00781         FinalICMPHeader((LPICMPHeader)pSendBuffer);
00782 
00783         //Send it
00784         int iResult;
00785         iResult=CSpoofSocket::Send(aDestinationAddress,
00786                                    pSendBuffer,
00787                                    iSendSize);
00788 
00789         if (m_pSendBuffer)
00790             delete [] pSendBuffer;
00791 
00792         //Done
00793         return iResult>0;
00794     }
00795     ERROR_HANDLER_RETURN("SendICMP",FALSE)
00796 }

BOOL CICMPSocket::SendICMP ( LPICMPHeader  lpHead,
const std::string &  rDestinationAddress 
) [protected, inherited]

Definition at line 740 of file ICMPSocket.cpp.

00742 {
00743     try
00744     {
00745         return SendICMP(lpHead,
00746                         StringToLong(rDestinationAddress));
00747     }
00748     ERROR_HANDLER_RETURN("SendICMP",FALSE)
00749 }

BOOL CICMPSocket::SendInformation ( IP  aDestinationAddress,
BOOL  bReply,
unsigned short  usIdentifier,
unsigned short  usSequence 
) [inherited]

Definition at line 486 of file ICMPSocket.cpp.

00490 {
00491     try
00492     {
00493         //Create the header
00494         LPICMPHeader lpHead;
00495         lpHead=ConstructICMP();
00496 
00497         if (!lpHead)
00498         {
00499             //Report it
00500             ReportError("SendInformation","Failed to construct ICMP header!");
00501 
00502             //Exit
00503             return FALSE;
00504         }
00505 
00506         //Check if echo or reply
00507         if (bReply)
00508             lpHead->ucICMPType=ICMP_Information_Reply;
00509         else
00510             lpHead->ucICMPType=ICMP_Information;
00511 
00512         lpHead->ucICMPCode=0;
00513         lpHead->sICMP.sUS.us1=htons(usIdentifier);
00514         lpHead->sICMP.sUS.us2=htons(usSequence);
00515         
00516         //And the checksum
00517         //Using only first 8 bytes
00518         lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,
00519                                                  ICMP_Information_SIZE);
00520 
00521         //Send it
00522         BOOL bSend;
00523         bSend=SendICMP(lpHead,
00524                        aDestinationAddress);
00525 
00526         //Exit
00527         return bSend;
00528     }
00529     ERROR_HANDLER_RETURN("SendInformation",FALSE)
00530 }

BOOL CICMPSocket::SendInformation ( const std::string &  rDestinationAddress,
BOOL  bReply,
unsigned short  usIdentifier,
unsigned short  usSequence 
) [inherited]

Definition at line 471 of file ICMPSocket.cpp.

00475 {
00476     try
00477     {
00478         return SendInformation(StringToLong(rDestinationAddress),
00479                                bReply,
00480                                usIdentifier,
00481                                usSequence);
00482     }
00483     ERROR_HANDLER_RETURN("SendInformation",FALSE)
00484 }

BOOL CICMPSocket::SendParameter ( IP  aDestinationAddress,
unsigned char  ucError 
) [inherited]

Definition at line 217 of file ICMPSocket.cpp.

00219 {
00220     try
00221     {
00222         //Construct the header
00223         LPICMPHeader lpHead;
00224         lpHead=ConstructICMP();
00225 
00226         if (!lpHead)
00227         {
00228             //Report it
00229             ReportError("SendParameter","Failed to construct ICMP header!");
00230 
00231             //Exit
00232             return FALSE;
00233         }
00234 
00235         //Protect it
00236         std::auto_ptr<ICMPHeader> pProtection(lpHead);
00237 
00238         //Set the values
00239         lpHead->ucICMPType=ICMP_Parameter;
00240         lpHead->ucICMPCode=ICMP_Parameter_ERROR;
00241         lpHead->sICMP.sUC.uc1=ucError;
00242 
00243         //And the checksum
00244         lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,ICMPHeaderLength);
00245 
00246         //Send it
00247         BOOL bSend;
00248         bSend=SendICMP(lpHead,
00249                        aDestinationAddress);
00250 
00251         //Done
00252         return bSend;
00253     }
00254     ERROR_HANDLER_RETURN("SendParameter",FALSE)
00255 }

BOOL CICMPSocket::SendParameter ( const std::string &  rDestinationAddress,
unsigned char  ucError 
) [inherited]

Definition at line 206 of file ICMPSocket.cpp.

00208 {
00209     try
00210     {
00211         return SendParameter(StringToLong(rDestinationAddress),
00212                              ucError);
00213     }
00214     ERROR_HANDLER_RETURN("SendParameter",FALSE)
00215 }

BOOL CICMPSocket::SendQuench ( IP  aDestinationAddress  )  [inherited]

Definition at line 266 of file ICMPSocket.cpp.

00267 {
00268     try
00269     {
00270         return Send(aDestinationAddress,
00271                     ICMP_Quench,
00272                     0);
00273     }
00274     ERROR_HANDLER_RETURN("SendQuench",FALSE)
00275 }

BOOL CICMPSocket::SendQuench ( const std::string &  rDestinationAddress  )  [inherited]

Definition at line 257 of file ICMPSocket.cpp.

00258 {
00259     try
00260     {
00261         return SendQuench(StringToLong(rDestinationAddress));
00262     }
00263     ERROR_HANDLER_RETURN("SendQuench",FALSE)
00264 }

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 CICMPSocket::SendRedirect ( IP  aDestinationAddress,
unsigned char  ucType,
IP  aGatewayAddress 
) [inherited]

Definition at line 290 of file ICMPSocket.cpp.

00293 {
00294     try
00295     {
00296         LPICMPHeader lpHead;
00297         lpHead=ConstructICMP();
00298 
00299         if (!lpHead)
00300         {
00301             //Report it
00302             ReportError("SendRedirect","Failed to construct ICMP header!");
00303 
00304             //Exit
00305             return FALSE;
00306         }
00307 
00308         //Protect it
00309         std::auto_ptr<ICMPHeader> pProtection(lpHead);
00310 
00311         //Set the values
00312         lpHead->ucICMPType=ICMP_Redirect;
00313         lpHead->ucICMPCode=ucType;
00314         lpHead->sICMP.sUL=aGatewayAddress;
00315 
00316         //And the checksum
00317         lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,ICMPHeaderLength);
00318 
00319         //Send it
00320         BOOL bSend;
00321         bSend=SendICMP(lpHead,
00322                        aDestinationAddress);
00323 
00324         //Exit
00325         return bSend;
00326     }
00327     ERROR_HANDLER_RETURN("SendRedirect",FALSE)
00328 }

BOOL CICMPSocket::SendRedirect ( const std::string &  rDestinationAddress,
unsigned char  ucType,
const std::string &  rGatewayAddress 
) [inherited]

Definition at line 277 of file ICMPSocket.cpp.

00280 {
00281     try
00282     {
00283         return SendRedirect(StringToLong(rDestinationAddress),
00284                             ucType,
00285                             StringToLong(rGatewayAddress));
00286     }
00287     ERROR_HANDLER_RETURN("SendRedirect",FALSE)
00288 }

BOOL CICMPSocket::SendTime ( IP  aDestinationAddress,
unsigned char  ucType 
) [inherited]

Definition at line 154 of file ICMPSocket.cpp.

00156 {
00157     try
00158     {
00159         return Send(aDestinationAddress,
00160                     ICMP_Time,
00161                     ucType);
00162     }
00163     ERROR_HANDLER_RETURN("SendTime",FALSE)
00164 }

BOOL CICMPSocket::SendTime ( const std::string &  rDestinationAddress,
unsigned char  ucType 
) [inherited]

Definition at line 143 of file ICMPSocket.cpp.

00145 {
00146     try
00147     {
00148         return SendTime(StringToLong(rDestinationAddress),
00149                         ucType);
00150     }
00151     ERROR_HANDLER_RETURN("SendTime",FALSE)
00152 }

BOOL CICMPSocket::SendTimestamp ( IP  aDestinationAddress,
BOOL  bReply,
unsigned short  usIdentifier,
unsigned short  usSequence,
unsigned long  ulOriginateTimestamp,
unsigned long  ulReceiveTimestamp,
unsigned long  ulTransmitTimestamp 
) [inherited]

Definition at line 418 of file ICMPSocket.cpp.

00425 {
00426     try
00427     {
00428         //Create the header
00429         LPICMPHeader lpHead;
00430         lpHead=ConstructICMP();
00431 
00432         if (!lpHead)
00433         {
00434             //Report it
00435             ReportError("SendTimestamp","Failed to construct ICMP header!");
00436 
00437             //Exit
00438             return FALSE;
00439         }
00440 
00441         //Protect it
00442         std::auto_ptr<ICMPHeader> pProtection(lpHead);
00443 
00444         //Check if echo or reply
00445         if (bReply)
00446             lpHead->ucICMPType=ICMP_Timestamp_Reply;
00447         else
00448             lpHead->ucICMPType=ICMP_Timestamp;
00449 
00450         lpHead->ucICMPCode=0;
00451         lpHead->sICMP.sUS.us1=htons(usIdentifier);
00452         lpHead->sICMP.sUS.us2=htons(usSequence);
00453         lpHead->ulICMP_Originate_Timestamp=htonl(ulOriginateTimestamp);
00454         lpHead->ulICMP_Receive_Timestamp=htonl(ulReceiveTimestamp);
00455         lpHead->ulICMP_Transmit_Timestamp=htonl(ulTransmitTimestamp);
00456 
00457         //And the checksum
00458         lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,ICMPHeaderLength);
00459 
00460         //Send it
00461         BOOL bSend;
00462         bSend=SendICMP(lpHead,
00463                        aDestinationAddress);
00464 
00465         //Exit
00466         return bSend;
00467     }
00468     ERROR_HANDLER_RETURN("SendTimestamp",FALSE)
00469 }

BOOL CICMPSocket::SendTimestamp ( const std::string &  rDestinationAddress,
BOOL  bReply,
unsigned short  usIdentifier,
unsigned short  usSequence,
unsigned long  ulOriginateTimestamp,
unsigned long  ulReceiveTimestamp,
unsigned long  ulTransmitTimestamp 
) [inherited]

Definition at line 397 of file ICMPSocket.cpp.

00404 {
00405     try
00406     {
00407         return SendTimestamp(StringToLong(rDestinationAddress),
00408                              bReply,
00409                              usIdentifier,
00410                              usSequence,
00411                              ulOriginateTimestamp, 
00412                              ulReceiveTimestamp, 
00413                              ulTransmitTimestamp);
00414     }
00415     ERROR_HANDLER_RETURN("SendTimestamp",FALSE)
00416 }

BOOL CICMPSocket::SendUnreachable ( IP  aDestinationAddress,
unsigned char  ucType 
) [inherited]

Definition at line 109 of file ICMPSocket.cpp.

00111 {
00112     try
00113     {
00114         return Send(aDestinationAddress,
00115                     ICMP_Unreachable,
00116                     ucType);
00117     }
00118     ERROR_HANDLER_RETURN("SendUnreachable",FALSE)
00119 }

BOOL CICMPSocket::SendUnreachable ( const std::string &  rDestinationAddress,
unsigned char  ucType 
) [inherited]

Definition at line 98 of file ICMPSocket.cpp.

00100 {
00101     try
00102     {
00103         return SendUnreachable(StringToLong(rDestinationAddress),
00104                                ucType);
00105     }
00106     ERROR_HANDLER_RETURN("SendUnreachable",FALSE)
00107 }

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 CIPCrafter::SetChecksum ( unsigned short  usChecksum  )  [inherited]

Definition at line 105 of file IPCrafter.cpp.

00106 {
00107     m_usChecksum=usChecksum;
00108 }

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

Definition at line 1606 of file SpoofSocket.cpp.

01607 {
01608     m_aConnectedTo=rAddress;
01609 }

void CIPCrafter::SetDefault (  )  [inherited]

Definition at line 90 of file IPCrafter.cpp.

00091 {
00092     try
00093     {
00094         m_usFragmentationFlags=IpFragFlag_DONT_FRAG;
00095         m_usIdentification=(unsigned short)GetCurrentProcessId();
00096         m_ucHeaderLength=IPCRAFTER_DEFAULT_HEADER_SIZE; //Default size
00097         m_ucTypeOfService=IpService_ROUTINE;
00098 
00099         //Default checksum used
00100         m_DefaultChecksum=TRUE;
00101     }
00102     ERROR_HANDLER("SetDefault")
00103 }

void CICMPCrafter::SetDestinationAddress ( const std::string &  rDestinationAddress  ) 

Definition at line 121 of file ICMPCrafter.cpp.

00122 {
00123     //Check if null
00124     if (rDestinationAddress.empty())
00125         m_aDestinationAddress=0;
00126     else
00127         m_aDestinationAddress=StringToLong(rDestinationAddress);
00128 }

void CICMPCrafter::SetDestinationAddress ( IP  aDestinationAddress  ) 

Definition at line 116 of file ICMPCrafter.cpp.

00117 {
00118     m_aDestinationAddress=aDestinationAddress;
00119 }

void CIPCrafter::SetFragmentationFlags ( unsigned short  usFragmentationFlags  )  [inherited]

Definition at line 70 of file IPCrafter.cpp.

00071 {
00072     m_usFragmentationFlags=usFragmentationFlags;
00073 }

void CIPCrafter::SetHeaderLength ( unsigned char  ucHeaderLength  )  [inherited]

Definition at line 80 of file IPCrafter.cpp.

00081 {
00082     m_ucHeaderLength=ucHeaderLength;
00083 }

void CICMPCrafter::SetICMPChecksum ( unsigned short  usChecksum  ) 

Definition at line 105 of file ICMPCrafter.cpp.

00106 {
00107     m_usChecksum=usChecksum;
00108 }

void CICMPCrafter::SetICMPUseDefaultChecksum ( BOOL  bDefault  ) 

Definition at line 100 of file ICMPCrafter.cpp.

00101 {
00102     m_bDefaultChecksum=bDefault;
00103 }

void CIPCrafter::SetIdentification ( unsigned short  usIdentification  )  [inherited]

Definition at line 75 of file IPCrafter.cpp.

00076 {
00077     m_usIdentification=usIdentification;
00078 }

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 }

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 CICMPSocket::SetSendBuffer ( const char *  pBuffer,
unsigned short  usSendSize 
) [inherited]

Definition at line 798 of file ICMPSocket.cpp.

00800 {
00801     //Set the buffer
00802     m_pSendBuffer=pBuffer;
00803     m_usBufferSendSize=usSendSize;
00804 }

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 }

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 CIPCrafter::SetTypeOfService ( unsigned char  ucTypeOfService  )  [inherited]

Definition at line 85 of file IPCrafter.cpp.

00086 {
00087     m_ucTypeOfService=ucTypeOfService;
00088 }

void CIPCrafter::SetUseDefaultChecksum ( BOOL  bDefault  )  [inherited]

Definition at line 110 of file IPCrafter.cpp.

00111 {
00112     m_DefaultChecksum=bDefault;
00113 }

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 }

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 }

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 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

BOOL CIPCrafter::m_DefaultChecksum [protected, inherited]

Definition at line 102 of file IPCrafter.h.

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

Definition at line 124 of file SpoofBase.h.

unsigned char CIPCrafter::m_ucHeaderLength [protected, inherited]

Definition at line 97 of file IPCrafter.h.

unsigned char CIPCrafter::m_ucTypeOfService [protected, inherited]

Definition at line 98 of file IPCrafter.h.

unsigned short CIPCrafter::m_usFragmentationFlags [protected, inherited]

Definition at line 95 of file IPCrafter.h.

unsigned short CIPCrafter::m_usIdentification [protected, inherited]

Definition at line 96 of file IPCrafter.h.


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