-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConnectInfo.cpp
124 lines (91 loc) · 3.13 KB
/
ConnectInfo.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/********************************************************************************
Gnucleus - An Application for the Gnutella Network
Copyright (C) 2000-2005 John Marshall Group
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
By contributing code you grant John Marshall Group an unlimited, non-exclusive
license to your contribution.
For support, questions, commercial use, etc...
E-Mail: swabby@c0re.net
********************************************************************************/
#include "stdafx.h"
#include "Gnucleus.h"
#include "GnucleusDoc.h"
#include "ConnectInfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CConnectInfo::CConnectInfo(CWnd* pParent /*=NULL*/, CGnucleusDoc* pDoc)
: CDialog(CConnectInfo::IDD, pParent)
{
m_pDoc = pDoc;
hAsync = 0;
//{{AFX_DATA_INIT(CConnectInfo)
//}}AFX_DATA_INIT
}
CConnectInfo::~CConnectInfo()
{
if(hAsync)
::WSACancelAsyncRequest(hAsync);
}
void CConnectInfo::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConnectInfo)
DDX_Control(pDX, IDC_EDIT_HOSTNAME, m_ebHostName);
DDX_Control(pDX, IDC_EDIT_HOST, m_ebHost);
DDX_Control(pDX, IDC_STATIC_TIME, m_stcTime);
DDX_Control(pDX, IDC_EDIT_HANDSHAKE, m_ebHandshake);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CConnectInfo, CDialog)
//{{AFX_MSG_MAP(CConnectInfo)
ON_MESSAGE(CONNECT_INFO, OnAsyncGetHostByAddr)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CConnectInfo::OnInitDialog()
{
CDialog::OnInitDialog();
m_Handshake.Replace("\n\n", "\r\n\r\n");
m_ebHost.SetWindowText(m_Host + ":" + DWrdtoStr(m_Port));
CString ConnectTime = m_Time.Format("%I:%M%p %d%b");
ConnectTime.MakeUpper();
m_stcTime.SetWindowText(ConnectTime);
m_ebHandshake.SetWindowText(m_Handshake);
//Makslane: start asynchronous host name resolving
IP HostIP = StrtoIP(m_Host);
hAsync = ::WSAAsyncGetHostByAddr(m_hWnd,
CONNECT_INFO,
(char*) &HostIP.S_addr,
sizeof(HostIP.S_addr),
PF_INET,
bufHost,
MAXGETHOSTSTRUCT);
if(hAsync)
m_ebHostName.SetWindowText(_T("Resolving host name..."));
else
m_ebHostName.SetWindowText(m_Host);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
LRESULT CConnectInfo::OnAsyncGetHostByAddr(WPARAM wParam, LPARAM lParam)
{
hAsync = 0;
int nWSAError = WSAGETASYNCERROR(lParam);
if(!nWSAError)
m_ebHostName.SetWindowText(((LPHOSTENT)bufHost)->h_name);
else
m_ebHostName.SetWindowText("Could not resolve host");
return NULL;
}