Subject: Re: Updating arp(8) to use getifaddrs (cf. bin/8566)
To: Andrew Brown <firstname.lastname@example.org>
From: None <email@example.com>
Date: 11/08/2002 11:11:26
>On Thu, Nov 07, 2002 at 09:17:35AM -0500, Andrew Brown wrote:
> | >The problem with SIOCGIFCONF as used by most programs is that it
> | >doesn't cater for when the number of interfaces * sizeof(struct ifreq)
> | >(== 32) exceeds the buffer size passed in, so you might get truncated
> | >results. There is a way to detect and work around this, except non
> | >of the programs in usr.sbin/* that use SIOCGIFCONF do this, and won't
> | >work correctly if the buffer size is exceeded.
> | >(I checked various programs in usr.sbin which use SIOCGIFCONF, and
> | >they support between 10, 16, 32, 256 (or 1 case, 512) addresses.)
> | they're done incredibly wrong then. my understanding of the
> | "canonical" way to use SIOCGIFCONF was to call it once with an empty
> | struct ifconf (ie, ifc_buf is null and ifc_len is zero), and then
> | malloc a buffer of the size returned in ifc_len. probably with a pad
> | so that any *new* addresses that show up in between your first a
> | second calls are also covered. it's simple to check that you didn't
> | "get back" more data than you expected if you save the value of
> | ifc_len between the first and second calls.
SIOCGIFCONF is way too hard to get right, that's the very reason why
we now have getifaddrs(3). i'm all for the change.