【发布时间】:2013-11-30 04:11:47
【问题描述】:
我在 windows xp 上收到错误“过程入口点 inet_ntop 无法位于动态链接库 WS2_32.dll 中”,经过一番谷歌搜索后,我发现 inet_ntop 在 XP 中不可用,所以我制作了一个宏请改用 inet_ntoa。但它似乎没有工作,我仍然得到同样的错误......我错过了什么吗?
char *get_ip(char *host)
{
struct hostent *hent;
int iplen = 39;
long errorcode;
char *ip = (char *)malloc(iplen + 1);
memset(ip, 0, iplen + 1);
if ((hent = gethostbyname(host)) == NULL)
{
perror("Could not get the IP address");
exit(1);
}
#if (_WIN32_WINNT >= 0x600)
if (inet_ntop(AF_INET, (void *)hent->h_addr_list[0], ip, iplen) == NULL)
{
perror("Could not resolve the host");
exit(1);
}
#else
ip = inet_ntoa(*((struct in_addr *)hent->h_addr_list[0]));
if (ip == NULL)
{
perror("Could not resolve the host");
exit(1);
}
#endif
return ip;
}
【问题讨论】:
标签: c windows windows-xp