views:

203

answers:

3

Hi All,

I am giving an IP Address : 64.78.58.91 and i would like to retrieve the hostname using GetHostByAddr() win32 API.

Instead of returning www.ripcode.com it returns intermedia.net

I would expect to get www.ripcode.com Can you suggest a Different API which could solve this problem.

Thanks in Advance

Best Regards, Suren

A: 

Absolutely! Use getaddrinfo() now, not gethostbyaddr().

http://beej.us/guide/bgnet/output/html/multipage/syscalls.html#getaddrinfo

Matt Ball
This is exactly opposite of what the question is asking for.
Mark Ransom
What is the question asking for, then? He's looking for a way to retrieve a hostname other than gethostbyaddr().
Matt Ball
getaddrinfo accepts a hostname and returns an IP address. The question is how to turn an IP address into a hostname.
Mark Ransom
GetAddrInfo never returned www.ripcode.com i have run the program available at :http://msdn.microsoft.com/en-us/library/ms738520(VS.85).aspx
getaddrinfo returned successgetaddrinfo response 1 Flags: 0x4 Family: AF_INET (IPv4) Socket type: SOCK_STREAM (stream) Protocol: IPPROTO_TCP (TCP) Length of this sockaddr: 16 Canonical name: (null)
But not the hostname as Mark Ransom correctly said which is what i intend to get from an IP Address
My apologies. It's been a few months since I've done any sockets programming, and I (incorrectly) recalled that getaddrinfo could go in either direction.
Matt Ball
+4  A: 

A few reasons why you might get this behavior:

  1. A PTR record was never set up for www.ripcode.com, so the address still appears to belong to intermedia.net (likely the hosting provider for www.ripcode.com).

  2. Multiple domains are hosted on that same IP address, but only one (intermedia.net) actually has a PTR record.

  3. There are multiple PTR records set up, but GetHostByAddr() is only giving you one of them.

Assuming that you own www.ripcode.com, and you have exclusive use of that IP address (it's not a shared hosting setup) you would want to contact your hosting provider and have them change the PTR record to reference your domain so reverse dns lookups will work properly.

This is especially important for sending e-mail. Many e-mail servers will do a reverse lookup on the IP of the sending server and check the domain against the domain sending the mail. If they don't match up, the message will often be rejected.

Eric Petroelje
+1  A: 

If the IP address belongs to a shared host, it will serve many different websites. This may be the best you can do.

The process is called Reverse DNS.

Mark Ransom