以下是引用TonyDeng在2012-10-9 21:03:07的发言:
先解决能不能运行的问题
先解决能不能运行的问题
不行啊 难道要下载VS2012?
点击后

梅尚程荀
马谭杨奚
程序代码:
#include <cstdio>
#include <WinSock2.h>
#include <conio.h>
#pragma comment(lib, "ws2_32.lib")
int main(int argc, char* argv[])
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0)
{
printf_s("WSAStartup failed with error: %d\n", err);
return 1;
}
if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
{
printf_s("Could not find a usable version of Winsock.dll\n");
WSACleanup();
return 1;
}
struct hostent *remoteHost;
struct in_addr addr;
remoteHost = gethostbyname(argv[1]);
printf_s("struct hostent:\n");
printf_s("\th_name: %s\n", remoteHost->h_name);
printf_s("\th_length: %d\n", remoteHost->h_length);
printf_s("\th_addrtype: %d\n", remoteHost->h_addrtype);
if (remoteHost->h_addrtype == AF_INET)
{
int i = 0;
while (remoteHost->h_addr_list[i] != 0)
{
addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++];
printf_s("IP Address #%d: %s, alias: %s\n", i, inet_ntoa(addr), remoteHost->h_aliases[i]);
}
}
WSACleanup();
_getch();
return 0;
}
