www.pudn.com > HTTP协议分析器开发源码.rar > PageDlg3.cpp
// PageDlg3.cpp : implementation file
//
#include "stdafx.h"
#include "BPON.h"
#include "PageDlg3.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define Max_Num_Adapter 10
static char AdapterList[Max_Num_Adapter][512];
/////////////////////////////////////////////////////////////////////////////
// CPageDlg3 property page
IMPLEMENT_DYNCREATE(CPageDlg3, CPropertyPage)
CPageDlg3::CPageDlg3() : CPropertyPage(CPageDlg3::IDD)
{
//{{AFX_DATA_INIT(CPageDlg3)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CPageDlg3::~CPageDlg3()
{
}
void CPageDlg3::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPageDlg3)
DDX_Control(pDX, IDC_LISTA, m_lis);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPageDlg3, CPropertyPage)
//{{AFX_MSG_MAP(CPageDlg3)
ON_BN_CLICKED(IDOK, OnSniff)
ON_BN_CLICKED(IDC_LIST, OnList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPageDlg3 message handlers
int CPageDlg3::OnSniff()
{
//define a pointer to an ADAPTER structure
LPADAPTER lpAdapter = 0;
DWORD dwErrorCode;
int i=m_lis.GetCurSel();
// AfxMessageBox(AdapterList[i]);
lpAdapter = PacketOpenAdapter(AdapterList[i]);
if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE))
{
dwErrorCode=GetLastError();
AfxMessageBox("Unable to open the driver");//dwErrorCode
return -1;
}
//begin listening
CBPOParaClass::Sniff_INFO* pInfo = new (CBPOParaClass::Sniff_INFO);
CBPOThread* pThread=new CBPOThread("GOOD");
pInfo->pThread = pThread;
pInfo->ipAdapter = lpAdapter;
CWinThread* SniffT=NULL;
CString szShowInfo;
if(SniffT=AfxBeginThread(pThread->StartSniff,pInfo,THREAD_PRIORITY_NORMAL,
0,CREATE_SUSPENDED,NULL))
{
// nThreadCount++;
// szShowInfo="开始捕获网络包\r\n";
// pEditView1->SendMessage(WM_SHOWINFO,0,(LPARAM)(LPCTSTR)szShowInfo);
TRACE("开始捕获网络包\r\n");
SniffT->ResumeThread();
}
//listener = (HANDLE)_beginthread(SniffThread, 0, (void*) lpAdapter);
// wait a little while for listener thread
Sleep(500);
// WaitForSingleObject(SniffT, INFINITE);
// close the adapter and exit
// PacketCloseAdapter(lpAdapter);
delete pInfo;
delete pThread;
TRACE("Main Thread Stoped!\r\n");
return (0);
}
void CPageDlg3::OnList()
{
int i;
DWORD dwVersion;
DWORD dwWindowsMajorVersion;
//unicode strings (winnt)
// WCHAR AdapterName[8192]; // string that contains a list of the network adapters
// WCHAR *temp,*temp1;
//ascii strings (win95)
char AdapterNamea[8192]; // string that contains a list of the network adapters
char *tempa,*temp1a;
int AdapterNum=0;
ULONG AdapterLength;
// obtain the name of the adapters installed on this machine
AdapterLength=4096;
m_lis.AddString("packet 版本号----"+CString(PacketGetVersion()));
//AfxMessageBox(PacketGetVersion());
i=0;
// the data returned by PacketGetAdapterNames is different in Win95 and in WinNT.
// We have to check the os on which we are running
dwVersion=GetVersion();
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
/* if (!(dwVersion >= 0x80000000 && dwWindowsMajorVersion >= 4))
{ // Windows NT
if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE){
AfxMessageBox("Unable to retrieve the list of the adapters!");
return;
}
temp=AdapterName;
temp1=AdapterName;
while ((*temp!='\0')||(*(temp-1)!='\0'))
{
if (*temp=='\0')
{
memcpy(AdapterList[i],temp1,(temp-temp1)*2);
temp1=temp+1;
i++;
}
temp++;
}
AdapterNum=i;
for (i=0;i