www.pudn.com > zhuabao.rar > Send.cpp


// Send.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "packetreplay.h" 
#include "Send.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CSend dialog 
 
 
CSend::CSend(CWnd* pParent /*=NULL*/) 
	: CDialog(CSend::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CSend) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	alldevs=NULL; 
	d=NULL; 
	adhandle=NULL; 
	m_nPacketNum=0; 
} 
 
 
void CSend::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CSend) 
	DDX_Control(pDX, IDC_SHOW, m_show); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CSend, CDialog) 
	//{{AFX_MSG_MAP(CSend) 
	ON_BN_CLICKED(IDC_START, OnStart) 
	ON_BN_CLICKED(IDC_STOP, OnStop) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CSend message handlers 
 
void CSend::OnCancel()  
{ 
	// TODO: Add extra cleanup here 
	CDialog::OnCancel(); 
	CDialog::DestroyWindow(); 
 
} 
 
void CSend::OnStart()  
{ 
	// TODO: Add your control notification handler code here 
	m_pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd; 
	m_pComboBox=m_pFrame->GetComboBox() ;//获取组合框的指针 
	int index=m_pComboBox->GetCurSel(); //获得组合框的选择 
	if(index==CB_ERR || index==0) 
	{ 
		MessageBox("请你先选择一个网卡."); 
		return; 
	} 
	m_show.SetWindowText("开始发送数据......."); 
 
	pcap_findalldevs(&alldevs,errbuf); 
	d=alldevs; 
	for(int i=0;inext; 
 
	//打开设备  
	adhandle=pcap_open_live(d->name, //网络设备名 
		65535, //数据包的捕获部分长度 
		1, //混合模式 1 打开混合模式 0关闭混合模式 
		1000,//读超时值 
		errbuf);//错误信息缓存区 
	if(adhandle==NULL) 
	{ 
		MessageBox("错误%s",errbuf); 
		pcap_freealldevs(alldevs); 
	} 
 
	CStdioFile f; 
	CFileException e; 
	CString str,s; 
	char buf[2]; 
	u_char *packet; 
	if(f.Open("PACKET.log", CFile::modeRead, &e )) 
	{ 
		f.SeekToBegin(); 
		f.ReadString(str); 
		f.ReadString(str); 
		f.ReadString(str); 
		int PacketNum=strtol(str,NULL,10); 
		//str.Format("%d",PacketNum); 
		//MessageBox(str); 
		 
		for(int i=0;i