I am new. Hello!
I am trying to load in a text file that has IP addresses on each line. This should return to the screen the reverse lookup on each address.
What am I doing wrong? It compiles fine, but when I run it, it tells me the first address could not resolve, and then the second address shows "Host: " then hangs and gives a Windows error.
The IP's in question are ->
using namespace std;
if (WSAStartup(MAKEWORD(2,2), &wData) == SOCKET_ERROR)
cout << "Winsock init error\n";
hostent *h = NULL;
const char *ip;
while (! myfile.eof() )
ip = line.c_str();
unsigned int addr;
addr = inet_addr(ip);
h = gethostbyaddr(reinterpret_cast<char *>(&addr), 4, AF_INET);
if (h == NULL)
cout << "Could not resolve address" << endl;
cout << "Host: " << h->h_name << endl;