void Http::getIp(const char *domain, char*ip)
{
struct hostent *host = gethostbyname(domain);
if (host == NULL)
return;
for (int i = 0; host->h_addr_list[i]; i++)
{
strcpy(ip, inet_ntoa(*(struct in_addr*)host->h_addr_list[i]));
break;
}
}
gethostbyname()函数返回对应于给定主机名的hostent结构指针。
inet_ntoa()函数将一个32位网络字节序的二进制IP地址转换成相应的点分十进制的IP地址。