Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Jul 2002 09:50:04 -0700
From:      "Chuck T." <freebsdfan@hotmail.com>
To:        ertr1013@student.uu.se
Cc:        net@freebsd.org
Subject:   Re: programatically list all local IP addresses ?
Message-ID:  <F94kDgGorXhnfwhRxFF00019560@hotmail.com>

next in thread | raw e-mail | index | archive | help
>Use gethostname()/gethostbyname() (or gethostbyaddr()) and then look
>through the 'h_addr_list' array in the 'struct hostent' returned by
>gethostbyname(). That should contain all the network addresses that
>were found for the given host.

That doesn't work when the lookup matches an entry in /etc/hosts, only
the *first* address is returned even if there are multiple entries.
That was my first attempt.

The machine that was returning 127.0.0.1 also had a valid (nonlocal)
IP address listed later in the file.  127.0.0.1 isn't very useful in
my application because it's sent to another host, not used locally.

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F94kDgGorXhnfwhRxFF00019560>