Subject: Re: __attribute__ ((__packed__)) for struct ifreq
To: Andrew Brown <atatat@atatdot.net>
From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
List: tech-net
Date: 05/13/2000 15:14:41
>>	this is one of the motivation for migrating to getifaddrs(3), however,
>>	SIOCGIFCONF is widely used (and it is VERY hard to use SIOCGIFCONF
>>	100% correctly) so I think putting the attribute is more safe.
>funny...i had no problems using it.  i just assumed that nothing would
>be aligned properly and bcopied everything out of the returned buffer.
>maybe i'm just to careful...  :)

	It's extremely hard thing to do.  you are wizard if you made no mistake.
	- you need to allocate big-enough buffer before you call SIOCGIFCONF,
	  you end up doing SIOCGIFCONF couple of times to guess enough
	  buffer size.
	- ifreq pointer chasing - look at sa_len
	- bcopy before touching any of content on ifreq

	on ports with ALIGNBYTES = 8, with IPv6 address assigned to the
	node, SIOCGIFCONF will emit struct at address % 8 == 4.
	I've seen couple of unaligned accesses on alpha in various occasions.

	For many of basic applications we have migrated to getifaddrs(3),
	which hides this problem.
	http://www.NetBSD.org/cgi-bin/query-pr-single.pl?number=9866

itojun