www.pudn.com > listen.zip > listenDlg.cpp, change:2005-03-16,size:17305b


// listenDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "listen.h" 
#include "listenDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CListenDlg dialog 
 
BOOL b_IsRun=FALSE; 
 
UINT RecvIpPro(LPVOID lpParam); 
char* GetIp(); 
CString GetNowTime(); 
BOOL CreateLogFile(char *strInfo,char *strFileName="log.txt"); 
BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg, 
						 WPARAM wParam,LPARAM lParam); 
 
CListenDlg::CListenDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CListenDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CListenDlg) 
	m_iWprot = 0; 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_IsAllPort=TRUE; 
	m_IsAllIp=TRUE; 
	m_IsAllProto=TRUE; 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CListenDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CListenDlg) 
	DDX_Control(pDX, IDC_LIST1, m_NewList); 
	DDX_Text(pDX, IDC_EDIT1, m_iWprot); 
	DDV_MinMaxInt(pDX, m_iWprot, 0, 10000); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CListenDlg, CDialog) 
	//{{AFX_MSG_MAP(CListenDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1) 
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3) 
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2) 
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3) 
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1) 
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4) 
	ON_BN_CLICKED(IDC_RADIO5, OnRadio5) 
	ON_BN_CLICKED(IDC_RADIO6, OnRadio6) 
	ON_BN_CLICKED(IDC_RADIO7, OnRadio7) 
	ON_BN_CLICKED(IDC_RADIO8, OnRadio8) 
	ON_COMMAND(ID_COPY_SIP, OnCopySip) 
	ON_COMMAND(ID_COPY_DIP, OnCopyDip) 
	ON_WM_SYSCOMMAND() 
	ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1) 
	ON_WM_DESTROY() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CListenDlg message handlers 
 
BOOL CListenDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// 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 
	if(!InitSock()) 
		return FALSE; 
	//添加系统菜单 
	CMenu *pMenu=GetSystemMenu(FALSE); 
	AppendMenu(pMenu->m_hMenu,MF_SEPARATOR,0,NULL); 
	AppendMenu(pMenu->m_hMenu,MF_STRING,IDM_SYSMENU,"关于..."); 
 
	//初始化控件 
	((CButton *)GetDlgItem(IDC_RADIO2))->SetCheck(TRUE); 
	((CButton *)GetDlgItem(IDC_RADIO1))->SetCheck(TRUE); 
	((CButton *)GetDlgItem(IDC_RADIO5))->SetCheck(TRUE); 
 
	//初始化临界区对象 
	InitializeCriticalSection(&m_ls); 
	//建立显示IP包窗口 
	m_IpShowDlg.Create(IDD_IPDATA,this); 
	m_IpShowDlg.ShowWindow(SW_SHOW); 
	CRect rect; 
	GetClientRect(&rect); 
//	ClientToScreen(&rect); 
	m_IpShowDlg.MoveWindow(10,265,rect.right-20,100); 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// 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. 
 
