• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Resolving Hostname :: MFC

kuphryn

Senior member
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
 
Back
Top