Click here to Skip to main content
15,885,435 members
Articles / Desktop Programming / MFC

Cryptest (MFC Style Crypto++ v4.2 Library GUI).

Rate me:
Please Sign up or sign in to vote.
4.62/5 (16 votes)
6 Jan 2002CPOL3 min read 237.4K   2.7K   91  
A GUI version of the Crypto++ v4.2 Library that was written by Wei Dai.
// TCPForwarding.cpp : implementation file
//

#include "stdafx.h"
#include "Cryptest.h"
#include "TCPForwarding.h"

#include <winsock2.h>

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

/////////////////////////////////////////////////////////////////////////////
// CTCPForwarding dialog


CTCPForwarding::CTCPForwarding(CWnd* pParent /*=NULL*/)
	: CDialog(CTCPForwarding::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTCPForwarding)
	m_csDestPort = _T("378");
	m_csSourceHost = _T("This Computer!");
	m_csSourcePort = _T("111");
	//}}AFX_DATA_INIT
}


void CTCPForwarding::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTCPForwarding)
	DDX_Control(pDX, LIST_SOCKETS, m_lcSockets);
	DDX_Control(pDX, IPA_DESTINATION_HOST, m_ipaDestination);
	DDX_Text(pDX, EDT_DESTINATION_PORT, m_csDestPort);
	DDX_Text(pDX, EDT_SOURCE_HOST, m_csSourceHost);
	DDX_Text(pDX, EDT_SOURCE_PORT, m_csSourcePort);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTCPForwarding, CDialog)
	//{{AFX_MSG_MAP(CTCPForwarding)
	ON_WM_CLOSE()
	ON_BN_CLICKED(BTN_EXIT, OnExit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTCPForwarding message handlers

BOOL CTCPForwarding::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CCryptestApp* pcCryptest = (CCryptestApp*) AfxGetApp();
	
	// Setup the column headings
	CRect rect;
	m_lcSockets.GetClientRect(&rect);

	// Setup the list control
	ListView_SetExtendedListViewStyle(m_lcSockets.m_hWnd, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
		
	m_lcSockets.InsertColumn( 0, _T("Socket Stuff..."), LVCFMT_LEFT, rect.Width());

	pcCryptest->m_lcSockets = &m_lcSockets;

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTCPForwarding::OnOK() 
{
	CCryptestApp* pcCryptest = (CCryptestApp*) AfxGetApp();

	CString csDestHost = _T("");
	csDestHost = IPCtrlToSTR(&m_ipaDestination);

	if (!csDestHost.IsEmpty())
		pcCryptest->ForwardTcpPort(m_csSourcePort, csDestHost, m_csDestPort);
	else
	{
		MessageBox(_T("You MUST have a valid IP Address!"));
		m_ipaDestination.SetFocus();
	}
}

void CTCPForwarding::OnCancel() 
{
	//CDialog::OnCancel();
}

void CTCPForwarding::OnClose() 
{
	CDialog::OnOK();
}

void CTCPForwarding::OnExit() 
{
	CDialog::OnOK();
}

CString CTCPForwarding::IPCtrlToSTR(CIPAddressCtrl* ctrl)
{
	//Converts the control address to textual address
	//Convert bytes to string
	BYTE bOctet1;
	BYTE bOctet2;
	BYTE bOctet3;
	BYTE bOctet4;

	//Get the value and blank values
	int iBlank;
	iBlank=ctrl->GetAddress(bOctet1,bOctet2,bOctet3,bOctet4);

	if (iBlank!=4)
		//Not filled
		return _T("");
	else
	{
		in_addr iAddr;
		iAddr.S_un.S_un_b.s_b1=bOctet1;
		iAddr.S_un.S_un_b.s_b2=bOctet2;
		iAddr.S_un.S_un_b.s_b3=bOctet3;
		iAddr.S_un.S_un_b.s_b4=bOctet4;

		return (CString)inet_ntoa(iAddr);
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager
Germany Germany
I have been programming (as a hobby) for 20+ years (Unix C, Scripting, VB, C/C++, C#). I am getting too old to talk about it and been in the Security line of work (both Military/Civilian) for 25+ years.

Comments and Discussions