📄 tcpsocket.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_TCPSOCKET_H__77DA7F21_291E_4C2A_B12B_535ABA1E829C__INCLUDED_)
#define AFX_TCPSOCKET_H__77DA7F21_291E_4C2A_B12B_535ABA1E829C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "SpoofSocket.h"
#include "AsyncSocket.h"
/////////////////////////////////////////////////////////////////////////////
// CSpoofSocket command target
//////////////////////////////////////////////////////////////////
// //
// TCP Header //
// Implementation of RFC793 TCP Header //
// //
//////////////////////////////////////////////////////////////////
//##ModelId=3B43E6EF0088
typedef struct _TCPHeader
{
unsigned short SourcePort;
unsigned short DestinationPort;
unsigned int SequenceNumber;
unsigned int AcknowledgeNumber;
unsigned char DataOffset; //Crappy MFC can't use bits
unsigned char Flags;
unsigned short Windows;
unsigned short Checksum;
unsigned short UrgentPointer;
} TCPHeader;
//##ModelId=3B43E6EF00B7
typedef TCPHeader FAR * LPTCPHeader;
#define TCPHeaderLength sizeof(TCPHeader)
//All of the TCP header flags
#define TCPFlag_URG 0
#define TCPFlag_ACK 2
#define TCPFlag_PSH 4
#define TCPFlag_RST 8
#define TCPFlag_SYN 16
#define TCPFlag_FYN 32
//TCP Options
#define TCPOptions_END 0
#define TCPOptions_NO_OPERATION 1
#define TCPOptions_MAX_Segment 2
//Max segment size
#define TCPOptions_MAX_Segment_Length 4
//##ModelId=3B43E6EF012F
class CTCPOptions : protected CIPOptions
{
public:
//Add options Segment size
//##ModelId=3B43E6EF0143
void AddOption_SegmentSize(unsigned short usMax);
//Reset all the data in the options
//##ModelId=3B43E6EF014D
void Reset();
//Do we auto pad to a 4 bytes limit
//##ModelId=3B43E6EF014E
void SetAutoPad(BOOL bAutoPAD);
//List terminator
//##ModelId=3B43E6EF0158
virtual void AddOption_ENDLIST();
//Get the length of the options buffer
//##ModelId=3B43E6EF0161
int GetBufferLength();
//Get the buffer itself
//##ModelId=3B43E6EF0162
const char* GetBuffer();
//Add option nothing
//##ModelId=3B43E6EF016B
virtual void AddOption_Nothing();
//ctor and dtor
//##ModelId=3B43E6EF0175
CTCPOptions();
//##ModelId=3B43E6EF0176
virtual ~CTCPOptions();
};
//##ModelId=3B43E6EF0251
class CTCPSocket : public CSpoofSocket
{
public:
//Send data over the sockets
//##ModelId=3B43E6EF0265
BOOL Send(char* buf,int bufLen);
//Accept a connection, supply an already made socket
//##ModelId=3B43E6EF0268
BOOL Accept(CTCPSocket* tSok);
//Accept a connection, create the socket class
//##ModelId=3B43E6EF0270
CTCPSocket* Accept();
//Listen to incoming connections
//##ModelId=3B43E6EF0279
virtual BOOL Listen(int iBackLog);
//Create this socket as a regular socket
//##ModelId=3B43E6EF0283
virtual BOOL CreateRegular();
//Get the class of the TCP options
//##ModelId=3B43E6EF0285
CTCPOptions* GetTCPOptions();
//Connect to a remote system
//##ModelId=3B43E6EF028D
virtual BOOL Connect(int iSourcePort,LPCSTR lpDestinationAddress,int iDestinationPort);
//Create as a raw socket
//##ModelId=3B43E6EF02A1
virtual BOOL Create();
//Supply the class of TCP options
//##ModelId=3B43E6EF02AB
void SetTCPOptions(BOOL bOptions);
//ctor and dtor
//##ModelId=3B43E6EF02AD
CTCPSocket();
//##ModelId=3B43E6EF02B5
virtual ~CTCPSocket();
private:
//Initialize the class
//##ModelId=3B43E6EF02C9
void InitializeTCP();
//Attach to a socket
//##ModelId=3B43E6EF02CA
CTCPSocket(SOCKET sok);
//Set flags in the header
//##ModelId=3B43E6EF02DD
void SetHeaderFlag(LPTCPHeader lpHead,int iFlag);
//Create the TCP header
//##ModelId=3B43E6EF02E7
LPTCPHeader ConstructTCPHeader(int iSourcePort,int iDestinationPort,int iHeaderLength);
//The TCP options
//##ModelId=3B43E6EF0343
CTCPOptions* m_TCPOptions;
//Do we have options
//##ModelId=3B43E6EF036A
BOOL m_Options;
//Sequence in the TCP header
//##ModelId=3B43E6F00040
static unsigned int m_Sequence;
protected:
//When the socket is accepted, what to do
//##ModelId=3B43E6F00054
virtual void Accepted();
};
#endif // !defined(AFX_TCPSOCKET_H__77DA7F21_291E_4C2A_B12B_535ABA1E829C__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -