From: calista_heart@yahoo.com (Calista)
Subject: Re: gethostbyname returns only single IP address
Date: 26 Apr 2004 13:54:47 -0700 [thread overview]
Message-ID: <5d1678ff.0404261254.5405fb4e@posting.google.com> (raw)
In-Reply-To: gG8jc.345$kV.256@news.cpqcorp.net
Brian Haley <Brian.Haley@nospam_hp.com> wrote in message news:<gG8jc.345$kV.256@news.cpqcorp.net>...
> I'm not sure gethostbyname() will return what you're looking for.
>
> You said the system has two interfaces with two IP addresses, I'm
> assuming each has a name associated with it, for example:
>
> 10.0.0.1 foo # address on ee0
> 11.0.0.1 bar # address on ee1
>
> If I do a gethostbyname("foo") I would only expect to get one IP address
> back - the one for foo, the address for bar would not be returned.
>
> The preferred way to get all the local IP address information is to use
> ioctl(SIOCGIFCONF, ...).
>
> Have you tried this on a similarly configured system running a different
> OS, maybe Linux? Or a different Tru64 version? Is the behavior the same?
>
> -Brian
Yes Brian, I have tried the program on Linux, and there it prints both
of the IP addresses. It doesn't print both on Tru64 though. I suspect
the problem is with how the system is configured, but I have no idea
where\what to look for.
Calista.
>
>
> Calista wrote:
> > hostname is passed to this function.
> >
> > if ((hp = gethostbyname(hostname)) <= (struct hostent *)0
> > return -1;
> >
> > for( i = 0; i < 4; i++ ) { /* I can have max 4 ip addresses */
> > if( hp->h_addr_list[i] == NULL )
> > break;
> > memzero (&sin, sizeof(sin));
> > memcpy (hp->h_addr_list[i], &sin.sin_addr, hp->h_length);
> > sin.sin_family = hp->h_addrtype;
> > /* Get IP address. */
> > strncpy( ipaddress[i], inet_ntoa(sin.sin_addr), length );
> > /* take care of NULL character at end in ipaddress[i] */
> > }
> >
> > Now I print all IP addresses. It prints only one IP address although my
> > machine has multiple interfaces (two ip addresses).
> >
> > Let me know if you need more info.
> >
> > Calista.
next prev parent reply other threads:[~2004-04-26 20:54 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 [this message]
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
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