-
Notifications
You must be signed in to change notification settings - Fork 0
/
CONNECTD.CPP
101 lines (85 loc) · 2.35 KB
/
CONNECTD.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// connectd.cpp : implementation file
//
#include "stdafx.h"
#include "wsterm.h"
#include "connectd.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
// .INI File Section and entries
static const char szSection[] = "ConnectInfo";
static const char szHostName[] = "HostName";
static const char szPort[] = "Port";
/////////////////////////////////////////////////////////////////////////////
// CConnectDialog dialog
CConnectDialog::CConnectDialog(CWnd* pParent /*=NULL*/)
: CDialog(CConnectDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CConnectDialog)
m_strHostName = "";
m_strPort = "";
//}}AFX_DATA_INIT
}
void CConnectDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConnectDialog)
DDX_Text(pDX, IDC_HOSTNAME, m_strHostName);
DDX_CBString(pDX, IDC_PORT, m_strPort);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CConnectDialog, CDialog)
//{{AFX_MSG_MAP(CConnectDialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConnectDialog message handlers
BOOL CConnectDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// Restore previous selections
m_strHostName = AfxGetApp()->GetProfileString(szSection,
szHostName);
m_strPort = AfxGetApp()->GetProfileString(szSection,
szPort);
UpdateData(FALSE);
return TRUE;
}
// Convert m_strPort and
// store in m_nPort in HOST order
void CConnectDialog::OnOK()
{
// Service entry structure
LPSERVENT pServEntry;
UpdateData(TRUE);
m_nPort = atoi(m_strPort);
// Is it already a number?
if (m_nPort == 0)
{
// Use WinSock database routine
// for service resolution
// First, make copy and
// convert to lower case
CString strCopy(m_strPort);
strCopy.MakeLower();
pServEntry = getservbyname(strCopy, "tcp");
if (pServEntry == NULL)
{
AfxMessageBox("Unknown service name");
return;
}
// Port already in network order
// Socket classes assume we will
// use host order, so we convert
m_nPort = ntohs(pServEntry->s_port);
}
// Save entries to .ini for next use
AfxGetApp()->WriteProfileString(szSection,
szHostName,
m_strHostName);
AfxGetApp()->WriteProfileString(szSection,
szPort,
m_strPort);
CDialog::OnOK();
}