void CListenDlg::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. 
HCURSOR CListenDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CListenDlg::OnButton1()  
{ 
	// TODO: Add your control notification handler code here 
	CWinThread *pThread=NULL; 
	CButton* pBtn=(CButton *)GetDlgItem(IDC_BUTTON1); 
	int n=pBtn->GetCheck(); 
	m_HostIp=GetIp(); //得到本机IP 
	if(1==n) //开始监听 
	{ 
		if(CreateSock()!=0) //建立 
		{ 
			AfxMessageBox("WinSock设置失败"); 
			DestroyWindow(); 
		} 
		else 
		{ 
			b_IsRun=TRUE; 
			pThread=AfxBeginThread(RecvIpPro,this); 
		} 
		pBtn->SetWindowText("停止监听"); 
	} 
	else //停止监听 
	{ 
		b_IsRun=FALSE; 
		if(pThread) 
		{ 
			TerminateThread(pThread->m_hThread, 0); 
			CloseHandle(pThread->m_hThread); 
		} 
 
		if(m_RawSock) 
			closesocket(m_RawSock); 
		pBtn->SetWindowText("开始监听"); 
	} 
 
 
} 
//在线程冲中不断接受IP包 
UINT RecvIpPro(LPVOID lpParam) 
{ 
	int err=0; 
	int recvLen; 
	CListenDlg* pDlg=(CListenDlg*)lpParam; 
	char recvBuf[MAX_PACK_LEN]={0}; 
	while(b_IsRun) 
	{ 
		recvLen=recv(pDlg->m_RawSock,recvBuf,MAX_PACK_LEN,0);//接受数据 
		 
		if(err==SOCKET_ERROR) 
		{ 
			if(WSAGetLastError()==WSAEWOULDBLOCK) //如果错误为阻塞那么将继续接受 
				continue; 
			break; 
		} 
		//处理已经接受到的IP包 
		EnterCriticalSection(&pDlg->m_ls); 
		pDlg->SplitIpPack(recvBuf,recvLen); //分解IP包 
		pDlg->ShowIpInfo(recvBuf,recvLen); //显示数据 
		LeaveCriticalSection(&pDlg->m_ls); 
	} 
	return 0; 
 
} 
 
//加载SOCK 
BOOL CListenDlg::InitSock() 
{ 
	WSADATA wsaData; 
	int err; 
	if((err=WSAStartup(MAKEWORD(2,2),&wsaData))!=0) //加载失败 
		return FALSE; 
	if (LOBYTE(wsaData.wVersion)!=2 || HIBYTE(wsaData.wVersion) != 2)  
	{ 
		WSACleanup();//未能要求到所需的版本 
		return FALSE; 
	} 
	return TRUE; 
} 
 
//建立原始套接字 
int CListenDlg::CreateSock() 
{ 
	int err; 
	char name[10]; 
	hostent *pHostent; 
	int port=8310; 
	SOCKADDR_IN sockaddr; 
	m_RawSock=socket(AF_INET,SOCK_RAW,IPPROTO_IP); 
	if(m_RawSock==INVALID_SOCKET) 
	{ 
		return WSAGetLastError(); //socket创建失败 
	} 
	 
	err=gethostname(name,10); 
	if(err==SOCKET_ERROR) 
	{ 
		return WSAGetLastError(); //取本机用户名失败 
	} 
 
	pHostent=gethostbyname (name); 
 
	sockaddr.sin_family=AF_INET; 
	sockaddr.sin_port=htons(port); 
	memcpy(&sockaddr.sin_addr.s_addr,pHostent->h_addr_list[0], 
		pHostent->h_length); 
 
	//free(pHostent); 
	 
	err=bind(m_RawSock,(SOCKADDR *)&sockaddr,sizeof(sockaddr));//绑定 
	if(err==SOCKET_ERROR) 
	{ 
		return WSAGetLastError(); //取本机用户名失败 
	} 
	BOOL bOptval=TRUE; 
 
	//设置套节字选项 
	setsockopt(m_RawSock,SOL_SOCKET,SO_REUSEADDR,(char*)&bOptval,sizeof(bOptval)); 
	err=setsockopt(m_RawSock,IPPROTO_IP,IP_HDRINCL,(char*)&bOptval, //IP_HDRINCL该选项使之能操作IP头 
		sizeof(bOptval)); 
	if(err==SOCKET_ERROR) 
	{ 
		return WSAGetLastError(); //设置套节字选项失败 
	} 
 
	//把网卡置于混杂模式。获取IO操作的相关信息 
	DWORD dwBufferLen[10] ; 
	DWORD dwBufferInLen = 1 ; 
	DWORD dwBytesReturned = 0 ; 
	err=WSAIoctl ( 
		m_RawSock,                                                
		SIO_RCVALL,       //设置SOCK_RAW为SIO_RCVALL,以便接收所有的IP包                            
		&dwBufferInLen,                                      
		sizeof(dwBufferInLen),                                        
		&dwBufferLen,                                     
		sizeof(dwBufferLen),                                       
		&dwBytesReturned,                               
		NULL,                            
		NULL   
		);//最后两参数设置非阻塞 
 
 
	if(err==SOCKET_ERROR) 
	{ 
		return WSAGetLastError(); //设置套节字选项失败 
	} 
	return 0; 
} 
 
