Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: Rick Jones <foo@bar.baz.invalid>
Subject: Re: gethostbyname returns only single IP address
Date: Fri, 23 Apr 2004 20:43:28 GMT	[thread overview]
Message-ID: <Qdfic.274$mw5.268@news.cpqcorp.net> (raw)
In-Reply-To: 5d1678ff.0404220743.37a2d7e1@posting.google.com

Calista <calista_heart@yahoo.com> wrote:
> I use gethostbyname() to get all the IP addresses on my machine. But
> it only returns the first one in /etc/hosts file.

> Should I do anything different?

I thought that when name resolution was accomplished via /etc/hosts
only one address was returned and it was only with DNS or whatnot that
one would get multiple IPs.

At least under HP-UX, the manpage for gethostbyname reads (in part):

    Nonserver Operation
      If the /etc/hosts file is used for name or address resolution, then
      the function:

           gethostent()           Reads the next line of /etc/hosts, opening
                                  the file if necessary.

           sethostent()           Opens and rewinds the file.  If the
                                  stayopen flag is non-zero, the host data
                                  base is not closed after each call to
                                  gethostent() (either directly or
                                  indirectly through one of the other
                                  gethost calls).

           endhostent()           Closes the file.

           gethostbyname()        Sequentially searches from the beginning
                                  of the file until a host name (among
                                  either the official names or the aliases)
                                  matching its name parameter is found, or
                                  until EOF is encountered.  Names are
                                  matched without respect to uppercase or
                                  lowercase, as described above in the name
                                  server case.

           gethostbyaddr()        Sequentially searches from the beginning
                                  of the file until an Internet address
                                  matching its addr parameter is found, or
                                  until EOF is encountered.

Which suggests that gethostbyname() stops after the first match. Now,
whether the Tru64 manpage says the same I don't know.

rick jones
-- 
Wisdom Teeth are impacted, people are affected by the effects of events.
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to raj in cup.hp.com  but NOT BOTH...


      parent reply	other threads:[~2004-04-23 20:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-22 15:43 gethostbyname returns only single IP address Calista
2004-04-23  1:42 ` Stuart Fuller
2004-04-23 13:04   ` Calista
2004-04-24  1:32     ` Peter da Silva
2004-04-26 14:05     ` Brian Haley
2004-04-26 20:54       ` Calista
2004-04-26 22:51         ` Brian Haley
2004-04-27 16:54           ` Calista
2004-04-27 20:36             ` Brian Haley
2004-05-03  3:15             ` Peter da Silva
2004-04-23 13:15   ` Calista
2004-04-23 20:43 ` Rick Jones [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox