From owner-freebsd-net@FreeBSD.ORG Mon Feb 23 19:41:38 2004 Return-Path: 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 9A88B16A4CE for ; Mon, 23 Feb 2004 19:41:38 -0800 (PST) Received: from smtpout.mac.com (smtpout.mac.com [17.250.248.44]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8F1F943D1F for ; Mon, 23 Feb 2004 19:41:38 -0800 (PST) (envelope-from justin@mac.com) Received: from mac.com (smtpin07-en2 [10.13.10.152]) by smtpout.mac.com (8.12.6/MantshX 2.0) with ESMTP id i1O3fc0a029803 for ; Mon, 23 Feb 2004 19:41:38 -0800 (PST) Received: from mac.com (c-24-6-87-110.client.comcast.net [24.6.87.110]) (authenticated bits=0) by mac.com (Xserve/smtpin07/MantshX 3.0) with ESMTP id i1O3faXq026262 (version=TLSv1/SSLv3 cipher=DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 23 Feb 2004 19:41:37 -0800 (PST) Date: Mon, 23 Feb 2004 19:41:35 -0800 Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v553) From: Justin Walker To: freebsd-net@freebsd.org Content-Transfer-Encoding: 7bit In-Reply-To: <46800.1077593230@monkeys.com> Message-Id: <585B0E50-667B-11D8-B1E0-00306544D642@mac.com> X-Mailer: Apple Mail (2.553) Subject: Re: Finding all IPv4 addresses associated with INADDR_ANY (?) X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Feb 2004 03:41:38 -0000 On Monday, February 23, 2004, at 07:27 PM, Ronald F. Guilmette wrote: > Given a socket which has been properly created, opened, and then bound > to some port and the special INADDR_ANY ``wildcard'' address, I need > to be able to them programatically find all of the IPv4 addresses that > the socket was just bound to. > > Can anyone suggest a way to do this? > > Can anyone suggest a way to do this easily? > > Can anyone suggest a way to do this portably? So I understand what you want, I'll rephrase: you want to find all the IPv4 addresses that have been assigned to devices on the local host. To pick nits, that socket was just bound to INADDR_ANY, not "all the address" on the host. Once a connection is accepted, that socket is bound based, probably, on the interface that accepted the request, or the destination address of that request. You can find the addresses on the host, in recent BSDs and Linux (AFAIK) with 'getifaddrs()', which is fairly easy to use, and fairly portable (although it's relatively new). Check the man page. You don't need to fuss with sockets to do this (but I'm not sure that is important to you). Does that help? Regards, Justin -- Justin C. Walker, Curmudgeon-At-Large * Institute for General Semantics | Men are from Earth. | Women are from Earth. | Deal with it. *--------------------------------------*-------------------------------*