Subject: Re: CMSG_* problems
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Matt Thomas <matt@3am-software.com>
List: tech-kern
Date: 02/12/2007 12:21:52
der Mouse wrote:

>> As I read RFC 2292 (today, for the first time) istm that was the
>> authors' intent.  The suggested implementations use an
>> "implementation defined" ALIGN() macro.
> 
> Indeed.  But they all assume the buffer is *already* aligned, which is
> my point - that ALIGN does nothing but maintain the existing alignment
> (and not even that, if it starts out misaligned on an architecture that
> errors on unaligned accesses).  The 2292 interface completely ignores
> the issue of buffer alignment, which is one of the reasons I think it
> is broken - it's usable only on machines with no alignment constraints,
> or with malloc()ed buffers, or with various ugly hacks to ensure
> alignment.  (The only way I can think of to ensure alignment suitable
> for a struct cmsghdr, without machine- or compiler-dependent hackery,
> is to allocate the buffer as an array of struct cmsghdr, and that still
> doesn't ensure the buffer is suitably aligned for the data fields of
> the control messages.)

The way it is normally is make it an array of the maximally aligned type
(usually of type long or long long).