How do I convert from a hostname (eg 'myhost') to a type of IPAddr
using Windows API. IPAddr
is an unsigned long.
Try this ( edited ):
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() );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.