From owner-freebsd-net Thu Jul 18 8: 2:52 2002 Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9E7A037B401 for ; Thu, 18 Jul 2002 08:02:48 -0700 (PDT) Received: from mail.emergecore.com (mail.emergecore.com [216.190.54.2]) by mx1.FreeBSD.org (Postfix) with SMTP id 7D6B643E3B for ; Thu, 18 Jul 2002 08:02:47 -0700 (PDT) (envelope-from bjones@emergecore.com) Received: (qmail 61649 invoked by uid 1007); 18 Jul 2002 15:04:12 -0000 Received: from bjones@emergecore.com by mail.emergecore.com by uid 1004 with qmail-scanner-1.12 (uvscan: v4.1.60/v4171. . Clear:. Processed in 0.732576 secs); 18 Jul 2002 15:04:12 -0000 Received: from unknown (HELO emergecore.com) (192.168.1.93) by 0 with SMTP; 18 Jul 2002 15:04:11 -0000 Message-ID: <3D36D820.4070707@emergecore.com> Date: Thu, 18 Jul 2002 09:00:48 -0600 From: Bruce Jones User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020408 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Erik Trulsson Cc: "Chuck T." , net@FreeBSD.ORG Subject: Re: programatically list all local IP addresses ? References: <20020718145129.GA39189@falcon.midgard.homeip.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org Erik Trulsson wrote: > On Thu, Jul 18, 2002 at 07:27:08AM -0700, Chuck T. wrote: > >>I'm sure this is a FAQ, but I sure can't find the answer. I've tried the >>usually suggested gethostname()/gethostbyname() approach, but that only >>returns the *first* match in /etc/hosts. In one case that was 127.0.0.1. >>Clearly this was a case where /etc/host.conf gave priority to the host file. > > > 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. > > Another possibility is of course to run 'ifconfig -a' and then parse > the output to find out what IP-addresses are configured on the machine. > > do a man getifaddrs(3) Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message