📄 dddialog.cpp
字号:
HNAdapter.Get_AsyncStatistics(stNdisMissed);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Refresh the user BPF filter statistics asynchronously
HNAdapter.Get_AsyncStatistics(stBpfReceive);
HNAdapter.Get_AsyncStatistics(stBpfAccept);
HNAdapter.Get_AsyncStatistics(stBpfReject);
HNAdapter.Get_AsyncStatistics(stBpfProcess);
}
else
{
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Refresh the adapter statistics synchronously
HNAdapter.UpdateAdapterStatistics();
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Refresh the user BPF filter statistics synchronously
HNAdapter.UpdateUserStatistics();
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Display the adapter statistics
#ifdef _WIN64
Stat.QuadPart = HNAdapter.Get_Missed();
#else
Stat.LowPart = HNAdapter.Get_Missed(&Stat.HighPart);
#endif
strNdisMissed.Format("%I64u",Stat.QuadPart);
#ifdef _WIN64
Stat.QuadPart = HNAdapter.Get_RecvWithErr();
#else
Stat.LowPart = HNAdapter.Get_RecvWithErr(&Stat.HighPart);
#endif
strNdisRecvWithErr.Format("%I64u",Stat.QuadPart);
#ifdef _WIN64
Stat.QuadPart = HNAdapter.Get_RecvWithoutErr();
#else
Stat.LowPart = HNAdapter.Get_RecvWithoutErr(&Stat.HighPart);
#endif
strNdisRecvWithoutErr.Format("%I64u",Stat.QuadPart);
#ifdef _WIN64
Stat.QuadPart = HNAdapter.Get_TranWithErr();
#else
Stat.LowPart = HNAdapter.Get_TranWithErr(&Stat.HighPart);
#endif
strNdisTranWithErr.Format("%I64u",Stat.QuadPart);
#ifdef _WIN64
Stat.QuadPart = HNAdapter.Get_TranWithoutErr();
#else
Stat.LowPart = HNAdapter.Get_TranWithoutErr(&Stat.HighPart);
#endif
strNdisTranWithoutErr.Format("%I64u",Stat.QuadPart);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Display the user BPF filter statistics
#ifdef _WIN64
Stat.QuadPart = HNAdapter.Get_AcceptCount();
#else
Stat.LowPart = HNAdapter.Get_AcceptCount(&Stat.HighPart);
#endif
strBpfAccept.Format("%I64u",Stat.QuadPart);
#ifdef _WIN64
Stat.QuadPart = HNAdapter.Get_ProcessCount();
#else
Stat.LowPart = HNAdapter.Get_ProcessCount(&Stat.HighPart);
#endif
strBpfProcess.Format("%I64u",Stat.QuadPart);
#ifdef _WIN64
Stat.QuadPart = HNAdapter.Get_RecvCount();
#else
Stat.LowPart = HNAdapter.Get_RecvCount(&Stat.HighPart);
#endif
strBpfReceive.Format("%I64u",Stat.QuadPart);
#ifdef _WIN64
Stat.QuadPart = HNAdapter.Get_RejectCount();
#else
Stat.LowPart = HNAdapter.Get_RejectCount(&Stat.HighPart);
#endif
strBpfReject.Format("%I64u",Stat.QuadPart);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Update the form data
UpdateData(false);
}
//---------------------------------------------------------------------------
// DefWindowProc - the handler for the dialog window messages
//---------------------------------------------------------------------------
LRESULT CDDDialog::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// A window message from the working packet is received.
// If the thread is stopped we stop intercepting the packets.
if(message == HN_WM_THREAD_EXIT)
{
Stop(); // Stop intercepting the packets
}
return CDialog::DefWindowProc(message, wParam, lParam);
}
//---------------------------------------------------------------------------
// OnDestroy - the handler for destroying the dialog
//---------------------------------------------------------------------------
void CDDDialog::OnDestroy()
{
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Stop receiving packets
OnCloseBtn();
CDialog::OnDestroy();
}
//---------------------------------------------------------------------------
// ClearCounters - clear counters
//---------------------------------------------------------------------------
void CDDDialog::ClearCounters()
{
dwOldCapTotal_Count = 0;
dwOldCapTotal_Bytes = 0;
dwCapTotal_Count = 0;
dwCapTotal_Bytes = 0;
dwOldPrTotal_Count = 0;
dwOldPrTotal_Bytes = 0;
dwPrTotal_Count = 0;
dwPrTotal_Bytes = 0;
dwIP_Count = 0;
dwIP_Bytes = 0;
dwTCP_Count = 0;
dwTCP_Bytes = 0;
dwUDP_Count = 0;
dwUDP_Bytes = 0;
dwARP_Count = 0;
dwARP_Bytes = 0;
dwICMP_Count = 0;
dwICMP_Bytes = 0;
dwOther_Count = 0;
dwOther_Bytes = 0;
ShowCounters();
}
//----------------------------------------------------------------------------------
// ShowCounters - show counters
//----------------------------------------------------------------------------------
void CDDDialog::ShowCounters()
{
DWORD dwlOldPrTotal_Count; // For process speed
DWORD dwlOldPrTotal_Bytes;
DWORD dwlPrTotal_Count;
DWORD dwlPrTotal_Bytes;
DWORD dwlOldCapTotal_Count; // For capture speed
DWORD dwlOldCapTotal_Bytes;
DWORD dwlCapTotal_Count;
DWORD dwlCapTotal_Bytes;
DWORD dwlIP_Count;
DWORD dwlIP_Bytes;
DWORD dwlTCP_Count;
DWORD dwlTCP_Bytes;
DWORD dwlUDP_Count;
DWORD dwlUDP_Bytes;
DWORD dwlARP_Count;
DWORD dwlARP_Bytes;
DWORD dwlICMP_Count;
DWORD dwlICMP_Bytes;
DWORD dwlOther_Count;
DWORD dwlOther_Bytes;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Save counters in local variables
dwlOldCapTotal_Count = dwOldCapTotal_Count;
dwlOldCapTotal_Bytes = dwOldCapTotal_Bytes;
dwlCapTotal_Count = dwCapTotal_Count;
dwlCapTotal_Bytes = dwCapTotal_Bytes;
dwlOldPrTotal_Count = dwOldPrTotal_Count;
dwlOldPrTotal_Bytes = dwOldPrTotal_Bytes;
dwlPrTotal_Count = dwPrTotal_Count;
dwlPrTotal_Bytes = dwPrTotal_Bytes;
dwlIP_Count = dwIP_Count;
dwlIP_Bytes = dwIP_Bytes;
dwlTCP_Count = dwTCP_Count;
dwlTCP_Bytes = dwTCP_Bytes;
dwlUDP_Count = dwUDP_Count;
dwlUDP_Bytes = dwUDP_Bytes;
dwlARP_Count = dwARP_Count;
dwlARP_Bytes = dwARP_Bytes;
dwlICMP_Count = dwICMP_Count;
dwlICMP_Bytes = dwICMP_Bytes;
dwlOther_Count = dwOther_Count;
dwlOther_Bytes = dwOther_Bytes;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Save current values of the Total counters as Old one-> Is used for
// capture and processing performance calculations
dwOldCapTotal_Count = dwlCapTotal_Count;
dwOldCapTotal_Bytes = dwlCapTotal_Bytes;
dwOldPrTotal_Count = dwlPrTotal_Count;
dwOldPrTotal_Bytes = dwlPrTotal_Bytes;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Total captured
CountersList.SetItemText(0,1,IntToStr(dwlCapTotal_Count));
CountersList.SetItemText(0,2,GetRate(dwlCapTotal_Bytes));
CountersList.SetItemText(0,3,"100 %");
CountersList.SetItemText(0,4,IntToStr(dwlCapTotal_Count - dwlOldCapTotal_Count," pkt/sec"));
GetRate(dwlCapTotal_Bytes - dwlOldCapTotal_Bytes);
Str += "/sec";
CountersList.SetItemText(0,5,Str);
// Total processed
CountersList.SetItemText(1,1,IntToStr(dwlPrTotal_Count));
CountersList.SetItemText(1,2,GetRate(dwlPrTotal_Bytes));
CountersList.SetItemText(1,3,"100 %");
CountersList.SetItemText(1,4,IntToStr(dwlPrTotal_Count - dwlOldPrTotal_Count," pkt/sec"));
GetRate(dwlPrTotal_Bytes - dwlOldPrTotal_Bytes);
Str += "/sec";
CountersList.SetItemText(1,5,Str);
if(!dwlPrTotal_Count) dwlPrTotal_Count = 1;
// IP
CountersList.SetItemText(2,1,IntToStr(dwlIP_Count));
CountersList.SetItemText(2,2,GetRate(dwlIP_Bytes));
CountersList.SetItemText(2,3,IntToStr((dwlIP_Count*100)/dwlPrTotal_Count," %"));
// TCP
CountersList.SetItemText(3,1,IntToStr(dwlTCP_Count));
CountersList.SetItemText(3,2,GetRate(dwlTCP_Bytes));
CountersList.SetItemText(3,3,IntToStr((dwlTCP_Count*100)/dwlPrTotal_Count," %"));
// UDP
CountersList.SetItemText(4,1,IntToStr(dwlUDP_Count));
CountersList.SetItemText(4,2,GetRate(dwlUDP_Bytes));
CountersList.SetItemText(4,3,IntToStr((dwlUDP_Count*100)/dwlPrTotal_Count," %"));
// ICMP
CountersList.SetItemText(5,1,IntToStr(dwlICMP_Count));
CountersList.SetItemText(5,2,GetRate(dwlICMP_Bytes));
CountersList.SetItemText(5,3,IntToStr((dwlICMP_Count*100)/dwlPrTotal_Count," %"));
// ARP
CountersList.SetItemText(6,1,IntToStr(dwlARP_Count));
CountersList.SetItemText(6,2,GetRate(dwlARP_Bytes));
CountersList.SetItemText(6,3,IntToStr((dwlARP_Count*100)/dwlPrTotal_Count," %"));
// Other
CountersList.SetItemText(7,1,IntToStr(dwlOther_Count));
CountersList.SetItemText(7,2,GetRate(dwlOther_Bytes));
CountersList.SetItemText(7,3,IntToStr((dwlOther_Count*100)/dwlPrTotal_Count," %"));
}
//-----------------------------------------------------------------------------
// ProcessPacket
//-----------------------------------------------------------------------------
void __stdcall CDDDialog::ProcessPacket(void* hPacket)
{
PETHERNET_HEADER pEth;
PIP_HEADER pIp;
DWORD IPPktLen;
DWORD IPDataLen;
DWORD PacketSize;
char *Pkt;
USHORT EthType;
CHNPacket HNPacket;
HNPacket = hPacket;
Pkt = (char*)HNPacket.Get_PacketData();
PacketSize = HNPacket.Get_PacketSize();
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// increase processed packets counters
dwPrTotal_Count = dwPrTotal_Count + 1;
dwPrTotal_Bytes = dwPrTotal_Bytes + PacketSize;
pEth = PETHERNET_HEADER(Pkt);
EthType = htons(pEth->EthType);
// ARP
if(EthType == ETHERTYPE_ARP)
{
dwARP_Count = dwARP_Count + 1;
dwARP_Bytes = dwARP_Bytes + (PacketSize - sizeof(ETHERNET_HEADER));
}
// IP
else if(EthType == ETHERTYPE_IP)
{
pIp = PIP_HEADER(&Pkt[sizeof(ETHERNET_HEADER)]);
IPPktLen = PacketSize - sizeof(ETHERNET_HEADER);
IPDataLen = IPPktLen - pIp->Len*sizeof(DWORD);
dwIP_Count = dwIP_Count + 1;
dwIP_Bytes = dwIP_Bytes + IPPktLen;
// TCP
if(pIp->Protocol == IPPROTO_TCP)
{
dwTCP_Count = dwTCP_Count + 1;
dwTCP_Bytes = dwTCP_Bytes + IPDataLen;
}
// UDP
else if(pIp->Protocol == IPPROTO_UDP)
{
dwUDP_Count = dwUDP_Count + 1;
dwUDP_Bytes = dwUDP_Bytes + IPDataLen;
}
// ICMP
else if(pIp->Protocol == IPPROTO_ICMP)
{
dwICMP_Count = dwICMP_Count + 1;
dwICMP_Bytes = dwICMP_Bytes + IPDataLen;
}
}
// Other
else
{
dwOther_Count = dwOther_Count + 1;
dwOther_Bytes = dwOther_Bytes + (PacketSize - sizeof(ETHERNET_HEADER));
}
}
//----------------------------------------------------------------------------------
// ClearPtkStat_BtnClick - clear counters
//----------------------------------------------------------------------------------
void CDDDialog::OnClearBtn()
{
ClearCounters();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -