#include <windows.h>
#include <winsock.h>
#include <stdio.h>
void main()
{
WSADATA wsaData;
char szHostname[100];
HOSTENT *pHostEnt;
int nAdapter = 0;
struct sockaddr_in sAddr;
if (WSAStartup(0x0101, &wsaData))
{
printf("WSAStartup failed %s/n", WSAGetLastError());
return;
}
pHostEnt = gethostbyname( "www.sina.com.cn");
while ( pHostEnt->h_addr_list[nAdapter] )
{
// pHostEnt->h_addr_list[nAdapter] is the current address in host
// order.
// Copy the address information from the pHostEnt to a sockaddr_in
// structure.
memcpy ( &sAddr.sin_addr.s_addr, pHostEnt->h_addr_list[nAdapter],
pHostEnt->h_length);
// Output the machines IP Address.
printf("Name: %s/nAddress: %s/n", pHostEnt->h_name,
inet_ntoa(sAddr.sin_addr));
nAdapter++;
}
WSACleanup();
return;
}
vc gethostbyname用法
最新推荐文章于 2016-12-27 09:34:15 发布