//分解IP包 
void CListenDlg::SplitIpPack(char *pData, int len) 
{ 
	IP_HEADER* pIpHead; 
	pIpHead=(IP_HEADER*)pData; //转为IP头结构 
	SOCKADDR_IN saSource,saDest; //中间变量分别为源IP地址结构和目标IP地址结构  
 
	//得到包中协议 
	int iProtocol; 
	iProtocol=pIpHead->proto; 
	//得到协议字符形式表示m_szProtocol 
	strncpy(m_szProtocol,CheckProtocol(iProtocol),MAX_PROTO_TEXT_LEN); 
 
 
	//得到源IP 
	saSource.sin_addr.s_addr=pIpHead->sourceIP; 
	strncpy(m_szSourceIP,inet_ntoa(saSource.sin_addr),MAX_ADDR_LEN); 
 
	//得到目标IP 
	saDest.sin_addr.s_addr=pIpHead->destIP; 
	strncpy(m_szDestIP,inet_ntoa(saDest.sin_addr),MAX_ADDR_LEN); 
 
	//得到TTL 
	int ttl; 
	ttl=pIpHead->ttl; 
	wsprintf(m_szTTL,"%d",ttl); 
 
	//得到头长度 
	int ihLen=sizeof(unsigned long)*(pIpHead->h_lenver & 0xf); 
 
	m_ihLen=ihLen; 
	unsigned short srcPort=0,destPort=0; 
	switch(iProtocol) { 
	case IPPROTO_TCP: 
		TCP_HEADER* pTcpHead; 
		pTcpHead=(TCP_HEADER*)(pData+ihLen); 
		srcPort=ntohs(pTcpHead->th_sport); 
		destPort=ntohs(pTcpHead->th_dport); 
		wsprintf(m_szSourcePort,"%d",srcPort); 
		wsprintf(m_szDestPort,"%d",destPort); 
		break; 
	case IPPROTO_UDP: 
		UDP_HEADER* pUdpHead; 
		pUdpHead=(UDP_HEADER*)(pData+ihLen); 
		srcPort=ntohs(pUdpHead->uh_sport); 
		destPort=ntohs(pUdpHead->uh_dport);	 
		wsprintf(m_szSourcePort,"%d",srcPort); 
		wsprintf(m_szDestPort,"%d",destPort); 
		break; 
	case IPPROTO_ICMP: 
		ICMP_HEADER* pIcmpHead; 
		pIcmpHead=(ICMP_HEADER*)(pData+ihLen); 
		wsprintf(m_szSourcePort,"%s",""); 
		wsprintf(m_szDestPort,"%s",""); 
		break; 
	default: 
		wsprintf(m_szSourcePort,"%s",""); 
		wsprintf(m_szDestPort,"%s",""); 
	} 
		 
} 
 
//将协议int转为字符串 
char* CListenDlg::CheckProtocol(int iProtocol) 
{ 
	for(int i=0; i<MAX_PROTO_NUM; i++) 
	{ 
		if(ProtoMap[i].ProtoNum==iProtocol) 
		{ 
			return ProtoMap[i].ProtoText; 
		} 
	} 
		return ""; 
} 
 
//得到本机IP 
char* GetIp() 
{ 
	WORD wVersionRequested; 
	WSADATA wsaData; 
	char name[255]; 
	char *ip; 
	PHOSTENT hostinfo; 
	wVersionRequested = MAKEWORD( 2, 0 ); 
	if ( WSAStartup( wVersionRequested, &wsaData ) == 0 ) 
	{ 
		 
		if( gethostname ( name, sizeof(name)) == 0) 
		{ 
			if((hostinfo = gethostbyname(name)) != NULL) 
			{ 
				ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list); 
			} 
		} 
		 
		WSACleanup( ); 
	}  
	return ip; 
} 
 
