From owner-freebsd-net@FreeBSD.ORG Tue Mar 6 08:03:58 2012 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 386901065675 for ; Tue, 6 Mar 2012 08:03:58 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: from mail-lpp01m010-f54.google.com (mail-lpp01m010-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 9F83D8FC13 for ; Tue, 6 Mar 2012 08:03:57 +0000 (UTC) Received: by lagv3 with SMTP id v3so8045166lag.13 for ; Tue, 06 Mar 2012 00:03:56 -0800 (PST) Received-SPF: pass (google.com: domain of pluknet@gmail.com designates 10.152.132.132 as permitted sender) client-ip=10.152.132.132; Authentication-Results: mr.google.com; spf=pass (google.com: domain of pluknet@gmail.com designates 10.152.132.132 as permitted sender) smtp.mail=pluknet@gmail.com; dkim=pass header.i=pluknet@gmail.com Received: from mr.google.com ([10.152.132.132]) by 10.152.132.132 with SMTP id ou4mr14552438lab.26.1331021036443 (num_hops = 1); Tue, 06 Mar 2012 00:03:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=NfSBJcwTzI9sDULMKfY51Bg2E15i30e/0/Yt4HmHIBU=; b=blT/xYwlS484wJ292gPHSoagyX7nDIis+JMZaFSp8eSRI4WO9LmcWibfsvIBUa74bv BUSSoB6ffsO0uMPAicLW9RcHQTPMXQJoNmj07879wnYGZLHsd83BRo6VuJzFT2iqbvm+ +MZ8em3l2S8vZHLcdQtlRWcuyujCvTG7F7ssqpLOuOx5X+wbFJiTlgsSOWZ9pk9soVP2 THxjRpiYUsz8sOsUmmxrgjhzbZq7eS87B9w3fmAAJjzbIIMbyckxbn8zbwGwkCnDJV4w Lb6bAJmSOqNei7sQjx4CahIL7Yn3/iiIppxd6W8QKRxGAUQP354z+KvZ5HEdoYQic5U0 NZOA== MIME-Version: 1.0 Received: by 10.152.132.132 with SMTP id ou4mr11942191lab.26.1331021036381; Tue, 06 Mar 2012 00:03:56 -0800 (PST) Received: by 10.152.21.73 with HTTP; Tue, 6 Mar 2012 00:03:56 -0800 (PST) In-Reply-To: References: Date: Tue, 6 Mar 2012 11:03:56 +0300 Message-ID: From: Sergey Kandaurov To: hiren panchasara Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-net@freebsd.org Subject: Re: Difference between "struct addr" and "struct addrs" X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 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, 06 Mar 2012 08:03:58 -0000 On 6 March 2012 11:08, hiren panchasara wrote: > > > On Mon, Mar 5, 2012 at 10:57 PM, Sergey Kandaurov wrote: >> >> struct ifaddr is the in-kernel representation of the interface address. >> In kernel each network interface consists of a linked list of interface >> addresses, described by ifaddr structures. >> See man ifnet(9): http://man.freebsd.org/ifnet >> >> struct ifaddrs is used in the userland BSD API getifaddrs(3). This >> interface >> is used to get interface addresses in userland programs. See how it is >> used in e.g. ifconfig(8) sources: /usr/src/sbin/ifconfig/ifconfig.c >> See man getifaddrs(3): http://man.freebsd.org/getifaddrs > > Thanks Sergey, appreciate your help. > > Are they connected in any way? Can I get one if I have another? Well, not strictly. getifaddrs() collects addresses on all network interfaces using sysctl interface to the routine table with NET_RT_IFLIST[L] argument. NET_RT_IFLIST[L] does what you would expect: it runs through the linked list of network interfaces and gathers all struct ifaddr on each of them. You can see how that works in /usr/src/sys/net/rtsock.c:sysctl_iflist(). See also man sysctl(3) w.r.t. NET_RT_IFLIST / NET_RT_IFLISTL. -- wbr, pluknet