[Info-vax] Which name is returned by the gethostbyaddr(<IP address>) in the hostent h_name field

glen herrmannsfeldt gah at ugcs.caltech.edu
Fri Jul 22 10:03:00 EDT 2011


jbriggs444 <jbriggs444 at gmail.com> wrote:
> On Jul 22, 2:59 am, Andy <andrew... at gmail.com> wrote:

>> I have not had much experience with IP programming. I have some
>> software that uses the gethostbyaddr(<IP address>) hostent h_name
>> field to do some checking.
(snip)

> It is a routine that attempts to return the host name that corresponds
> to the IP address provided by the caller.

(snip)
> So the lookup from IP address to host name could come from, for
> instance:

> 1. The hosts file (or VMS host name table)
> 2. DNS (with specifiable servers)
> 3. WINS
> 4. Yellow Pages/NIS

On systems I use, it is configured to use DNS, or DNS first.

In that case, it returns the PTR record, traditionally there is
supposed to only be one, from the DNS server.  To protect against
fake (forged) PTR entries, some servers then do a forward
(gethostbyname) lookup on the name returned, and verify that the
original address is one of the addresses for the specified name.

> In my experience, the host name that is returned has nothing
> whatsoever to do with the host name that is configured into the
> machine at the target IP address -- the routine does not reach
> out into the network and ask the target machine for its canonical
> host name.

Among others, gethostbyaddr should return the fully qualified
name, where gethostname usually doesn't.

> Of course, folks usually try to maintain some consistency in these
> matters -- so that reverse DNS is the mirror image of forward DNS,
> hosts files match DNS databases match internally configured host
> names, etc.

It is usual to put only one PTR entry per address, for hosts that 
have more than one name.  

-- glen



More information about the Info-vax mailing list