gethostbyname 函数已经过时,怎么由getaddrinfo替换
1个回答
展开全部
之前使用gethostbyname 很简单,类似这样:
struct hostent *remoteHost;
struct in_addr addr;
if ( ( remoteHost = gethostbyname( hostname ) ) == NULL ){
xxxx;
}
else{
if (remoteHost->h_addrtype == AF_INET)
{
while (remoteHost->h_addr_list[i] != 0) {
addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++];
printf("\tIP Address #%d: %s\n", i, inet_ntoa(addr));
}
}
}
struct hostent *remoteHost;
struct in_addr addr;
if ( ( remoteHost = gethostbyname( hostname ) ) == NULL ){
xxxx;
}
else{
if (remoteHost->h_addrtype == AF_INET)
{
while (remoteHost->h_addr_list[i] != 0) {
addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++];
printf("\tIP Address #%d: %s\n", i, inet_ntoa(addr));
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询