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


CTCPPortScannerLinear Class Reference

#include <TCPPortScannerLinear.h>

Inheritance diagram for CTCPPortScannerLinear:
Collaboration diagram for CTCPPortScannerLinear:

List of all members.


Public Types

typedef std::set< unsigned short > PortsList
enum  _LogPriority { lpDebug, lpMessage, lpCritical, lpError }
typedef enum
CErrorHandler::_LogPriority 
LogPriority

Public Member Functions

virtual BOOL Scan (const std::string &rDestinationAddress)
virtual BOOL Scan (IP aTarget)
 CTCPPortScannerLinear ()
virtual ~CTCPPortScannerLinear ()
void SetMaxSockets (int iMaxSockets)
int GetMaxSockets () const
void SetConnectionTimeout (int iMS)
int GetConnectionTimeout () const
const char * GetData (unsigned short usPort) const
char * GetDataForModify (unsigned short usPort) const
const PortsListGetPortList () const
BOOL IsDone () const
BOOL IsError () const
void SetReceiveData (int iMaxDataSize, DWORD dwTimeout)
DWORD GetReceiveDataTimeout () const
int GetReceiveDataSize () const
virtual BOOL StopScan ()
void AddPorts (unsigned short usFromPort, unsigned short usToPort)
void SetLocalLog (CErrorLog *pLog)

Static Public Member Functions

static std::string GetCurrentDateTime ()
static std::string ErrorCodeToString (DWORD dwErrorCode)
static void SetLog (CErrorLog *pLog)

Protected Member Functions

virtual void OnPort (unsigned short usPort, BOOL bConnected)
virtual void OnPortData (unsigned short usPort, const char *pData, int iDataSize)
virtual void TCPScanDone (BOOL bError)
virtual void TCPScanDoneLib (BOOL bError)
virtual void PortScanned (unsigned short usPort)
void ScanDone (BOOL bError, BOOL bSpawnThread=TRUE)
BOOL CanScan ()
int AdjustNumberOfSockets (int iIncrement)
unsigned short GetNextPort ()
void SocketDone (unsigned short usPort, BOOL bConnected)
void SocketDone (unsigned short usPort, char *pData, int iDataSize)
void DeletePortsMap ()
virtual CTCPSocketAsyncAllocateSocket (unsigned short usPort) const
virtual void DestroySocket (CTCPSocketAsync *pSocket) const
BOOL NewSocket ()
void SetError (BOOL bError)
void SetDone (BOOL bDone)
void ResetSocketCount ()
void ResetPair ()
void ResetData ()
void SetTarget (IP aTarget)
IP GetTarget () const
BOOL IsFinished () 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)

Detailed Description

Definition at line 47 of file TCPPortScannerLinear.h.


Member Typedef Documentation

typedef std::set<unsigned short> CTCPPortScanner::PortsList [inherited]

Definition at line 59 of file TCPPortScanner.h.


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;


Constructor & Destructor Documentation

CTCPPortScannerLinear::CTCPPortScannerLinear (  ) 

Definition at line 51 of file TCPPortScannerLinear.cpp.

00051                                              : CTCPPortScanner()
00052 {
00053     try
00054     {
00055         //Set our name
00056         SetName(CTCPPortScannerLinear_Class);
00057     }
00058     ERROR_HANDLER("CTCPPortScannerLinear")
00059 }

CTCPPortScannerLinear::~CTCPPortScannerLinear (  )  [virtual]

Definition at line 61 of file TCPPortScannerLinear.cpp.

00062 {
00063 }


Member Function Documentation

void CTCPPortScanner::AddPorts ( unsigned short  usFromPort,
unsigned short  usToPort 
) [inherited]

Definition at line 243 of file TCPPortScanner.cpp.

00245 {
00246     try
00247     {
00248         //Check we can insert them
00249         if (!(usFromPort &&
00250               usToPort &&
00251               usFromPort<=usToPort))
00252             return;
00253 
00254         //Insert them
00255         ScanPair aData;
00256         aData.usFromPort=usFromPort;
00257         aData.usToPort=usToPort;
00258 
00259         //Lock
00260         CCriticalAutoRelease aRelease(m_pCSection,TRUE);
00261 
00262         m_aPortsToScan.push_back(aData);
00263     }
00264     ERROR_HANDLER("AddPorts")
00265 }

