Something I put together (minor changes from another source) a LONG time ago.
Compiles fine with VC++6.
strHost should be an IP address.
Code:
char * Resolve(const char *strHost)
{
char chAddress[32];
struct hostent *hinfo = NULL;
struct in_addr tempAddr;
if(strHost == NULL)
{
memset(chAddress, 0, 32);
gethostname(chAddress, 32);
hinfo = gethostbyname(chAddress);
if(hinfo == NULL)
{
return NULL;
}
}
else
{
hinfo = gethostbyname(strHost);
if(hinfo == NULL)
{
return NULL;
}
}
memcpy(&tempAddr, hinfo->h_addr_list[0], sizeof(struct in_addr));
return inet_ntoa(tempAddr);
}