3
如何使用Windows API将主机名(例如'myhost')转换为类型IPAddr
。 IPAddr
是一个无符号长整数。将主机名转换为IPAddr
如何使用Windows API将主机名(例如'myhost')转换为类型IPAddr
。 IPAddr
是一个无符号长整数。将主机名转换为IPAddr
试一下这个(编辑):
hostent * record = gethostbyname(argv[1]);
if(record == NULL)
{
printf("%s is unavailable\n", argv[1]);
exit(1);
}
in_addr * address = (in_addr *)record->h_addr;
string ip_address = inet_ntoa(* address);
IPAddr dst_ip = ::inet_addr(ip_address.c_str());
是的,这让我一个IP地址字符串,而不是IPADDR(unsigned long类型)。你可以更新你的答案,添加以下行:'IPAddr dst_ip = :: inet_addr(ip_address.c_str());' – Blazes 2011-05-26 14:33:46
@Blazes:补充,谢谢:) – Marco 2011-05-26 14:48:58