//得到当前时间 
CString GetNowTime() 
{ 
	CTime time; 
	CString str; 
	time = CTime::GetCurrentTime();	 
	str = time.Format("%Y-%m-%d %H:%M:%S"); 
	return str; 
} 
 
//写入文件 
BOOL CreateLogFile(char *strInfo,char *strFileName) 
{ 
	if (lstrlen(strInfo)<1) 
		return FALSE; 
	CFile file; 
	file.Open(strFileName,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate/*modeWrite|CFile::modeRead)*/);//CFile::modeNoTruncate为不截去以前的数据,追加新数据 
	file.SeekToEnd(); 
	CString temp; 
	char *pStrInfo; 
	temp=strInfo; 
	temp=temp+"\r\n"; 
	pStrInfo=temp.GetBuffer(temp.GetLength()); 
	file.Write(pStrInfo,::lstrlen(pStrInfo)); 
	file.Close(); 
	return TRUE; 
} 
 
//复制到剪贴板 
BOOL CListenDlg::SetClipboard(char* pData) 
{ 
//	pData="12345"; 
	if(::lstrlen(pData)<1) 
		return FALSE; 
	if(!::OpenClipboard(m_hWnd)) 
		return FALSE; 
	::EmptyClipboard(); 
	HANDLE hData=::GlobalAlloc(GHND|GMEM_SHARE,::lstrlen(pData)+1); //申请全局内存 
	char* pToData=(char*)::GlobalLock(hData); //得到该内存的指针,锁定改内存 
	::lstrcpy(pToData,pData); //将该字符串复制给该内存 
	::GlobalUnlock(hData); //解锁 
	::SetClipboardData(CF_TEXT,hData); 
	::CloseClipboard(); 
	return TRUE; 
} 
void CListenDlg::OnButton3()  
{ 
	// TODO: Add your control notification handler code here 
	DelListBuf(); //列表框清空 
 
} 
 
