📄 snifferdlg.h
字号:
// SnifferDlg.h : header file
//
#pragma once
#include <WinSock2.h>
#include <MSTcpIP.h>
#include "Definition.h"
#include "iphdr.h"
#include <afxtempl.h>
#include "afxwin.h"
#include "afxcmn.h"
struct Session
{
unsigned int sourcePort, destPort;
CString sourceIP, destIP;
Session* pOtherSide;
tcp_seq ISN;
DWORD len;
};
class TVPacketItem
{
public:
const CString m_SourceIP;
const CString m_DestIP;
const CString m_SourcePort;
const CString m_DestPort;
const CString m_Size;
const CString m_Flags;
const CString m_Sequence;
const CString m_Ack;
TVPacketItem(const CString& sourceIP, const CString& sourcePort, const CString& destIP,
const CString& destPort, const CString& size, const CString& flags, const CString& sequence,
const CString& ack)
: m_SourceIP(sourceIP), m_SourcePort( sourcePort ), m_DestIP( destIP ),
m_DestPort( destPort ), m_Size ( size ), m_Flags ( flags ),
m_Sequence ( sequence ), m_Ack( ack )
{
}
};
#define LV_SOURCE_IP 0
#define LV_DEST_IP 1
#define LV_SOURCE_PORT 2
#define LV_DEST_PORT 3
#define LV_SIZE 4
#define LV_SEQUENCE 5
#define LV_ACK 6
#define LV_FLAG 7
// CSnifferDlg dialog
class CSnifferDlg : public CDialog
{
// Construction
public:
CSnifferDlg(CWnd* pParent = NULL); // standard constructor
static ULONG WINAPI SnifferThread(LPVOID pParam);
// Starts the sniffing process
bool StartSniffing(void);
// Dialog Data
enum { IDD = IDD_SNIFFER_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
private:
CImageList m_IL;
void InsertPacketToTV(const TVPacketItem& packetItem);
bool m_bExit;
HANDLE m_hThread;
DWORD m_dwThreadID;
// Array of Interfaces
CStringArray m_Interfaces;
// Print the session to a log file
void PrintSession( Session* pSession );
// Print the packet to a log file
void PrintPacket( const CString& source, const CString& destination,TCP_HDR* pTCPHeader, DWORD dwSize, const CString& errors ) ;
bool ParseTCPPacket(const CString& source, const CString& destination, TCP_HDR* pTCPHeader, char* pData, unsigned long len );
//
// Filter Variables
//
SOCKADDR_STORAGE m_saSourceAddress, // Source address to filter
m_saDestinationAddress; // Destination address to filter
unsigned long m_ulFilterMask; // Indicates which fields in IP hdr to
// filter on.
CFile m_Logger;
CArray<Session*,Session*> m_Array;
bool Init(void);
// Decodes the packet
bool DecodePacket(char* pData, DWORD dwSize);
void ConvertAddress( unsigned int address, CString& strAddress );
public:
bool GetInterfaces(CStringArray& interfaces);
afx_msg void OnSize(UINT nType, int cx, int cy);
void ResizeForm(void);
private:
CComboBox m_CmbInterfaces;
public:
CStatic m_FrmInterfaces;
afx_msg void OnBnClickedStartsniffing();
private:
// Selected Interface
CString m_SelInterface;
public:
afx_msg void OnClose();
CButton m_BtnStartSniffing;
// TreeView of packets
CTreeCtrl m_TVPackets;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -