Hi.
I am working on a simple program that resolves hostname. Here is the concept:
Enter hostname: www.google.com
Resolve IP: 216.239.33.101
The program has a dialog box for the user to enter the hostname such as (www.google.com or www.yahoo.com).
Here is the function that does it:
-----
void CDomainDNS::resolveHost(const CString &rHName)
{
WSAData wData;
if (WSAStartup(MAKEWORD(2,2), &wData) == SOCKET_ERROR)
{
CString error;
error.Format("Error initialization Winsock");
AfxMessageBox(error);
return;
}
hostent *host = 0;
host = gethostbyname(rHName);
if (host == 0)
mVeri = false;
else
{
mIP = inet_ntoa(*(reinterpret_cast(host->h_addr)));
mVeri = true;
}
}
-----
The code above works perfect under Win32 *console*. However, it only outputs my *internal* ip in MFC application mode.
For example:
Enter hostname: www.google.com
Resolve IP: 192.168.0.1
Is there something I need to change or add when dealing with the code above in Win32 MFC environment? Maybe there is a better tool for resolve hostname via MFC?
Thanks,
Kuphryn