// TODO: Add your message handler code here if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } // Do not call CDialog::OnPaint() for painting messages }
#define AFX_PROANALYSIS_H__E62B2332_53D0_45DE_8E97_7E8666E87D08__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afxcview.h>
#include <afxtempl.h>
#include <pcap.h>
// ProAnalysis.h : header file
//
class IPGram;
class EtherHead;
class TCPGram;
class UDPGram;
class ICMPGram;
class ARPGram;
class RARPGram;
class CMainFrame;
class CMulPackView;/////////////////////////////////////////////////////////////////////////////
// CProAnalysis dialogclass CProAnalysis : public CDialog
{
// Construction
public:
CProAnalysis( CArray<const struct pcap_pkthdr *,const struct pcap_pkthdr *>&pkt_header,
CArray<const u_char *,const u_char *>&pkt_data,
int totallen,CWnd* pParent= NULL ); // standard constructor HICON m_hIcon;
IPGram *ip;
EtherHead *ether;
TCPGram *tcp;
UDPGram *udp;
ICMPGram *icmp;
ARPGram *arp;
RARPGram *rarp;
int i;
CArray<const struct pcap_pkthdr *,const struct pcap_pkthdr *> pkt_header;
CArray<const u_char *,const u_char *> pkt_data;
// Dialog Data
//{{AFX_DATA(CProAnalysis)
enum { IDD = IDD_ProtocolAnalysis_DIALOG };
CTabCtrl m_tab1;
CListCtrl m_list_arp;
CListCtrl m_list_common;
CListCtrl m_list_udp;
CListCtrl m_list_tcp;
CListCtrl m_list_ethernet;
CListCtrl m_list_ip;
CListCtrl m_list_icmp;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CProAnalysis)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CProAnalysis)
afx_msg void OnClickTab1(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnPaint();
virtual BOOL OnInitDialog();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnButtonStart();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_PROANALYSIS_H__E62B2332_53D0_45DE_8E97_7E8666E87D08__INCLUDED_)
//#include "stdafx.h"
#include "snifferpro.h"
#include "ProAnalysis.h"
#include"Mainfrm.h"
#include "MulPackView.h"
#include "resource.h"
#include <afxtempl.h>#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
HWND hWnd;
struct ProtocolNumber
{
int count;
int ethernet;
int arp;
int ip;
int tcp;
int udp;
int icmp;
};
struct ProtocolNumber PacketNumber;
/////////////////////////////////////////////////////////////////////////////
// CProAnalysis dialog
CProAnalysis::CProAnalysis( CArray<const struct pcap_pkthdr *,const struct pcap_pkthdr *> &pkt_header,
CArray<const u_char *,const u_char *>&pkt_data,
int totallen,CWnd* pParent )
:CDialog(CProAnalysis::IDD, pParent)
{
//{{AFX_DATA_INIT(CProAnalysis)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// int j;
this->pkt_header.Copy(pkt_header);
this->pkt_data.Copy(pkt_data);
// j= this->pkt_header.GetSize();
i=totallen;
ip=NULL; ether=NULL; tcp=NULL; udp=NULL;
icmp=NULL; arp=NULL; rarp=NULL;
}
void CProAnalysis::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProAnalysis)
DDX_Control(pDX, IDC_TAB1, m_tab1);
DDX_Control(pDX, IDC_LIST3, m_list_arp);
DDX_Control(pDX, IDC_LIST2, m_list_common);
DDX_Control(pDX, IDC_LIST_UDP, m_list_udp);
DDX_Control(pDX, IDC_LIST_TCP, m_list_tcp);
DDX_Control(pDX, IDC_LIST_PPPOE, m_list_ethernet);
DDX_Control(pDX, IDC_LIST_IP, m_list_ip);
DDX_Control(pDX, IDC_LIST_ICMP, m_list_icmp);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProAnalysis, CDialog)
//{{AFX_MSG_MAP(CProAnalysis)
ON_NOTIFY(NM_CLICK, IDC_TAB1, OnClickTab1)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1)
ON_WM_PAINT()
ON_WM_SIZE()
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CProAnalysis message handlersvoid CProAnalysis::OnClickTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CRect rect1, rect2;
m_tab1.GetWindowRect(rect1);
m_tab1.GetItemRect(0, rect2);
ScreenToClient(rect1);
rect1.left += 2;
rect1.top += rect2.Height() + 3;
m_list_common.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_arp.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_ip.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_tcp.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_udp.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_icmp.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_ethernet.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
*pResult = 0;
}void CProAnalysis::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
if (m_tab1.GetCurSel() == 0)
{
m_list_common.ShowWindow(SW_SHOW);
m_list_arp.ShowWindow(SW_HIDE);
m_list_ip.ShowWindow(SW_HIDE);
m_list_tcp.ShowWindow(SW_HIDE);
m_list_udp.ShowWindow(SW_HIDE);
m_list_icmp.ShowWindow(SW_HIDE);
m_list_ethernet.ShowWindow(SW_HIDE);
CStatic *p=(CStatic *)GetDlgItem(IDC_STATIC_STATUS);
p->SetWindowText ("数据包信息"); }
else if (m_tab1.GetCurSel() == 1)
{
m_list_arp.ShowWindow(SW_SHOW);
m_list_common.ShowWindow(SW_HIDE);
m_list_ip.ShowWindow(SW_HIDE);
m_list_tcp.ShowWindow(SW_HIDE);
m_list_udp.ShowWindow(SW_HIDE);
m_list_icmp.ShowWindow(SW_HIDE);
m_list_ethernet.ShowWindow(SW_HIDE);
CStatic *p=(CStatic *)GetDlgItem(IDC_STATIC_STATUS);
p->SetWindowText ("ARP协议分析");
}
else if (m_tab1.GetCurSel() == 2)
{
m_list_ip.ShowWindow(SW_SHOW);
m_list_common.ShowWindow(SW_HIDE);
m_list_arp.ShowWindow(SW_HIDE);
m_list_tcp.ShowWindow(SW_HIDE);
m_list_udp.ShowWindow(SW_HIDE);
m_list_icmp.ShowWindow(SW_HIDE);
m_list_ethernet.ShowWindow(SW_HIDE);
CStatic *p=(CStatic *)GetDlgItem(IDC_STATIC_STATUS);
p->SetWindowText ("IP协议分析");
}
else if (m_tab1.GetCurSel() == 3)
{
m_list_tcp.ShowWindow(SW_SHOW);
m_list_ip.ShowWindow(SW_HIDE);
m_list_common.ShowWindow(SW_HIDE);
m_list_arp.ShowWindow(SW_HIDE);
m_list_udp.ShowWindow(SW_HIDE);
m_list_icmp.ShowWindow(SW_HIDE);
m_list_ethernet.ShowWindow(SW_HIDE);
CStatic *p=(CStatic *)GetDlgItem(IDC_STATIC_STATUS);
p->SetWindowText ("TCP协议分析");
}
else if (m_tab1.GetCurSel() == 4)
{
m_list_udp.ShowWindow(SW_SHOW);
m_list_ip.ShowWindow(SW_HIDE);
m_list_common.ShowWindow(SW_HIDE);
m_list_arp.ShowWindow(SW_HIDE);
m_list_icmp.ShowWindow(SW_HIDE);
m_list_tcp.ShowWindow(SW_HIDE);
m_list_ethernet.ShowWindow(SW_HIDE);
CStatic *p=(CStatic *)GetDlgItem(IDC_STATIC_STATUS);
p->SetWindowText ("UDP协议分析");
}
else if (m_tab1.GetCurSel() == 5)
{
m_list_icmp.ShowWindow(SW_SHOW);
m_list_ip.ShowWindow(SW_HIDE);
m_list_common.ShowWindow(SW_HIDE);
m_list_arp.ShowWindow(SW_HIDE);
m_list_udp.ShowWindow(SW_HIDE);
m_list_tcp.ShowWindow(SW_HIDE);
m_list_ethernet.ShowWindow(SW_HIDE);
CStatic *p=(CStatic *)GetDlgItem(IDC_STATIC_STATUS);
p->SetWindowText ("ICMP协议分析");
}
else if(m_tab1.GetCurSel () == 6 )
{
m_list_ethernet.ShowWindow(SW_SHOW);
m_list_icmp.ShowWindow(SW_HIDE);
m_list_ip.ShowWindow(SW_HIDE);
m_list_common.ShowWindow(SW_HIDE);
m_list_arp.ShowWindow(SW_HIDE);
m_list_udp.ShowWindow(SW_HIDE);
m_list_tcp.ShowWindow(SW_HIDE);
CStatic *p=(CStatic *)GetDlgItem(IDC_STATIC_STATUS);
p->SetWindowText ("以太网协议分析");
}
else
{
m_list_common.ShowWindow(SW_HIDE);
m_list_arp.ShowWindow(SW_HIDE);
m_list_ip.ShowWindow(SW_HIDE);
m_list_tcp.ShowWindow(SW_HIDE);
m_list_udp.ShowWindow(SW_HIDE);
m_list_icmp.ShowWindow(SW_HIDE);
m_list_ethernet.ShowWindow(SW_HIDE);
CStatic *p=(CStatic *)GetDlgItem(IDC_STATIC_STATUS);
p->SetWindowText ("ICMP协议分析");
}
CRect rect1, rect2;
m_tab1.GetWindowRect(rect1);
m_tab1.GetItemRect(0, rect2);
ScreenToClient(rect1);
rect1.left += 2;
rect1.top += rect2.Height() + 3;
m_list_common.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_arp.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_ip.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_tcp.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_udp.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
m_list_icmp.SetWindowPos(NULL, rect1.left, rect1.top, rect1.Width(),
rect1.Height() - rect2.Height() - 000, NULL);
*pResult = 0;
}
{
// CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
// Do not call CDialog::OnPaint() for painting messages
}