How to resolve IP address to computer name
Posted on 2001-08-07
Using Windows 2000, Visual C++ 6.0.
I need a RELIABLE way to find the computer name that corresponds to a given IP address. So far, I have tried gethostbyaddr from the WinSock API, like this.
char *p = "10.10.191.51";
pHostInfo = gethostbyaddr(p, strlen(p), AF_INET);
From this, I get error 11004, which is "The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for."
Am I calling the function incorrectly? It so happens that the address I'm trying to resolve is specified in my hosts file, not on the name server. Does that matter? I still need something that works in the scenario.
If I run "ping /a 10.10.191.51" in a cmd window, it is able to lookup the computer name correctly. If necessary, I will launch the ping command from within my program and parse the output, but that is an undesireable solution and I will not accept it as the answer.