I'm trying to write a function to do a DNS lookup which takes an IP address and finds the hostname corresponding to the IP as well as the ALIASES associated with this IP address since a single IP address may be associated with multiple domain names.
I have reached as far as getting the hostname associated with the IP address but I have been unable to retrieve any aliases associated with this IP address.
The code I have written so far is.....
using namespace std;
if( WSAStartup( MAKEWORD(2, 2), &wsa) != 0 )
char* ip = "22.214.171.124"; // google
// Convert IP to long.....
unsigned int x = inet_addr(ip);
if(x == INADDR_NONE)
cout << "Cannot resolve IP address!" << endl;
// Resolve IP address to hostname...
hostent* h = gethostbyaddr( (const char*)&x, sizeof(x), AF_INET);
if(h == NULL)
cout << "Failed to get hostname!" << endl;
// Print the hostname...
cout << h->h_name << endl;
// How to get aliases now?
// This where I am stuck!
I'm not sure that "www.google.com" has any aliases associated with it but even if you choose a site that has an alias I still don't know how to retrieve that alias. If anyone knows how to get the aliases associated with an IP please help.