gethostbyaddr Help Plz
Can someone give me an example of using gethostbyaddr to convert and IP to a hostname then display it in a messagebox.
I have done this to convert a hostname to an IP:
h = gethostbyname("modem-537.****covered_lol");
MessageBox(hWnd, inet_ntoa(*((struct in_addr *)h->h_addr)), "IP Address", NULL);
This works fine and converts the hostname to an IP.
But i cant work out how to do it the other way round, and convert an IP to a hostname.
Thanks in advance
Hm.. Might be wrong, but I dont think it works that way??
Create an in_addr struct to hold the IP address, send it to gethostbyaddr(), and save the pointer to the returned HOSTENT struct:
At this point, you have the hostname of the computer in the LPHOSTENT struct.
toBeResolved.s_addr = inet_addr("127.0.0.1");
hasBeenResolved = gethostbyaddr((const char *)&toBeResolved, sizeof(struct in_addr), AF_INET);