-
大小:文件類型: .cpp金幣: 1下載: 0 次發(fā)布日期: 2021-05-11
- 語(yǔ)言: C/C++
- 標(biāo)簽:
資源簡(jiǎn)介
windows網(wǎng)絡(luò)編程課程設(shè)計(jì)源代碼
代碼片段和文件信息
//?getIp.cpp?:?定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//
//?winPrgrmSkts.cpp?:?Defines?the?entry?point?for?the?application.
#include?“stdafx.h“
#include
#include
#include
#include
#pragma?comment(lib“ws2_32.lib“)
int?main(int?argcchar?**argv){
//聲明和初始化變量
WSADATA?wsaData;
int?iResult;
DWORD?dwError;
int?i=0;
struct?hostent?*remoteHost;
char?*host_name;
struct?in_addr?addr;
char?**pAlias;
//驗(yàn)證參數(shù)的合法性
if(argc?!=2){
?printf(“usage:GetHostIp?hostname:\n“);
?return?1;
}//if(argc?!=2)
//初始化windows?socket
iResult?=?WSAStartup(MAKEWORD(22)&wsaData);
if(iResult?!=0?){
printf(“WSAStartup?failed:%d\n“iResult);
return?1;
}//if(iResult?!=0?){}
host_name?=?argv[1];
//host_name=“www.google.com“;
printf(“Calling?gethostname?with?%s\n?“host_name);
????remoteHost?=?gethostbyname(host_name);
//對(duì)返回結(jié)果進(jìn)行判斷
if(remoteHost==NULL){
dwError?=?WSAGetLastError();
??if(dwError?!=0){
????if(dwError?==?WSAHOST_NOT_FOUND){
printf(“Host?not?found\n“);
return?1;
}else?if(dwError==WSANO_DATA){
printf(“No?data?record?found\n“);
return?1;
}else?{
printf(“Function?failed?with?error:%d\n“dwError);
return?1;
}
}//if(dwError?!=0)
}//if(remoteHost==NULL)
- 上一篇:c++ 最小二乘算法擬合球心 使用Vs2008
- 下一篇:編譯原理 電梯程序
評(píng)論
共有 條評(píng)論