FileterDlg.cpp
资源名称:ntpacket.zip [点击查看]
上传用户:qxsjcl
上传日期:2007-01-08
资源大小:263k
文件大小:6k
源码类别:
网络截获/分析
开发平台:
Visual C++
- // FileterDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "GetPacket.h"
- #include "FileterDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CFileterDlg dialog
- CFileterDlg::CFileterDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CFileterDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CFileterDlg)
- m_edit_sport = 0;
- m_edit_dport = 0;
- //}}AFX_DATA_INIT
- m_pSIPAddrCtl = NULL;
- m_pDIPAddrCtl = NULL;
- memset(m_sAddr, 0, 4);
- memset(m_dAddr, 0, 4);
- }
- void CFileterDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- if (NULL == m_pSIPAddrCtl)
- m_pSIPAddrCtl = (CIPAddrCtl*) GetDlgItem(IDC_IPSADDR);
- ASSERT(NULL != m_pSIPAddrCtl);
- if (NULL == m_pDIPAddrCtl)
- m_pDIPAddrCtl = (CIPAddrCtl*) GetDlgItem(IDC_IPDADDR);
- ASSERT(NULL != m_pDIPAddrCtl);
- //{{AFX_DATA_MAP(CFileterDlg)
- DDX_Control(pDX, ID_LIST_SPORT, m_list_sport);
- DDX_Control(pDX, ID_LIST_DPORT, m_list_dport);
- DDX_Control(pDX, ID_LIST_DIP, m_list_dip);
- DDX_Control(pDX, ID_LIST_SIP, m_list_sip);
- DDX_Text(pDX, ID_EDIT_SPORT, m_edit_sport);
- DDV_MinMaxInt(pDX, m_edit_sport, 0, 65535);
- DDX_Text(pDX, ID_EDIT_DPORT, m_edit_dport);
- DDV_MinMaxInt(pDX, m_edit_dport, 0, 65535);
- //}}AFX_DATA_MAP
- DDX_IPAddr(pDX, IDC_IPSADDR, m_sAddr);
- DDX_IPAddr(pDX, IDC_IPDADDR, m_dAddr);
- }
- BEGIN_MESSAGE_MAP(CFileterDlg, CDialog)
- //{{AFX_MSG_MAP(CFileterDlg)
- ON_BN_CLICKED(ID_BUTTON_SIP_ADD, OnButtonSipAdd)
- ON_BN_CLICKED(ID_BUTTON_DIP_ADD, OnButtonDipAdd)
- ON_BN_CLICKED(ID_BUTTON_SPORT_ADD, OnButtonSportAdd)
- ON_BN_CLICKED(ID_BUTTON_DPORT_ADD, OnButtonDportAdd)
- ON_BN_CLICKED(ID_BUTTON_DIP_DEL, OnButtonDipDel)
- ON_BN_CLICKED(ID_BUTTON_DPORT_DEL, OnButtonDportDel)
- ON_BN_CLICKED(ID_BUTTON_SIP_DEL, OnButtonSipDel)
- ON_BN_CLICKED(ID_BUTTON_SPORT_DEL, OnButtonSportDel)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFileterDlg message handlers
- BOOL CFileterDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- //initialize filters' listboxes
- int i;
- char buffer[64];
- CGetPacketApp *pApp;
- pApp=(CGetPacketApp*)AfxGetApp();
- for(i=0;i<pApp->SourceIP.GetSize();i++)
- m_list_sip.AddString(pApp->SourceIP.GetAt(i).GetBuffer(0));
- for(i=0;i<pApp->SourcePort.GetSize();i++)
- m_list_sport.AddString(_itoa( pApp->SourcePort.GetAt(i), buffer, 10 ));
- for(i=0;i<pApp->DestIP.GetSize();i++)
- m_list_dip.AddString(pApp->DestIP.GetAt(i).GetBuffer(0));
- for(i=0;i<pApp->DestPort.GetSize();i++)
- m_list_dport.AddString(_itoa( pApp->DestPort.GetAt(i), buffer, 10 ));
- return TRUE;
- }
- void CFileterDlg::OnOK()
- {
- char buffer[64];
- //clear filters
- CGetPacketApp *pApp;
- pApp=(CGetPacketApp*)AfxGetApp();
- pApp->SourceIP.RemoveAll();
- pApp->SourcePort.RemoveAll();
- pApp->DestIP.RemoveAll();
- pApp->DestPort.RemoveAll();
- //add new filters
- int i;
- for(i=0;i<m_list_sip.GetCount();i++)
- {
- m_list_sip.GetText(i,buffer);
- pApp->SourceIP.Add(buffer);
- }
- for(i=0;i<m_list_sport.GetCount();i++)
- {
- m_list_sport.GetText(i,buffer);
- pApp->SourcePort.Add(atoi(buffer));
- }
- for(i=0;i<m_list_dip.GetCount();i++)
- {
- m_list_dip.GetText(i,buffer);
- pApp->DestIP.Add(buffer);
- }
- for(i=0;i<m_list_dport.GetCount();i++)
- {
- m_list_dport.GetText(i,buffer);
- pApp->DestPort.Add(atoi(buffer));
- }
- CDialog::OnOK();
- }
- void CFileterDlg::OnButtonSipAdd()
- {
- if(!UpdateData(TRUE))
- return;
- if(m_sAddr[0]|m_sAddr[1]|m_sAddr[2]|m_sAddr[3])
- {
- int i;
- char buffer[64],text[64];
- wsprintf(buffer,"%hu.%hu.%hu.%hu ",m_sAddr[0],m_sAddr[1],m_sAddr[2],m_sAddr[3]);
- for(i=0;i<m_list_sip.GetCount();i++)
- {
- m_list_sip.GetText(i,text);
- if(!strcmp(text,buffer))
- {
- MessageBox("The entry already exists!","error",MB_OK);
- return;
- }
- }
- m_list_sip.AddString(buffer);
- }
- }
- void CFileterDlg::OnButtonDipAdd()
- {
- if(!UpdateData(TRUE))
- return;
- if(m_dAddr[0]|m_dAddr[1]|m_dAddr[2]|m_dAddr[3])
- {
- int i;
- char buffer[64],text[64];
- wsprintf(buffer,"%hu.%hu.%hu.%hu ",m_dAddr[0],m_dAddr[1],m_dAddr[2],m_dAddr[3]);
- for(i=0;i<m_list_dip.GetCount();i++)
- {
- m_list_dip.GetText(i,text);
- if(!strcmp(text,buffer))
- {
- MessageBox("The entry already exists!","error",MB_OK);
- return;
- }
- }
- m_list_dip.AddString(buffer);
- }
- }
- void CFileterDlg::OnButtonSportAdd()
- {
- if(!UpdateData(TRUE))
- return;
- int i;
- char buffer[64],text[64];
- _itoa( m_edit_sport, buffer, 10 );
- for(i=0;i<m_list_sport.GetCount();i++)
- {
- m_list_sport.GetText(i,text);
- if(!strcmp(buffer,text))
- {
- MessageBox("The entry already exists!","error",MB_OK);
- return;
- }
- }
- m_list_sport.AddString(buffer);
- }
- void CFileterDlg::OnButtonDportAdd()
- {
- if(!UpdateData(TRUE))
- return;
- int i;
- char buffer[64],text[64];
- _itoa( m_edit_dport, buffer, 10 );
- for(i=0;i<m_list_dport.GetCount();i++)
- {
- m_list_dport.GetText(i,text);
- if(!strcmp(buffer,text))
- {
- MessageBox("The entry already exists!","error",MB_OK);
- return;
- }
- }
- m_list_dport.AddString(buffer);
- }
- void CFileterDlg::OnButtonSipDel()
- {
- UINT index;
- if((index=m_list_sip.GetCurSel())==LB_ERR)
- return;
- m_list_sip.DeleteString(index);
- }
- void CFileterDlg::OnButtonDipDel()
- {
- UINT index;
- if((index=m_list_dip.GetCurSel())==LB_ERR)
- return;
- m_list_dip.DeleteString(index);
- }
- void CFileterDlg::OnButtonSportDel()
- {
- UINT index;
- if((index=m_list_sport.GetCurSel())==LB_ERR)
- return;
- m_list_sport.DeleteString(index);
- }
- void CFileterDlg::OnButtonDportDel()
- {
- UINT index;
- if((index=m_list_dport.GetCurSel())==LB_ERR)
- return;
- m_list_dport.DeleteString(index);
- }