//将IP记录显示到ListBox 
void CListenDlg::ShowIpInfo(char *pData, int len) 
{ 
	if(len<0) 
		return; 
	CString str; 
	char szSourceIP[32]={0}; 
	char szDestIP[32]={0}; 
 
	char szSourcePort[16]={0}; //截取到的源端口 
	char szDestPort[16]={0}; //截取到的目标端口 
 
	char szSourceIPt[32]={0}; //截取到源IP 
	char szDestIPt[32]={0}; //截取到目标IP 
	 
	char szWprot[5]={0}; //取得输入端口 
	char szIP[32]={0}; //取得输入IP 
	char szProto[16]={0}; //取得输入协议 
	 
 
 
	if(strcmp(m_HostIp,m_szSourceIP)==0) 
	{ 
		strcat(szSourceIP,"(本机)"); 
		strcat(szSourceIP,m_szSourceIP); 
	} 
	else 
		strncpy(szSourceIP,m_szSourceIP,16); 
 
	if(strcmp(m_HostIp,m_szDestIP)==0) 
	{ 
		strcat(szDestIP,"(本机)"); 
		strcat(szDestIP,m_szDestIP); 
	} 
	else 
		strncpy(szDestIP,m_szDestIP,16); 
 
	strncpy(szSourcePort,m_szSourcePort,5); 
	strncpy(szDestPort,m_szDestPort,5); 
	strncpy(szDestIPt,m_szSourceIP,32); 
	strncpy(szSourceIPt,m_szDestIP,32); 
	strncpy(szProto,m_szProtocol,16); 
 
	wsprintf(szWprot,"%d",GetDlgItemInt(IDC_EDIT1)); 
	GetDlgItem(IDC_EDIT2)->GetWindowText(szIP,32); 
	 
	BOOL bProt=m_IsAllPort|(strcmp(szSourcePort,szWprot)==0)| 
		(strcmp(szDestPort,szWprot)==0); //判断端口规则 
	BOOL bIp=m_IsAllIp|(strcmp(szSourceIPt,szIP)==0)| 
		(strcmp(szDestIPt,szIP)==0); //判断IP规则 
	BOOL bProto=m_IsAllProto|(strcmp(szProto,m_szProto)==0); //判断协议规则 
	 
	if(bProt&&bIp&&bProto) 
	{ 
			CString sNowTime=GetNowTime(); 
			str.Format("[%s] %s:%s->%s:%s 包大小(头/总)%d/%d %s",m_szProtocol,szSourceIP, 
				m_szSourcePort,szDestIP,m_szDestPort,m_ihLen,len, 
				sNowTime.GetBuffer(sNowTime.GetLength())); 
			int nCount=((CListBox*)GetDlgItem(IDC_LIST1))->GetCount(); 
			if (nCount>=1000) 
				DelListBuf(); 
			//显示 
			((CListBox*)GetDlgItem(IDC_LIST1))->AddString(str); 
			//绑定数据 
			IPDATA* pIpData = new IPDATA; 
			pIpData->len = len; 
			pIpData->buf = new char[len]; 
			memcpy(pIpData->buf, pData, len); 
		 
			((CListBox*)GetDlgItem(IDC_LIST1))->SetItemData(nCount,(DWORD)pIpData); 
			((CListBox*)GetDlgItem(IDC_LIST1))->SetCaretIndex(nCount); 
			int nCheck=((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck(); 
			if(nCheck) 
				CreateLogFile(str.GetBuffer(/*str.GetLength()*/0)); 
	} 
} 
 
//端口过滤 
void CListenDlg::OnRadio2()  
{ 
	m_IsAllPort=TRUE; 
	GetDlgItem(IDC_EDIT1)->EnableWindow(FALSE); 
} 
 
void CListenDlg::OnRadio3()  
{ 
	m_IsAllPort=FALSE; 
	GetDlgItem(IDC_EDIT1)->EnableWindow(TRUE); 
} 
 
 
//IP过滤 
void CListenDlg::OnRadio1()  
{ 
	// TODO: Add your control notification handler code here 
	m_IsAllIp=TRUE; 
	GetDlgItem(IDC_EDIT2)->EnableWindow(FALSE); 
} 
 
void CListenDlg::OnRadio4()  
{ 
	// TODO: Add your control notification handler code here 
	m_IsAllIp=FALSE; 
	GetDlgItem(IDC_EDIT2)->EnableWindow(TRUE); 
} 
 
 
 
//文本框只允许输入数字 
BOOL CListenDlg::PreTranslateMessage(MSG* pMsg)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	if(WM_CHAR==pMsg->message) 
	{ 
		int nChar=(int)(pMsg->wParam); 
		if((nChar<48||nChar>57)&&(nChar!=8)) 
			return TRUE; 
	} 
	return CDialog::PreTranslateMessage(pMsg); 
} 
 
//协议过滤 
void CListenDlg::OnRadio6()  
{ 
	// TODO: Add your control notification handler code here 
	m_IsAllProto=FALSE; 
	strncpy(m_szProto,"TCP ",5); 
} 
void CListenDlg::OnRadio5()  
{ 
	// TODO: Add your control notification handler code here 
	m_IsAllProto=TRUE; 
} 
 
void CListenDlg::OnRadio7()  
{ 
	// TODO: Add your control notification handler code here 
	m_IsAllProto=FALSE; 
	strncpy(m_szProto,"UDP ",5); 
} 
 
 
void CListenDlg::OnRadio8()  
{ 
	// TODO: Add your control notification handler code here 
	m_IsAllProto=FALSE; 
	strncpy(m_szProto,"ICMP",5); 
} 
 
//复制源IP,右键菜单 
void CListenDlg::OnCopySip()  
{ 
	// TODO: Add your command handler code here 
	int n=m_NewList.GetCurSel(); 
	CString SelAllStr,sSIp,sDIp; 
	m_NewList.GetText(n,SelAllStr); 
	 
	//从得到CLIST中得到目标IP 
	int nBegin=SelAllStr.Find("] "); 
	int nEnd=SelAllStr.Find("->"); 
	sSIp=SelAllStr.Mid(nBegin+2,nEnd-nBegin-2); 
	TRACE(sSIp); 
 
	if('('==sSIp.GetAt(0)) 
	{ 
		nBegin=sSIp.Find(')'); 
		sSIp=sSIp.Mid(nBegin+1,sSIp.GetLength()); 
	} 
	 
//	AfxMessageBox(sSIp.GetAt(0)); 
	SetClipboard(sSIp.GetBuffer(sSIp.GetLength())); //拷入剪贴板 
 
	 
} 
 
//复制目标IP,右键菜单 
void CListenDlg::OnCopyDip()  
{ 
	// TODO: Add your command handler code here 
	int n=m_NewList.GetCurSel(); 
	CString SelAllStr,sSIp,sDIp; 
	m_NewList.GetText(n,SelAllStr); 
	 
	int nBegin=SelAllStr.Find('>'); 
	int nEnd=SelAllStr.Find("包"); 
	sDIp=SelAllStr.Mid(nBegin+1,nEnd-nBegin-2); 
	TRACE(sDIp); 
	 
	if('('==sDIp.GetAt(0)) 
	{ 
		nBegin=sDIp.Find(')'); 
		sDIp=sDIp.Mid(nBegin+1,sDIp.GetLength()); 
	} 
	//	AfxMessageBox(sDIp); 
	BOOL N=SetClipboard(sDIp.GetBuffer(sDIp.GetLength())); //拷入剪贴板 
 
} 
//关于 
void CListenDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
	if(IDM_SYSMENU==nID) 
		DialogBox(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDD_DIALOG1),m_hWnd,DialogProc); 
	CDialog::OnSysCommand (nID, lParam); 
} 
BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg, 
						 WPARAM wParam,LPARAM lParam) 
{ 
	if(uMsg==WM_COMMAND&&LOWORD(wParam)==IDCLOSE) 
	{ 
		EndDialog(hwndDlg,1); 
		return TRUE; 
	} 
	return FALSE; 
} 
 
