From owner-freebsd-net@FreeBSD.ORG Mon Jul 21 21:31:03 2008 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 81A73106566B for ; Mon, 21 Jul 2008 21:31:03 +0000 (UTC) (envelope-from rehsack@web.de) Received: from fmmailgate01.web.de (fmmailgate01.web.de [217.72.192.221]) by mx1.freebsd.org (Postfix) with ESMTP id 367598FC14 for ; Mon, 21 Jul 2008 21:31:03 +0000 (UTC) (envelope-from rehsack@web.de) Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172]) by fmmailgate01.web.de (Postfix) with ESMTP id 4D0FDE8E1CDB; Mon, 21 Jul 2008 23:31:02 +0200 (CEST) Received: from [87.149.238.94] (helo=waldorf.muppets.liwing.de) by smtp06.web.de with esmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.109 #226) id 1KL2yD-0000WE-00; Mon, 21 Jul 2008 23:31:01 +0200 Message-ID: <4884FFFF.9090908@web.de> Date: Mon, 21 Jul 2008 21:30:39 +0000 From: Jens Rehsack User-Agent: Thunderbird 2.0.0.14 (X11/20080703) MIME-Version: 1.0 To: Brooks Davis References: <4884F401.4050103@web.de> <20080721204820.GE1699@lor.one-eyed-alien.net> In-Reply-To: <20080721204820.GE1699@lor.one-eyed-alien.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: rehsack@web.de X-Sender: rehsack@web.de X-Provags-ID: V01U2FsdGVkX1/G6Fp/9rh5WPFd7QisvRe1SrH26ieRZ1Hxvxud 2ys5p/jfr/iV46iiDPZv47U8ofNrI+klq3HWjqgs4UDl1wplKL OSmbUESrU= Cc: FreeBSD Net Subject: Re: lo0 not in ioctl( SIOCGIFCONF ) 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: Mon, 21 Jul 2008 21:31:03 -0000 Brooks Davis wrote: >> Hi, >> >> maybe this question is better asked in this list ... >> >> I was searching why ports/net/p5-Net-Interface was not working as >> expected and found some reasons. Most of them I can answer by implementing >> some test code as attached, but now I'm wondering why em0 is shown twice >> and lo0 is not included. >> The same situation on another machine .. > > The attachment didn't make it through. > > -- Brooks Copy&Paste starts here ... #include #include #include #include #include #include #include #include #ifndef _SIZEOF_ADDR_IFREQ #define _SIZEOF_ADDR_IFREQ(ifr) \ ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \ (sizeof(struct ifreq) - sizeof(struct sockaddr) + \ (ifr).ifr_addr.sa_len) : sizeof(struct ifreq)) #endif int main() { struct ifconf ifc; struct ifreq *ifr, *lifr; int fd; unsigned int n; fd = socket( AF_INET, SOCK_STREAM, 0 ); bzero(&ifc, sizeof(ifc)); n = 3; ifr = calloc( ifc.ifc_len, sizeof(*ifr) ); do { n *= 2; ifr = realloc( ifr, sizeof(*ifr) * n ); bzero( ifr, sizeof(*ifr) * n ); ifc.ifc_req = ifr; ifc.ifc_len = n * sizeof(*ifr); } while( ( ioctl( fd, SIOCGIFCONF, &ifc ) == -1 ) || ( ifc.ifc_len == n * sizeof(*ifr)) ); lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len]; while (ifr < lifr) { printf( "%s\n", ifr->ifr_name ); ifr = (struct ifreq *)(((char *)ifr) + _SIZEOF_ADDR_IFREQ(*ifr)); } return 0; }