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.....
#include <iostream>
using namespace std;
#include <winsock2.h>
bool InitializeWinsock()
{
WSADATA wsa;
if( WSAStartup( MAKEWORD(2, 2), &wsa) != 0 )
return false;
return true;
}
int main()
{
InitializeWinsock();
char* ip = "216.239.51.101"; // 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...
else
cout << h->h_name << endl;
// How to get aliases now?
// This where I am stuck!
return 0;
}
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.