www.pudn.com > firewallpapisrc.rar > RuleDlg.cpp
/*
Name: RuleDlg.cpp
Copyright: Jesús Oliva
Author: Jesús Oliva (jeoliva@telefonica.net)
Date: 25/09/03 20:19
*/
// 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("0.0.0.0");
m_dstMask = _T("0.0.0.0");
//}}AFX_DATA_INIT
defaultAction = PF_ACTION_FORWARD;
}
void CRuleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRuleDlg)
DDX_Control(pDX, IDC_COMBO3, m_actionCombo);
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 Address isn't valid.");
return;
}
if(srcIp == 0)
srcMask = 0;
else
{
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 Address isn't valid.");
return;
}
if(dstIp == 0)
dstMask = 0;
else
{
result = inet_addr(m_dstMask, &dstMask);
if(result == -1)
{
AfxMessageBox("Destination Mask isn't valid.");
return;
}
}
srcPort = m_portsource;
dstPort = m_portDestination;
if(m_protocol == "TCP")
protocol = 6;
else if(m_protocol == "UDP")
protocol = 17;
else if(m_protocol == "ICMP")
{
protocol = 1;
if(srcPort == 0x00)
srcPort = 0xff;
if(dstPort == 0x00)
dstPort = 0xff;
}
else
protocol = 0;
if(m_action == "")
{
AfxMessageBox("Select an action, please");
return;
}
else
{
if(m_action == "Forward")
cAction = 0;
else
cAction = 1;
}
CDialog::OnOK();
}
BOOL CRuleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if(defaultAction == PF_ACTION_DROP)
m_actionCombo.AddString("Forward");
else
m_actionCombo.AddString("Drop");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}