From owner-freebsd-hackers Fri Jun 2 00:29:19 1995 Return-Path: hackers-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.10/8.6.6) id AAA11526 for hackers-outgoing; Fri, 2 Jun 1995 00:29:19 -0700 Received: from haywire.DIALix.COM (peter@haywire.DIALix.COM [192.203.228.65]) by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id AAA11512 for ; Fri, 2 Jun 1995 00:29:14 -0700 Received: (from peter@localhost) by haywire.DIALix.COM (8.6.12/8.6.12/DIALix) id PAA16275; Fri, 2 Jun 1995 15:28:59 +0800 Date: Fri, 2 Jun 1995 15:28:58 +0800 (WST) From: Peter Wemm To: hackers@FreeBSD.ORG Subject: Size of SIOCGIFCONF ioctl data structure Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: hackers-owner@FreeBSD.ORG Precedence: bulk Something interesting was bought up on the bind-workers mailing list.. Bind was getting a truncated list of interfaces (it bind()'s to them all so that it can handle multi-homed hosts correctly). Anyway, there is no way to calculate how much is *enough* space to pass for the buffer. One if the solutions proposed is to use a while loop, malloc'ing a larger buffer each time around and doing the ioctl(s, SIOCGIFCONF, &ifr) each time until it gets a non-truncated list. Sun (In solaris 2.3) have added a SIOCGIFNUM ioctl, that returns the number of interfaces, so that the request buffer can be appropriately sized in one go, rather than going over and over the loop. What would be the chances of adding such an ioctl to FreeBSD? Since FreeBSD can return variable sized ifreq structures with larger addresses for various address family types, something would have to be done there. There'd be two ways around it.. 1: Calculate the number of bytes and divide it by the basic size of the structure (and round up), so that programs like named could so "bufsize = nif * sizeof(struct ifreq) + FUDGE_FACTOR; " 2: Introduce Yet Another (TM) ioctl that returns the number of bytes. Yes, I know there's the sysctl() way of doing it, but I don't think that would make it into Paul Vixie's release for a while. There's many other generic programs "out there" that could also benefit from this, where the author's are not prepared to dump the existing code and rewrite it from scratch to the 4.4bsd way of doing it This affects people that are running machines with lots of aliases on their ethernet addresses for things like web servers, as well as people running lots of slip/ppp/tun interfaces. Opinions? -Peter