int CTCPPortScanner::AdjustNumberOfSockets ( int  iIncrement  )  [protected, inherited]

Definition at line 585 of file TCPPortScanner.cpp.

00586 {
00587     try
00588     {
00589         //Lock the data
00590         CCriticalAutoRelease aRelease(m_pCSection,TRUE);
00591 
00592         //Readjust
00593         m_iActiveSockets+=iIncrement;
00594 
00595         //Return it
00596         return m_iActiveSockets;
00597     }
00598     ERROR_HANDLER_RETURN("AdjustNumberOfSockets",0)
00599 }

CTCPSocketAsync * CTCPPortScanner::AllocateSocket ( unsigned short  usPort  )  const [protected, virtual, inherited]

Reimplemented in CTCPPortScannerStealth, and CUDPScanner.

Definition at line 793 of file TCPPortScanner.cpp.

00794 {
00795     try
00796     {
00797         CTCPScanner* pSocket;
00798         pSocket=new CTCPScanner((CTCPPortScanner*)this,
00799                                 usPort,
00800                                 GetReceiveDataSize(),
00801                                 GetReceiveDataTimeout());
00802 
00803         //Do we have receive data ?
00804         if (!GetReceiveDataSize())
00805             //Disable receive
00806             pSocket->DisableEvents(CAsyncSocket::aeReceive);
00807 
00808         if (!pSocket->Create())
00809         {
00810             //Delete it
00811             delete pSocket;
00812 
00813             //Error
00814             return NULL;
00815         }
00816         else
00817         {
00818             //Set timeout
00819             if (GetConnectionTimeout())
00820                 if (!pSocket->SetConnectionTimeout(GetConnectionTimeout()))
00821                 {   
00822                     //Delete it
00823                     delete pSocket;
00824 
00825                     //Error
00826                     return NULL;
00827                 }
00828 
00829             //Done
00830             return pSocket;
00831         }           
00832     }
00833     ERROR_HANDLER_RETURN("AllocateSocket",NULL)
00834 }

BOOL CTCPPortScanner::CanScan (  )  [protected, inherited]

Definition at line 331 of file TCPPortScanner.cpp.

00332 {
00333     try
00334     {
00335         //Lock the data
00336         CCriticalAutoRelease aRelease(m_pCSection,TRUE);
00337 
00338         //Do we have a pair
00339         if (!m_aCurrentPair.usFromPort ||
00340             !m_aCurrentPair.usToPort ||
00341             m_aCurrentPair.usFromPort>m_aCurrentPair.usToPort)
00342             //Get a pair
00343             if (m_aPortsToScan.begin()==m_aPortsToScan.end())
00344                 return FALSE;
00345             else
00346             {
00347                 //Get the pair and remove it
00348                 m_aCurrentPair=m_aPortsToScan.front();
00349                 m_aPortsToScan.pop_front();
00350             }
00351 
00352         return TRUE;
00353     }
00354     ERROR_HANDLER_RETURN("CanScan",FALSE)
00355 }

void CTCPPortScanner::DeletePortsMap (  )  [protected, inherited]

Definition at line 481 of file TCPPortScanner.cpp.

00482 {
00483     try
00484     {
00485         //Get the iterator
00486         DataMap::iterator aIterator;
00487         aIterator=m_aPortsData.begin();
00488 
00489         //Start
00490         while (aIterator!=m_aPortsData.end())
00491         {
00492             //Save the iterator
00493             DataMap::iterator aBackupIterator;
00494             aBackupIterator=aIterator;
00495 
00496             //Advance it
00497             ++aIterator;
00498 
00499             //Delete the data
00500             delete [] aBackupIterator->second;
00501 
00502             //Remove the data
00503             m_aPortsData.erase(aBackupIterator);
00504         }
00505     }
00506     ERROR_HANDLER("DeletePortsMap")
00507 }

void CTCPPortScanner::DestroySocket ( CTCPSocketAsync pSocket  )  const [protected, virtual, inherited]

Reimplemented in CTCPPortScannerStealth, and CUDPScanner.

Definition at line 836 of file TCPPortScanner.cpp.

00837 {
00838     try
00839     {
00840         delete pSocket;
00841     }
00842     ERROR_HANDLER("DestroySocket")
00843 }

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 }

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 }

int CTCPPortScanner::GetConnectionTimeout (  )  const [inherited]

Definition at line 732 of file TCPPortScanner.cpp.

00733 {
00734     return m_iConnectionTimeout;
00735 }

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 }

const char * CTCPPortScanner::GetData ( unsigned short  usPort  )  const [inherited]

Definition at line 693 of file TCPPortScanner.cpp.

00694 {
00695     try
00696     {
00697         //Try to look for the data
00698         DataMap::const_iterator aIterator;
00699         aIterator=m_aPortsData.find(usPort);
00700 
00701         //Do we have it
00702         if (aIterator!=m_aPortsData.end())
00703             return aIterator->second;
00704         else
00705             return NULL;
00706     }
00707     ERROR_HANDLER_RETURN("GetData",NULL)
00708 }

char * CTCPPortScanner::GetDataForModify ( unsigned short  usPort  )  const [inherited]

Definition at line 710 of file TCPPortScanner.cpp.

00711 {
00712     try
00713     {
00714         //Try to look for the data
00715         DataMap::const_iterator aIterator;
00716         aIterator=m_aPortsData.find(usPort);
00717 
00718         //Do we have it
00719         if (aIterator!=m_aPortsData.end())
00720             return aIterator->second;
00721         else
00722             return NULL;
00723     }
00724     ERROR_HANDLER_RETURN("GetDataForModify",NULL)
00725 }

int CTCPPortScanner::GetMaxSockets (  )  const [inherited]

Definition at line 742 of file TCPPortScanner.cpp.

00743 {
00744     return m_iMaxSockets;
00745 }

unsigned short CTCPPortScanner::GetNextPort (  )  [protected, inherited]

Definition at line 297 of file TCPPortScanner.cpp.

00298 {
00299     try
00300     {
00301         //Lock the data
00302         CCriticalAutoRelease aRelease(m_pCSection,TRUE);
00303 
00304         //Do we have a pair
00305         if (!m_aCurrentPair.usFromPort ||
00306             !m_aCurrentPair.usToPort ||
00307             m_aCurrentPair.usFromPort>m_aCurrentPair.usToPort)
00308             //Get a pair
00309             if (m_aPortsToScan.begin()==m_aPortsToScan.end())
00310                 return 0;
00311             else
00312             {
00313                 //Get the pair and remove it
00314                 m_aCurrentPair=m_aPortsToScan.front();
00315                 m_aPortsToScan.pop_front();
00316             }
00317 
00318         //Get the pair we want to send
00319         unsigned short usPort;
00320         usPort=m_aCurrentPair.usFromPort;
00321 
00322         //Increase the port
00323         ++m_aCurrentPair.usFromPort;
00324 
00325         //Done
00326         return usPort;
00327     }
00328     ERROR_HANDLER_RETURN("GetNextPort",0)
00329 }

const CTCPPortScanner::PortsList & CTCPPortScanner::GetPortList (  )  const [inherited]

Definition at line 673 of file TCPPortScanner.cpp.

00674 {
00675     return m_aPortList;
00676 }

int CTCPPortScanner::GetReceiveDataSize (  )  const [inherited]

Definition at line 292 of file TCPPortScanner.cpp.

00293 {
00294     return m_iReceiveData;
00295 }

DWORD CTCPPortScanner::GetReceiveDataTimeout (  )  const [inherited]

Definition at line 287 of file TCPPortScanner.cpp.

00288 {
00289     return m_dwTimeout;
00290 }

IP CTCPPortScanner::GetTarget (  )  const [protected, inherited]

Definition at line 771 of file TCPPortScanner.cpp.

00772 {
00773     return m_aTarget;
00774 }

BOOL CTCPPortScanner::IsDone (  )  const [inherited]

Definition at line 267 of file TCPPortScanner.cpp.

00268 {
00269     return m_bDone;
00270 }

BOOL CTCPPortScanner::IsError (  )  const [inherited]

Definition at line 357 of file TCPPortScanner.cpp.

00358 {
00359     return m_bError;
00360 }

BOOL CTCPPortScanner::IsFinished (  )  const [protected, inherited]

Definition at line 853 of file TCPPortScanner.cpp.

00854 {
00855     return m_bFinished;
00856 }

BOOL CTCPPortScanner::NewSocket (  )  [protected, inherited]

Definition at line 509 of file TCPPortScanner.cpp.

