Map URL address to IP address
-
I am not sure if this question makes sense, but I am trying to write program to send email, all the socket functions take IP address as in 155.233.55.10 and not URL address as in www.microsoft.com, wonder if there are functions that map one to the other. Functions I am using are: connect,listen,bind,send,recv. Thanks,
-
I am not sure if this question makes sense, but I am trying to write program to send email, all the socket functions take IP address as in 155.233.55.10 and not URL address as in www.microsoft.com, wonder if there are functions that map one to the other. Functions I am using are: connect,listen,bind,send,recv. Thanks,
You first need to resolve the URL to corresponding IP address:
struct hostent * host = gethostbyname(name);
if ( host == NULL )
{
AfxMessageBox("gethostbyname() failed");
return;
}struct in_addr addr;
memcpy(&addr, host->h_addr_list[0], sizeof(addr));
sprintf(m_strHost,"%s", inet_ntoa(addr));
printf("Resolved Host is %s\n\n",m_strHost);