So I guess gethostbyname is deprecated, and I am trying to be all polite, and trying to make a unicode compatible application with the new name resolution technique of getaddrinfo + getnameinfo. I end up with a dotted IP address representing the host, as a Unicode string. I do not know how to convert this to an IN_ADDR structure, inet_addr only takes ANSI strings.
Code:
ADDRINFOT * addr = { 0 };
TCHAR * host = _T("www.yahoo.com");
TCHAR hostBuffer[256];
int ret = ::GetAddrInfo(host, 0, 0, &addr);
if(ret)
{
ErrorMessage(_T("GetAddrInfo: %d"), ::WSAGetLastError());
}
if(addr)
{
::GetNameInfo
(addr->ai_addr, sizeof sockaddr,
hostBuffer, sizeof hostBuffer,
0, 0, NI_NUMERICHOST);
// unsigned long ip = inet_addr(hostBuffer); //
// how how how how how how how how //
}
::FreeAddrInfo(addr);