From owner-freebsd-net@FreeBSD.ORG Tue Feb 24 12:35:02 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 CF15716A4CE; Tue, 24 Feb 2004 12:35:02 -0800 (PST) Received: from segfault.monkeys.com (segfault.monkeys.com [66.60.159.24]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9A06F43D1D; Tue, 24 Feb 2004 12:35:00 -0800 (PST) (envelope-from rfg@monkeys.com) Received: from monkeys.com (unknown [127.0.0.1]) by segfault.monkeys.com (Postfix) with ESMTP id 4B01D42031; Tue, 24 Feb 2004 12:35:00 -0800 (PST) To: Robert Watson In-reply-to: Your message of Mon, 23 Feb 2004 23:35:34 -0500. Date: Tue, 24 Feb 2004 12:35:00 -0800 Message-ID: <74400.1077654900@monkeys.com> From: "Ronald F. Guilmette" cc: freebsd-net@freebsd.org 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 20:35:02 -0000 In message , you wrote: > >On Mon, 23 Feb 2004, 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? > >In another e-mail, it's recommended that you try out getifaddrs(). This >is almost certainly the best thing to do, but I wanted to point out one >thing about the question you asked: when you bind a socket to INADDR_ANY, >you're actually not saying "bind to all addresses available at the moment >of binding", you're saying "bind to all addresses available at the moment >of comparison". I.e., the PCB in kernel retains the value INADDR_ANY, and >will match new IP addresses added to interfaces at some later time also. Thank you for pointing that out. I certainly did not know that interesting fact. For me at least, this distinction is rarely important in practice, because I personally don't tend to ifconfig new interfaces all that often... like hardly ever... but it is Good for me to know the implications of what you just said.