void CListenDlg::OnSelchangeList1()  //选择列表 
{ 
	// TODO: Add your control notification handler code here 
	int n=m_NewList.GetCurSel(); 
	CString SelAllStr; 
	DWORD data=m_NewList.GetItemData(n); //得到绑定数据在m_IpShowDlg中显示 
	if (data<1) 
		return; 
	IPDATA* pIpData=(IPDATA*)data; 
	m_IpShowDlg.ShowIpData(pIpData->buf,pIpData->len); 
//	CreateLogFile(pIpData->buf); 
	//AfxMessageBox(SelAllStr); 
} 
 
//清除和ListBox绑定的数据和列表 
void CListenDlg::DelListBuf() 
{ 
	for(int i=0;i<m_NewList.GetCount();i++) 
	{ 
		DWORD data=m_NewList.GetItemData(i); 
			if (data>0) 
			{ 
				IPDATA* pData=(IPDATA*)data; 
				delete pData; //清除堆内存 
			} 
	} 
	m_IpShowDlg.m_CharEdit.SetWindowText(""); 
	m_IpShowDlg.m_HexEdit.SetWindowText(""); 
	m_IpShowDlg.m_NumEdit.SetWindowText(""); 
	m_NewList.ResetContent(); 
} 
 
//程序退出 
void CListenDlg::OnDestroy()  
{ 
	CDialog::OnDestroy(); 
	 
	// TODO: Add your message handler code here 
	DelListBuf(); 
	DeleteCriticalSection(&m_ls); 
}