RuleDlg.cpp
上传用户:wlquartz
上传日期:2022-03-04
资源大小:89k
文件大小:3k
- // RuleDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "FirewallApp.h"
- #include "RuleDlg.h"
- #include "sockUtil.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CRuleDlg dialog
- CRuleDlg::CRuleDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CRuleDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CRuleDlg)
- m_ipsource = _T("0.0.0.0");
- m_portsource = 0;
- m_ipdestination = _T("0.0.0.0");
- m_portDestination = 0;
- m_action = _T("Tirar");
- m_protocol = _T("TCP");
- m_srcMask = _T("255.255.255.255");
- m_dstMask = _T("255.255.255.255");
- //}}AFX_DATA_INIT
- }
- void CRuleDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CRuleDlg)
- DDX_Text(pDX, IDC_EDIT1, m_ipsource);
- DDV_MaxChars(pDX, m_ipsource, 15);
- DDX_Text(pDX, IDC_EDIT2, m_portsource);
- DDX_Text(pDX, IDC_EDIT3, m_ipdestination);
- DDV_MaxChars(pDX, m_ipdestination, 15);
- DDX_Text(pDX, IDC_EDIT4, m_portDestination);
- DDX_CBString(pDX, IDC_COMBO3, m_action);
- DDX_CBString(pDX, IDC_COMBO4, m_protocol);
- DDX_Text(pDX, IDC_EDIT6, m_srcMask);
- DDV_MaxChars(pDX, m_srcMask, 15);
- DDX_Text(pDX, IDC_EDIT5, m_dstMask);
- DDV_MaxChars(pDX, m_dstMask, 15);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CRuleDlg, CDialog)
- //{{AFX_MSG_MAP(CRuleDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CRuleDlg message handlers
- void CRuleDlg::OnOK()
- {
- int result;
- UpdateData(TRUE);
- result = inet_addr(m_ipsource, &srcIp);
- if(result == -1)
- {
- AfxMessageBox("Source Ip isn't valid.");
- return;
- }
- result = inet_addr(m_srcMask, &srcMask);
- if(result == -1)
- {
- AfxMessageBox("Source Mask isn't valid.");
- return;
- }
- result = inet_addr(m_ipdestination, &dstIp);
- if(result == -1)
- {
- AfxMessageBox("Destination Ip isn't valid.");
- return;
- }
- result = inet_addr(m_dstMask, &dstMask);
- if(result == -1)
- {
- AfxMessageBox("Destination Mask isn't valid.");
- return;
- }
- if(m_protocol == "TCP")
- protocol = 6;
- else if(m_protocol == "UDP")
- protocol = 17;
- else if(m_protocol == "ICMP")
- protocol = 1;
- else
- protocol = 0;
- if(m_action == "")
- {
- AfxMessageBox("Select an Action, please");
- return;
- }
- else
- {
- if(m_action == "Forward")
- cAction = 0;
- else
- cAction = 1;
- }
- srcPort = m_portsource;
- dstPort = m_portDestination;
-
- CDialog::OnOK();
- }