[NTLUG:Discuss] Bug in gethostbyaddr?

MadHat madhat at unspecific.com
Fri Mar 12 10:33:56 CST 2004


On Mar 12, 2004, at 9:57 AM, Neil Aggarwal wrote:
> Hello:
>
> I am trying to use gethostbyaddr to find the reverse DNS entry for
> the IP 216.234.230.2 but it gives me back a null result.
>
> When I do a dig on that IP, I get many results.  Is that throwing
> off gethostbyaddr?
>
> I have tried this on RedHat 9 and Fedora Core 1 and they both
> act the same.
>

Because by default gethostby uses UDP, but this data (which is so far 
off  from RFCs for PTR records) is so large, it has to use TCP to 
transfer the data.  The code you have uses the default UDP.  Check the 
mman pages for how to use TCP as the transport.  I am pretty sure, 
though I don't do much C lately), you need to use sethostent() to 
specify TCP before you make the gethostbyaddr.

If you do a host, you can see the error, as you can in dig.

$ host 216.234.230.2
;; Truncated, retrying in TCP mode.

$ dig -x 216.234.230.2
;; Truncated, retrying in TCP mode.




More information about the Discuss mailing list