📄 spoofbase.h
字号:
/*
*
*
* Copyright (c) 2000 Barak Weichselbaum <barak@komodia.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*
* Contact info:
* Site: http://www.komodia.com
* Email: barak@komodia.com
*/
#if !defined(AFX_SPOOFBASE_H__3760FA30_2B52_4F62_9EB6_46640C36E4F1__INCLUDED_)
#define AFX_SPOOFBASE_H__3760FA30_2B52_4F62_9EB6_46640C36E4F1__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//windows sockets2
#include <winsock2.h>
#include <ws2tcpip.h>
#define ERROR_HANDLER(METHOD_NAME) \
catch (...)\
{\
/*Get the last error*/\
ReportError(METHOD_NAME);\
}
#define ERROR_HANDLER_RETURN(METHOD_NAME,RETURN_VALUE) \
catch (...)\
{\
/*Get the last error*/\
ReportError(METHOD_NAME);\
return RETURN_VALUE;\
}
//Manage static handlers
#define ERROR_HANDLER_STATIC(CLASS_NAME,METHOD_NAME) \
catch (...)\
{\
/*Get the last error*/\
CSpoofBase::ReportStaticError(CLASS_NAME,METHOD_NAME);\
}
#define ERROR_HANDLER_STATIC_RETURN(CLASS_NAME,METHOD_NAME,RETURN_VALUE) \
catch (...)\
{\
/*Get the last error*/\
CSpoofBase::ReportStaticError(CLASS_NAME,METHOD_NAME);\
return RETURN_VALUE;\
}
#define ERROR_HANDLER_AMBIG(BASE_CLASS,METHOD_NAME) \
catch (...)\
{\
/*Get the last error*/\
BASE_CLASS::ReportError(METHOD_NAME);\
}
#define ERROR_HANDLER_AMBIG_RETURN(BASE_CLASS,METHOD_NAME,RETURN_VALUE) \
catch (...)\
{\
/*Get the last error*/\
BASE_CLASS::ReportError(METHOD_NAME);\
return RETURN_VALUE;\
}
//Handles basic errors
//##ModelId=3B43E6F30289
class CSpoofBase
{
public:
//The external log
//##ModelId=3B43E6F40050
class CSpoofLog
{
friend class CSpoofBase;
public:
//ctor and dtor
//##ModelId=3B43E6F4005A
CSpoofLog();
//##ModelId=3B43E6F40064
virtual ~CSpoofLog();
protected:
//Report an error must overide
//##ModelId=3B43E6F4006E
virtual void ReportCatchError(LPCSTR lpClass,LPCSTR lpMethod,LPCSTR lpMessage)=0;
//##ModelId=3B43E6F4007A
virtual void ReportInitiatedError(LPCSTR lpClass,LPCSTR lpMethod,LPCSTR lpMessage)=0;
//##ModelId=3B43E6F4008C
virtual void ReportSocketError(LPCSTR lpClass,LPCSTR lpMethod,int iErrorCode)=0;
};
public:
//Set the local log
//##ModelId=3B43E6F3029D
void SetLocalLog(CSpoofLog* pLog);
//Convert long to string
//##ModelId=3B43E6F3029F
char FAR * LongToString(long lAddr);
//Save a new log
//##ModelId=3B43E6F302A8
void SetLog(CSpoofLog* pLog);
//Initialize the sockets
//##ModelId=3B43E6F302B2
static BOOL InitializeSockets(BOOL bMultiThreaded=FALSE,int iNumberOfThreads=0);
//Shutdown the sockets
//##ModelId=3B43E6F302BD
static BOOL ShutdownSockets();
//Get the last error
//##ModelId=3B43E6F302C6
int GetLastError();
//ctor and dtor
//##ModelId=3B43E6F302CF
CSpoofBase();
//##ModelId=3B43E6F302D0
virtual ~CSpoofBase();
protected:
//Get the number of threads
//##ModelId=3B43E6F302DA
static int GetNumberOfThreads();
//Are we multithreaded
//##ModelId=3B43E6F302E4
static BOOL IsMultiThreaded();
//Report an unknown error (use GetLastError)
//##ModelId=3B43E6F302ED
void ReportError(LPCSTR lpMethod);
//Report an unknown error (use GetLastError)
//##ModelId=3B43E6F302F8
static void ReportStaticError(LPCSTR lpClass,LPCSTR lpMethod);
//Report an unknown error (use GetLastError)
//##ModelId=3B43E6F3030B
static void ReportStaticError(LPCSTR lpClass,LPCSTR lpMethod,LPCSTR lpMessage);
//Shutdown notifier
//##ModelId=3B43E6F30317
virtual void NotifyShutdown();
//Register shutdown class
//##ModelId=3B43E6F3031F
void RegisterShutdown(CSpoofBase* pBase);
//Report an error
//##ModelId=3B43E6F3032A
void ReportError(LPCSTR lpMethod,LPCSTR lpMessage);
//Report and error
//##ModelId=3B43E6F30335
virtual void ReportError(LPCSTR lpMethod,int iErrorCode);
//Set the name of the current class
//##ModelId=3B43E6F30347
void SetName(LPCSTR lpName);
//Set the socket last error
//##ModelId=3B43E6F30351
void SetLastError(LPCSTR lpMethod);
//##ModelId=3B43E6F3035C
void SetLastError(LPCSTR lpMethod,int iErrorCode);
private:
//Get the correct log
//##ModelId=3B43E6F3036F
CSpoofLog* GetLog();
//Last error we had
//##ModelId=3B43E6F30370
int m_LastError;
//Our log
//##ModelId=3B43E6F30384
static CSpoofLog* m_Log;
//If we have a local log
//##ModelId=3B43E6F303A2
CSpoofLog* m_LocalLog;
//Are we initialized
//##ModelId=3B43E6F303AB
static BOOL m_Initialized;
//Our class name
//##ModelId=3B43E6F303BF
LPSTR m_lpClassName;
//Class to notify
//##ModelId=3B43E6F303DE
static CSpoofBase* m_pShutdownClass;
//Are we multithreaded
//##ModelId=3B43E6F40000
static BOOL m_bMultiThreaded;
//Number of threaded
//##ModelId=3B43E6F4001E
static int m_NumberOfThreads;
};
#endif // !defined(AFX_SPOOFBASE_H__3760FA30_2B52_4F62_9EB6_46640C36E4F1__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -