Ethereal-dev: Re: [Ethereal-dev] Buffers and pointers in a dissector

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxx>
Date: Fri, 22 Nov 2002 12:28:33 -0800
On Sat, Nov 23, 2002 at 03:42:23AM +1100, Ronnie Sahlberg wrote:
> Even if __attribute__ could be used by all compilers supported be ethereal
> it would still
> not help.
> The attribute will only really control the internal padding of a structure
> layout.
> I will not by magic convert
> > > > udp_hdr=(struct udp_header*)data_buffer
> into a 4 byte aligned address.

No, but it *does*, at least with *some* versions of GCC, cause the
compiler to generate code that's safe with unaligned pointers.

*However*, the GCC 2.95.3 manual says of "__attribute((packed))":

	http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC90

"The packed attribute specifies that a variable or structure field
should have the smallest possible alignment--one byte for a variable,
and one bit for a field, unless you specify a larger value with the
aligned attribute."

and does not appear to *explicitly* assert that the compiler generates
alignment-safe code, so I'm not sure it's safe to rely on GCC doing that.