📄 dddialog.cpp
字号:
/****************************************************************************
** **
** Copyright (c) 2004 microOLAP Technologies LTD, **
** Halturin A.P., Naumov D.A. **
** Source File **
** **
****************************************************************************/
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "HNPsSdkUser.h"
#include "PacketStat.h"
#include "DDDialog.h"
#include "Ethernet.h"
#include "Arp.h"
#include "Ip.h"
#include "Tcp.h"
#include "Udp.h"
#include "Icmp.h"
#include <stdio.h>
#include <ctype.h>
//-----------------------------------------------------------------------------
#define HN_TIMER_ID 1 // Statistics timer ID
//-----------------------------------------------------------------------------
// HN_WM_THREAD_EXIT - our window message for informing of the working thread
// exit
#define HN_WM_THREAD_EXIT (WM_USER + 1)
//-----------------------------------------------------------------------------
DWORD dwOldPrTotal_Count; // For process speed
DWORD dwOldPrTotal_Bytes;
DWORD dwPrTotal_Count;
DWORD dwPrTotal_Bytes;
DWORD dwOldCapTotal_Count; // For capture speed
DWORD dwOldCapTotal_Bytes;
DWORD dwCapTotal_Count;
DWORD dwCapTotal_Bytes;
DWORD dwIP_Count;
DWORD dwIP_Bytes;
DWORD dwTCP_Count;
DWORD dwTCP_Bytes;
DWORD dwUDP_Count;
DWORD dwUDP_Bytes;
DWORD dwARP_Count;
DWORD dwARP_Bytes;
DWORD dwICMP_Count;
DWORD dwICMP_Bytes;
DWORD dwOther_Count;
DWORD dwOther_Bytes;
//-----------------------------------------------------------------------------
// Static handlers for the
// HNPSManager.OnConfigChange
// HNQueue.OnPacketReceive
// events redirect calls to the dialog object class
//-----------------------------------------------------------------------------
void __stdcall _raw_OnConfigChange(DWORD_PTR Param, HANDLE hCfg, DWORD ChangeType)
{
((CDDDialog*)Param)->OnConfigChange(hCfg,ChangeType);
}
void __stdcall _raw_OnPacketReceive(DWORD_PTR Param, DWORD_PTR ThParam, HANDLE hPacket, LPVOID pPacketData, DWORD IncPacketSize)
{
((CDDDialog*)Param)->OnPacketReceive(ThParam,hPacket,pPacketData,IncPacketSize);
}
//-----------------------------------------------------------------------------
// CDDDialog MESSAGE MAP
//-----------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CDDDialog, CDialog)
//{{AFX_MSG_MAP(CDDDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ABOUT_BTN, OnAboutBtn)
ON_BN_CLICKED(IDC_MGR_INIT_BTN, OnManagerInitBtn)
ON_BN_CLICKED(IDC_OPEN_BTN, OnOpenBtn)
ON_BN_CLICKED(IDC_CLOSE_BTN, OnCloseBtn)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_CLEAR_BTN, OnClearBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
// CDDDialog dialog
//-----------------------------------------------------------------------------
CDDDialog::CDDDialog(CWnd* pParent /*=NULL*/)
: CDialog(CDDDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CDDDialog)
strBpfAccept = _T("0");
strBpfProcess = _T("0");
strBpfReceive = _T("0");
strBpfReject = _T("0");
strNdisMissed = _T("0");
strNdisRecvWithErr = _T("0");
strNdisRecvWithoutErr = _T("0");
strNdisTranWithErr = _T("0");
strNdisTranWithoutErr = _T("0");
PktPoolCountEdit = _T("250000");
PoolMem_Label = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
//-----------------------------------------------------------------------------
// DoDataExchange
//-----------------------------------------------------------------------------
void CDDDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDDDialog)
DDX_Control(pDX, IDC_POOL_COUNT_EDIT, WndPktCount);
DDX_Control(pDX, IDC_PACKET_STAT_LIST, CountersList);
DDX_Control(pDX, IDC_MGR_INIT_BTN, MgrInitBtn);
DDX_Control(pDX, IDC_CLOSE_BTN, CloseBtn);
DDX_Control(pDX, IDC_OPEN_BTN, OpenBtn);
DDX_Control(pDX, IDC_NET_CARDS_COMBO, cbNetCardList);
DDX_Text(pDX, IDC_BPF_ACCEPT, strBpfAccept);
DDX_Text(pDX, IDC_BPF_PROCESS, strBpfProcess);
DDX_Text(pDX, IDC_BPF_RECEIVE, strBpfReceive);
DDX_Text(pDX, IDC_BPF_REJECT, strBpfReject);
DDX_Text(pDX, IDC_NDIS_MISSED, strNdisMissed);
DDX_Text(pDX, IDC_NDIS_RECV_WITH_ERR, strNdisRecvWithErr);
DDX_Text(pDX, IDC_NDIS_RECV_WITHOUT_ERR, strNdisRecvWithoutErr);
DDX_Text(pDX, IDC_NDIS_TRAN_WITH_ERR, strNdisTranWithErr);
DDX_Text(pDX, IDC_NDIS_TRAN_WITHOUT_ERR, strNdisTranWithoutErr);
DDX_Text(pDX, IDC_POOL_COUNT_EDIT, PktPoolCountEdit);
DDX_Text(pDX, IDC_POOL_MEM_STATIC, PoolMem_Label);
//}}AFX_DATA_MAP
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// CDDDialog message handlers
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//-----------------------------------------------------------------------------
// OnSysCommand
//-----------------------------------------------------------------------------
void CDDDialog::OnSysCommand(UINT nID, LPARAM lParam)
{
CDialog::OnSysCommand(nID, lParam);
}
//-----------------------------------------------------------------------------
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
//-----------------------------------------------------------------------------
// OnPaint
//-----------------------------------------------------------------------------
void CDDDialog::OnPaint()
{
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();
}
}
//-----------------------------------------------------------------------------
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
//-----------------------------------------------------------------------------
// OnQueryDragIcon
//-----------------------------------------------------------------------------
HCURSOR CDDDialog::OnQueryDragIcon()
{
return (HCURSOR)m_hIcon;
}
//---------------------------------------------------------------------------
// OnInitDialog
//---------------------------------------------------------------------------
BOOL CDDDialog::OnInitDialog()
{
//########################################################################
// The code generated with the MFC Wisard
CDialog::OnInitDialog();
// Add the "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if(pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if(!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//########################################################################
// Our initialization code
ValFormat[0] = "0 bytes";
ValFormat[1] = "%.1f Kb";
ValFormat[2] = "%.2f Mb";
ValFormat[3] = "%.2f Gb";
cbNetCardList.SetDroppedWidth(100);
cbNetCardList.SetCurSel(0);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Set the OnConfigChange event handler
HNPSManager.Set_OnConfigChange((FARPROC)_raw_OnConfigChange,(DWORD_PTR)this);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Set the OnPacketReceive event handler
HNQueue.Set_OnPacketRecv((FARPROC)_raw_OnPacketReceive,(DWORD_PTR)this);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Set the ReceiveQueue property
HNAdapter.Set_ReceiveQueue(HNQueue.Get_Handle());
PoolMem_Label = PoolMem_Label + "= " + GetRate((DWORD)HNQueue.Get_AllocatedSize()) + " of memory";
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Set the HNQueue properties
HNQueue.Set_ItemsCount(100000);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 34 = sizeof(ETHERNET_HEADER) + sizeof(IP_HEADER)
// it's enough :)
HNQueue.Set_MaxPacketSize(sizeof(ETHERNET_HEADER) + sizeof(IP_HEADER));
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Init list of 駉unters
LVCOLUMN lvCol = {0};
lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_FMT;
lvCol.fmt = LVCFMT_LEFT;
lvCol.cx = 100;
lvCol.pszText = "Protocol";
CountersList.InsertColumn(0,&lvCol);
lvCol.fmt = LVCFMT_RIGHT;
lvCol.cx = 110;
lvCol.pszText = "Count";
CountersList.InsertColumn(1,&lvCol);
lvCol.cx = 100;
lvCol.pszText = "Size";
CountersList.InsertColumn(2,&lvCol);
lvCol.cx = 50;
lvCol.pszText = "%";
CountersList.InsertColumn(3,&lvCol);
lvCol.cx = 100;
lvCol.pszText = "Count speed";
CountersList.InsertColumn(4,&lvCol);
lvCol.pszText = "Size speed";
CountersList.InsertColumn(5,&lvCol);
int ItemIndex;
LVITEM lvItem = {0};
lvItem.mask = LVIF_TEXT;
// Total captured
lvItem.iItem = 0;
lvItem.iSubItem = 0;
lvItem.pszText = "Total captured";
ItemIndex = CountersList.InsertItem(&lvItem);
lvItem.iItem = ItemIndex;
lvItem.pszText = "0";
lvItem.iSubItem = 1; // count
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 2; // size
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 3; // %
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 4; // count speed
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 5; // size speed
CountersList.SetItem(&lvItem);
// Total processed
lvItem.iItem += 1;
lvItem.iSubItem = 0;
lvItem.pszText = "Total processed";
ItemIndex = CountersList.InsertItem(&lvItem);
lvItem.iItem = ItemIndex;
lvItem.pszText = "0";
lvItem.iSubItem = 1; // count
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 2; // size
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 3; // %
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 4; // count speed
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 5; // size speed
CountersList.SetItem(&lvItem);
// IP
lvItem.iItem += 1;
lvItem.iSubItem = 0;
lvItem.pszText = "IP";
ItemIndex = CountersList.InsertItem(&lvItem);
lvItem.iItem = ItemIndex;
lvItem.pszText = "0";
lvItem.iSubItem = 1; // count
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 2; // size
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 3; // %
CountersList.SetItem(&lvItem);
lvItem.pszText = "";
lvItem.iSubItem = 4; // count speed
CountersList.SetItem(&lvItem);
lvItem.iSubItem = 5; // size speed
CountersList.SetItem(&lvItem);
// TCP
lvItem.iItem += 1;
lvItem.iSubItem = 0;
lvItem.pszText = " TCP";
ItemIndex = CountersList.InsertItem(&lvItem);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -