南邮 通达 软件设计 实验报告
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2011 / 2012 2
Socket
090037
09003711
,,, 2012 6 21
IP (2)
1 (2)
2 (2)
3 (2)
4 (3)
5 (3)
6 (5)
(5)
1 (5)
2 (5)
3 (5)
4 (6)
5 (7)
6 (12)
UDP (12)
1 (12)
2 (12)
3 (12)
4 (13)
5 (13)
6 (15)
(16)
1 (16)
2 (16)
3 (16)
4 (18)
5 (20)
6 (27)
(28)
1 (28)
2 (28)
3 (28)
4 (31)
5 (31)
6 (34)
(34)
(34)
IP
1
IP
2
IP
3
1.
MFC AppWizard[exe]”,
09003711A
,
windows sockets
2. ResourceView
Dialog
IDD_MY09003711A_DIALOG ,
static
Edit
Push Button
1.1
1.1
1.1
1.1ID
3.
Message Maps
Class Name
CMy09003711ADlg
OnGetIP
1.2
5. 09003711ADlg.app"winsock.h " , "wsipx.h ",
"wsnwlink.h ","iphlpapi.h "
6.
7. ---------/IPHLPAPI.LIB
4
1.2
DNS192.168.0.1
5
int CMy09003711ADlg::GetHostName(CString& sHostName)
{ char szHostName[256];
int nRetCode;
nRetCode = gethostname(szHostName, sizeof(szHostName));
if (nRetCode != 0) {
sHostName = _T("Not available");;
return WSAGetLastError(); }
sHostName = szHostName;
return 0; }
int CMy09003711ADlg::GetIPAddress(const CString& sHostName, CString& sIPAddress)
{ struct hostent FAR *lpHostEnt = gethostbyname (sHostName);
if (lpHostEnt == NULL) {
sIPAddress = _T("");
return WSAGetLastError(); }
LPSTR lpAddr = lpHostEnt->h_addr_list[0];
if (lpAddr) {
struct in_addr inAddr;
memmove (&inAddr, lpAddr, 4);
sIPAddress = inet_ntoa (inAddr);
if (sIPAddress.IsEmpty())
sIPAddress = _T("Not available"); }
return 0; }
void CMy09003711ADlg::GetGateWay_SubNet()
{ if (pinfo!=NULL)
delete (pinfo);
unsigned long nError;
pinfo= (PIP_ADAPTER_INFO)malloc(len);
nError = GetAdaptersInfo(pinfo,&len);
if (nError==0)
{ if (pinfo!=NULL)
{ PIP_ADDR_STRING pAddressList = &(pinfo->IpAddressList);
do
{ pAddressList = pAddressList->Next;
} while (pAddressList != NULL);
m_sSubnetMask.Format("%s",pinfo->IpAddressList.IpMask.String);
m_sGateWay.Format("%s",pinfo->GatewayList.IpAddress.String);} } } void CMy09003711ADlg::GetDNS()
{ FixedInfo=(FIXED_INFO*)GlobalAlloc(GPTR,sizeof( FIXED_INFO ) );
len = sizeof( FIXED_INFO );
if( ERROR_BUFFER_OVERFLOW==GetNetworkParams( FixedInfo, &len ) ) { GlobalFree( FixedInfo );
FixedInfo = (FIXED_INFO *) GlobalAlloc( GPTR, len ); } GetNetworkParams( FixedInfo, &len );
m_sDNS.Format("%s",FixedInfo -> DnsServerList.IpAddress.String); }
void CMy09003711ADlg::OnGetIP()
{ int nRetCode;
nRetCode = StartUp();
TRACE1("StartUp RetCode: %d\n", nRetCode);