⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ip.cpp

📁 lwip tcp/ip 协议栈 adsp BF533 DSP 移植 用 visual dsp++ 编译
💻 CPP
字号:
// IP.cpp : implementation file
//

#include "stdafx.h"
#include "TCPIPplugin.h"
#include "IP.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// Used to enable or disable Network Interface -1 property page.
extern bool g_EnableNI1Page;

// If any property is changed the value will be set to true.
// used in classwizplugin.cpp if user presses ok. 
//
extern bool g_save;
/////////////////////////////////////////////////////////////////////////////
// IP property page

IMPLEMENT_DYNCREATE(IP, CPropertyPage)

IP::IP() : CPropertyPage(IP::IDD)
{
	//{{AFX_DATA_INIT(IP)
		// NOTE: the ClassWizard will add member initialization here
	 m_ip_forward = false;
	 m_ip_options = false;
	 m_ip_fragmentation = false;
	 m_ip_reassembly = false;

	 m_multiple_networks = true;
	 m_num_networks = 1;
	 g_EnableNI1Page = false;

	//}}AFX_DATA_INIT	
}

IP::~IP()
{
}

void IP::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(IP)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP

	PopulateIPSettings();
}


BEGIN_MESSAGE_MAP(IP, CPropertyPage)
	//{{AFX_MSG_MAP(IP)
	ON_BN_CLICKED(IDC_CHECK_IP_FORWARD, OnCheckIpForward)
	ON_BN_CLICKED(IDC_CHECK_IP_OPTIONS, OnCheckIpOptions)
	ON_BN_CLICKED(IDC_CHECK_IP_FRAG, OnCheckIpFrag)
	ON_BN_CLICKED(IDC_CHECK_REASSEMBLY, OnCheckReassembly)
	ON_BN_CLICKED(IDC_CHECK_IP_MULNETWORK, OnCheckIpMulnetwork)
	ON_EN_CHANGE(IDC_EDIT_NO_NETWORKS, OnChangeEditNoNetworks)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// IP message handlers

void IP::OnCheckIpForward() 
{
	CButton *pButton_IpFeature= (CButton*)GetDlgItem(IDC_CHECK_IP_FORWARD);
	bool o_ip_forward = m_ip_forward;

	if(pButton_IpFeature != NULL)
		(pButton_IpFeature->GetCheck() == BST_CHECKED) ? m_ip_forward = true : m_ip_forward = false;	

	(o_ip_forward != m_ip_forward) ? g_save = true : 0;
}

void IP::OnCheckIpOptions() 
{
	CButton *pButton_IpFeature= (CButton*)GetDlgItem(IDC_CHECK_IP_OPTIONS);
	bool o_ip_options = m_ip_options;

	if(pButton_IpFeature != NULL)
		(pButton_IpFeature->GetCheck() == BST_CHECKED) ? m_ip_options = true : m_ip_options = false;	

	(o_ip_options != m_ip_options) ? g_save = true : 0;
	
}

void IP::OnCheckIpFrag() 
{
	CButton *pButton_IpFeature= (CButton*)GetDlgItem(IDC_CHECK_IP_FRAG);
	bool o_ip_fragmentation = m_ip_fragmentation;

	if(pButton_IpFeature != NULL)
		(pButton_IpFeature->GetCheck() == BST_CHECKED) ? m_ip_fragmentation = true : m_ip_fragmentation = false;	

	(o_ip_fragmentation != m_ip_fragmentation) ? g_save = true : 0;
}

void IP::OnCheckReassembly() 
{
	CButton *pButton_IpFeature= (CButton*)GetDlgItem(IDC_CHECK_REASSEMBLY);
	bool o_ip_reassembly = m_ip_reassembly;

	if(pButton_IpFeature != NULL)
		(pButton_IpFeature->GetCheck() == BST_CHECKED) ? m_ip_reassembly = true : m_ip_reassembly = false;	

	(o_ip_reassembly != m_ip_reassembly) ? g_save = true : 0;
}

void IP::OnCheckIpMulnetwork() 
{
	char tbuf[80];
	CButton *pButton_IpFeature= (CButton*)GetDlgItem(IDC_CHECK_IP_MULNETWORK);
	bool o_multiple_networks= m_multiple_networks;

	if(pButton_IpFeature != NULL)
	{
		if(pButton_IpFeature->GetCheck() == BST_CHECKED)
		{
			CEdit *pEdit_NumNetworks = (CEdit*)GetDlgItem(IDC_EDIT_NO_NETWORKS);
			pEdit_NumNetworks->GetWindowText(tbuf,sizeof(tbuf));
			pEdit_NumNetworks->EnableWindow(TRUE);
			int NumNetworks  = atoi(tbuf);
			m_multiple_networks = true;
			if(NumNetworks == 2)
				g_EnableNI1Page = true;
			else if (NumNetworks > 2)
			{
				g_EnableNI1Page = true;
				int res = AfxMessageBox("UI supports only two interfaces, Manually configure the rest",MB_ICONEXCLAMATION | MB_ICONWARNING | MB_OK);
			}

		}
		else
		{
			CEdit *pEdit_NumNetworks = (CEdit*)GetDlgItem(IDC_EDIT_NO_NETWORKS);
			pEdit_NumNetworks->EnableWindow(FALSE);
		
			m_multiple_networks = false;
			g_EnableNI1Page = false;
			m_num_networks = 1;
		}
		(o_multiple_networks != m_multiple_networks) ? g_save = true : 0;
	}

}

void IP::InitDefaultIPSettings()
{
	 m_ip_forward = false;
	 m_ip_options = false;
	 m_ip_fragmentation = false;
	 m_ip_reassembly = false;

	 m_multiple_networks = false;
	 m_num_networks = 1;
}

void IP::OnChangeEditNoNetworks() 
{
	CEdit *pEdit_NumNetworks = (CEdit*)GetDlgItem(IDC_EDIT_NO_NETWORKS);
	char temp_buf_arr[80];
	char *end_ptr;
	int o_num_networks = m_num_networks;

	if(pEdit_NumNetworks  != NULL)
	{
		pEdit_NumNetworks->GetWindowText(temp_buf_arr,80);
		m_num_networks = strtol(temp_buf_arr,&end_ptr,10);
		if(m_num_networks == 0)
		{
			MessageBox("Invalid Number of Networks","IP",MB_OK);
			pEdit_NumNetworks->SetFocus();
		}
		else if (m_num_networks >= 2)
		{
			g_EnableNI1Page = true;
		}
		(o_num_networks != m_num_networks) ? g_save = true : 0;
	}
	
}

void IP::PopulateIPSettings()
{
	// make sure that we are using our resources
	CEdit *pEdit_IP = (CEdit*)GetDlgItem(IDC_EDIT_NO_NETWORKS);
	char temp_buf_arr[80];
	CButton *pButton_IpFeature= (CButton*)GetDlgItem(IDC_CHECK_IP_MULNETWORK);

#if 0
	(m_multiple_networks == true) ? pButton_IpFeature->SetCheck(TRUE) : pButton_IpFeature->SetCheck(FALSE);

	if(m_multiple_networks == true) 
		g_EnableNI1Page = true;
	else
		g_EnableNI1Page = false;
#endif
	
	// Setup Num Networks
	//
	if(pEdit_IP != NULL)
	{
		sprintf(temp_buf_arr,"%d",m_num_networks);
		pEdit_IP->SetWindowText(temp_buf_arr);
		//(m_multiple_networks == true) ? pEdit_IP->EnableWindow(TRUE) : pEdit_IP->EnableWindow(FALSE);
		pEdit_IP->EnableWindow(TRUE);
	}
	if(m_num_networks > 1)
		g_EnableNI1Page = true;
	else
		g_EnableNI1Page = false;

	
	pButton_IpFeature= (CButton*)GetDlgItem(IDC_CHECK_IP_FORWARD);
	(m_ip_forward == true) ? pButton_IpFeature->SetCheck(TRUE) : pButton_IpFeature->SetCheck(FALSE);
	
	pButton_IpFeature= (CButton*)GetDlgItem(IDC_CHECK_IP_OPTIONS);
	(m_ip_options == true) ? pButton_IpFeature->SetCheck(TRUE) : pButton_IpFeature->SetCheck(FALSE);

	pButton_IpFeature= (CButton*)GetDlgItem(IDC_CHECK_IP_FRAG);
	(m_ip_fragmentation == true) ? pButton_IpFeature->SetCheck(TRUE) : pButton_IpFeature->SetCheck(FALSE);

	pButton_IpFeature= (CButton*)GetDlgItem(IDC_CHECK_REASSEMBLY);
	(m_ip_reassembly == true) ? pButton_IpFeature->SetCheck(TRUE) : pButton_IpFeature->SetCheck(FALSE);

}

bool IP::StoreIPHeaderData(ConfigHeaderStruct *cfg_header)
{

	cfg_header->ip_forward = m_ip_forward;
	cfg_header->ip_fragmentation = m_ip_fragmentation;
	cfg_header->ip_options = m_ip_options;
	cfg_header->ip_reassembly = m_ip_reassembly;
	cfg_header->multiple_networks = m_multiple_networks;
	cfg_header->num_networks = m_num_networks;

	return true;
}

bool IP::LoadIPHeaderData(ConfigHeaderStruct *cfg_header)
{
	m_ip_forward	    = cfg_header->ip_forward;
	m_ip_fragmentation  = cfg_header->ip_fragmentation;
	m_ip_options	    = cfg_header->ip_options;
	m_ip_reassembly     = cfg_header->ip_reassembly;
	m_multiple_networks = cfg_header->multiple_networks;
	m_num_networks      = cfg_header->num_networks;
	return true;
}

void IP::OnCancel() 
{
	CPropertyPage::OnCancel();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -