Click to See Complete Forum and Search --> : gethostbyaddr, loopback, 11004 error!


Ajay Vijay
August 21st, 2009, 07:05 AM
I need to check if the given IP address belongs to current computer or not.

I wrote code that converts IP address to host name, and compare it with GetComputerName's result.

All works fine including standard 127.0.0.1 loopback.

But for other loopback (127.*.*.*) it returns 11004, which means address is correct but data is unavailable.

How does tool like ping, tracert work? For isntance if I enter:
> tracert/ping 127.20.21.22

it perfectly works and points to localhost/127.0.0.1/machinename.

rjbez
August 24th, 2009, 01:58 PM
I'm sorry I can't help you, but I had a very similar problem when I was calling GetHostByName(). I had a usb device connected (the device was setup to be a network adapter) and when I would call gethostbyname I would receive the same error as you. I spent almost two weeks trying to figure out why it would not work. I never figured it out, I just used Bonjour and used DNSServiceResolve() to get the IP address. I am interested in finding out why this error gets returned, I assumed ws2_32.dll was just not working properly because it is a windows DLL. I have heard of many people having problems with the GetHostByName/GetHostByAddr.

On MSDN they suggest GetNameInfo:

http://msdn.microsoft.com/en-us/library/ms738532(VS.85).aspx

instead of gethostbyaddr. Try and see if that will help you out.

hoxsiew
August 24th, 2009, 02:46 PM
Technically, a computer should have only one loopback interface and it should have only one address. The 127.x.x.x/8 paradigm is an historical quirk that goes back to the original DARPANET specification which only allowed 8 bit addresses. 127 was the loopback address. When addresses were expanded to 32 bits (almost immediately), 127.x.x.x/8 became the loopback space but wastes an entire class-A network needlessly. Conversely, IPV6 has only one single address for loopback.

I guess what it boils down to is that 127.0.0.0/8 addresses other than 127.0.0.1 are technically undefined. It's up to you how you implement it.

Ajay Vijay
August 25th, 2009, 05:26 AM
Thanks rjbez! I was aware of getnameinfo function, but I've been avoiding it for long. I will give it a shot soon!

hoxsiew, I agree with your point. But in that case if user enters IP address like 127.0.0.27, I would display some error. And I am doing the same.
Just curious how other utilities detect the same?

hoxsiew
August 25th, 2009, 08:51 AM
hoxsiew, I agree with your point. But in that case if user enters IP address like 127.0.0.27, I would display some error. And I am doing the same.
Just curious how other utilities detect the same?

I would guess that they just look for that pattern (127.x.x.x) and handle it differently.