Convert hostname to IPAddr

How can I convert from a host name (for example, "myhost") to a type IPAddrusing the Windows API. IPAddris unsigned length.

+3
source share
1 answer

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() );
+4
source

All Articles