SnifferDlg.h
资源名称:MSSniffer.zip [点击查看]
上传用户:benyan892
上传日期:2010-01-28
资源大小:158k
文件大小:3k
源码类别:
网络截获/分析
开发平台:
Visual C++
- // 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;
- };