00510 {
00511     try
00512     {
00513         //Are we done
00514         if (m_bDone ||
00515             m_bFinished)
00516             return TRUE;
00517 
00518         //Get a port
00519         unsigned short usPort;
00520         usPort=GetNextPort();
00521 
00522         //Do we have it
00523         if (!usPort)
00524         {
00525             //Are we done
00526             if (AdjustNumberOfSockets(-1)<=0)
00527                 ScanDone(FALSE);
00528 
00529             //Exit
00530             return TRUE;
00531         }
00532 
00533         //Create the socket
00534         CTCPSocketAsync* pSocket;
00535         pSocket=AllocateSocket(usPort);
00536         
00537         //Create it
00538         if (!pSocket)
00539         {
00540             //Are we done
00541             if (AdjustNumberOfSockets(-1)<=0 &&
00542                 !CanScan())
00543             {
00544                 //Run the scan
00545                 ScanDone(FALSE);
00546 
00547                 //Exit
00548                 return TRUE;
00549             }
00550             else
00551                 return FALSE;
00552         }
00553 
00554         //Connect it
00555         if (!pSocket->Connect(0,
00556                               m_aTarget,
00557                               usPort))
00558         {
00559             //Dispose the socket
00560             DestroySocket(pSocket);
00561 
00562             //Are we done
00563             if (AdjustNumberOfSockets(-1)<=0 &&
00564                 !CanScan())
00565             {
00566                 //Run the scan
00567                 ScanDone(FALSE);
00568 
00569                 //Exit
00570                 return TRUE;
00571             }
00572             else
00573                 return FALSE;
00574         }
00575 
00576         //We scanned the port
00577         PortScanned(usPort);
00578 
00579         //Done
00580         return TRUE;
00581     }
00582     ERROR_HANDLER_RETURN("NewSocket",FALSE)
00583 }

void CTCPPortScanner::OnPort ( unsigned short  usPort,
BOOL  bConnected 
) [protected, virtual, inherited]

Definition at line 678 of file TCPPortScanner.cpp.

00680 {
00681 }

void CTCPPortScanner::OnPortData ( unsigned short  usPort,
const char *  pData,
int  iDataSize 
) [protected, virtual, inherited]

Definition at line 683 of file TCPPortScanner.cpp.

00686 {
00687 }

void CTCPPortScanner::PortScanned ( unsigned short  usPort  )  [protected, virtual, inherited]

Reimplemented in CTCPPortScannerStealth.

Definition at line 849 of file TCPPortScanner.cpp.

00850 {
00851 }

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 }

void CTCPPortScanner::ResetData (  )  [protected, inherited]

Definition at line 782 of file TCPPortScanner.cpp.

00783 {
00784     try
00785     {
00786         //Clear the sets
00787         m_aPortAnswers.clear();
00788         m_aPortList.clear();
00789     }
00790     ERROR_HANDLER("ResetData")
00791 }

void CTCPPortScanner::ResetPair (  )  [protected, inherited]

Definition at line 776 of file TCPPortScanner.cpp.

00777 {
00778     m_aCurrentPair.usFromPort=0;
00779     m_aCurrentPair.usToPort=0;
00780 }

void CTCPPortScanner::ResetSocketCount (  )  [protected, inherited]

Definition at line 761 of file TCPPortScanner.cpp.

00762 {
00763     m_iActiveSockets=0;
00764 }

BOOL CTCPPortScannerLinear::Scan ( IP  aTarget  )  [virtual]

Implements CTCPPortScanner.

Definition at line 74 of file TCPPortScannerLinear.cpp.

00075 {
00076     //Check max sockets are ok
00077     if (GetMaxSockets()<=0 ||
00078         !IsDone() ||
00079         !aTarget)
00080     {
00081         //Report it
00082         ReportError("Scan","Invalid parameters!");
00083 
00084         //Exit
00085         return FALSE;
00086     }
00087 
00088     try
00089     {
00090         //Reset the pair
00091         ResetPair();
00092 
00093         //Can we scan
00094         if (!CanScan())
00095         {
00096             //Error
00097             ReportError("Scan","No ports given!");
00098 
00099             //Error
00100             SetError(TRUE);
00101 
00102             //Exit
00103             return FALSE;
00104         }
00105 
00106         //Set the flags
00107         SetError(FALSE);
00108         SetDone(FALSE);
00109 
00110         //Save the number of max sockets
00111         ResetSocketCount();
00112 
00113         //Delete the port data
00114         DeletePortsMap();
00115 
00116         //Delete other data
00117         ResetData();
00118 
00119         //Set our target
00120         SetTarget(aTarget);
00121 
00122         //Start the loop
00123         for (int iCounter=0;
00124              iCounter<GetMaxSockets();
00125              ++iCounter)
00126         {
00127             BOOL bQuit;
00128             bQuit=FALSE;
00129 
00130             //Try to allocate sockets
00131             while (!bQuit)
00132             {
00133                 //Another socket
00134                 AdjustNumberOfSockets(1);
00135 
00136                 //Create it
00137                 if (!(bQuit=NewSocket()))
00138                     ReportError("Scan","Failed to create socket!");
00139             }
00140         }
00141 
00142         //Done
00143         return TRUE;
00144     }
00145     ERROR_HANDLER_RETURN("Scan",FALSE)
00146 }

BOOL CTCPPortScannerLinear::Scan ( const std::string &  rDestinationAddress  )  [virtual]

Implements CTCPPortScanner.

Definition at line 65 of file TCPPortScannerLinear.cpp.

00066 {
00067     try
00068     {
00069         return Scan(CSpoofBase::StringToLong(rDestinationAddress));
00070     }
00071     ERROR_HANDLER_RETURN("Scan",FALSE)
00072 }

void CTCPPortScanner::ScanDone ( BOOL  bError,
BOOL  bSpawnThread = TRUE 
) [protected, inherited]

Definition at line 628 of file TCPPortScanner.cpp.

00630 {
00631     try
00632     {
00633         {
00634             //Lock
00635             CCriticalAutoRelease aRelease(m_pCSectionDone);
00636 
00637             //What shell we do?
00638             if (m_bDone ||
00639                 m_bFinished)
00640                 return;
00641 
00642             //Set we are finished
00643             m_bFinished=TRUE;
00644         }
00645 
00646         //Thread's data
00647         ThreadData* pData;
00648         pData=new ThreadData;
00649 
00650         //Populate it
00651         pData->bError=bError;
00652         pData->pScanner=this;
00653         
00654         //Do we have a thread
00655         if (bSpawnThread)
00656         {
00657             //Spawn a thread
00658             CGenericThread* pThread;
00659             pThread=COSManager::CreateThread(DoneThread);
00660 
00661             //Set to autodelete
00662             pThread->SetAutoDelete(TRUE);
00663 
00664             //Start it
00665             pThread->Start((LPVOID)pData);
00666         }
00667         else
00668             DoneThread((LPVOID)pData);
00669     }
00670     ERROR_HANDLER("ScanDone")
00671 }

void CTCPPortScanner::SetConnectionTimeout ( int  iMS  )  [inherited]

Definition at line 727 of file TCPPortScanner.cpp.

00728 {
00729     m_iConnectionTimeout=iMS;
00730 }

void CTCPPortScanner::SetDone ( BOOL  bDone  )  [protected, inherited]

Definition at line 752 of file TCPPortScanner.cpp.

00753 {
00754     m_bDone=bDone;
00755 
00756     //Set the finish flag
00757     if (!bDone)
00758         m_bFinished=FALSE;
00759 }

void CTCPPortScanner::SetError ( BOOL  bError  )  [protected, inherited]

Definition at line 747 of file TCPPortScanner.cpp.

00748 {
00749     m_bError=bError;
00750 }

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 CTCPPortScanner::SetMaxSockets ( int  iMaxSockets  )  [inherited]

Definition at line 737 of file TCPPortScanner.cpp.

00738 {
00739     m_iMaxSockets=iMaxSockets;
00740 }

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 CTCPPortScanner::SetReceiveData ( int  iMaxDataSize,
DWORD  dwTimeout 
) [inherited]

Definition at line 272 of file TCPPortScanner.cpp.

00274 {
00275     if (!m_bDone ||
00276         !m_bFinished)
00277         return;
00278 
00279     try
00280     {
00281         m_iReceiveData=iMaxDataSize;
00282         m_dwTimeout=dwTimeout;
00283     }
00284     ERROR_HANDLER("SetReceiveData")
00285 }

void CTCPPortScanner::SetTarget ( IP  aTarget  )  [protected, inherited]

Definition at line 766 of file TCPPortScanner.cpp.

00767 {
00768     m_aTarget=aTarget;
00769 }

void CTCPPortScanner::SocketDone ( unsigned short  usPort,
char *  pData,
int  iDataSize 
) [protected, inherited]

Definition at line 420 of file TCPPortScanner.cpp.

00423 {
00424     try
00425     {
00426         if (m_bDone ||
00427             m_bFinished)
00428             return;
00429 
00430         {
00431             //Lock the data
00432             CCriticalAutoRelease aRelease(m_pCSection,TRUE);
00433 
00434             //Did we receive this answer already?
00435             if (m_aPortAnswers.find(usPort)!=m_aPortAnswers.end())
00436                 return;
00437 
00438             //Add it to the list
00439             m_aPortList.insert(usPort);
00440 
00441             //And to the existing ports
00442             m_aPortAnswers.insert(usPort);
00443 
00444             //Add the data to the map
00445             m_aPortsData.insert(DataMap::value_type(usPort,pData));
00446         }
00447 
00448         //Inidicate for user
00449         OnPortData(usPort,
00450                    pData,
00451                    iDataSize);
00452 
00453         long lCount;
00454         lCount=AdjustNumberOfSockets(-1);
00455 
00456         //Decrease our count
00457         if (!CanScan() &&
00458             lCount<=0)
00459             ScanDone(FALSE);
00460         else
00461         {
00462             //Quit flag
00463             BOOL bQuit;
00464             bQuit=FALSE;
00465 
00466             //Create the socket
00467             while (!bQuit)
00468             {
00469                 //Adjust the number of sockets
00470                 AdjustNumberOfSockets(1);
00471 
00472                 //Allocate it
00473                 if (!(bQuit=NewSocket()))
00474                     ReportError("SocketDone","Error creating the socket!");
00475             }
00476         }
00477     }
00478     ERROR_HANDLER("SocketDone")
00479 }

void CTCPPortScanner::SocketDone ( unsigned short  usPort,
BOOL  bConnected 
) [protected, inherited]

Definition at line 362 of file TCPPortScanner.cpp.

00364 {
00365     try
00366     {
00367         if (m_bDone ||
00368             m_bFinished)
00369             return;
00370 
00371         //Only if connected
00372         if (bConnected)
00373         {
00374             //Lock the data
00375             CCriticalAutoRelease aRelease(m_pCSection,TRUE);
00376 
00377             //Did we receive this answer already?
00378             if (m_aPortAnswers.find(usPort)!=m_aPortAnswers.end())
00379                 return;
00380 
00381             //Add it to the list
00382             m_aPortList.insert(usPort);
00383 
00384             //And to the existing ports
00385             m_aPortAnswers.insert(usPort);
00386         }
00387 
00388         //Inicate for user
00389         OnPort(usPort,
00390                bConnected);
00391 
00392         long lCount;
00393         lCount=AdjustNumberOfSockets(-1);
00394 
00395         //Decrease our count
00396         if (!CanScan() &&
00397             lCount<=0)
00398             ScanDone(FALSE);
00399         else
00400         {
00401             //Quit flag
00402             BOOL bQuit;
00403             bQuit=FALSE;
00404 
00405             //Create the socket
00406             while (!bQuit)
00407             {
00408                 //Adjust the number of sockets
00409                 AdjustNumberOfSockets(1);
00410 
00411                 //Allocate it
00412                 if (!(bQuit=NewSocket()))
00413                     ReportError("SocketDone","Error creating the socket!");
00414             }
00415         }
00416     }
00417     ERROR_HANDLER("SocketDone")
00418 }

BOOL CTCPPortScanner::StopScan (  )  [virtual, inherited]

Definition at line 858 of file TCPPortScanner.cpp.

00859 {
00860     try
00861     {
00862         //Call we are done
00863         ScanDone(TRUE,
00864                  FALSE);
00865 
00866         //Done
00867         return TRUE;
00868     }
00869     ERROR_HANDLER_RETURN("StopScan",FALSE)
00870 }

void CTCPPortScanner::TCPScanDone ( BOOL  bError  )  [protected, virtual, inherited]

Definition at line 689 of file TCPPortScanner.cpp.

00690 {
00691 }

void CTCPPortScanner::TCPScanDoneLib ( BOOL  bError  )  [protected, virtual, inherited]

Reimplemented in CTCPPortScannerStealth, and CUDPScanner.

Definition at line 845 of file TCPPortScanner.cpp.

00846 {
00847 }

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 }


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