Ethereal-dev: RE: [Ethereal-dev] Re: question on TLV

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

From: Mark Pilant <Mark.Pilant@xxxxxxx>
Date: Tue, 13 Sep 2005 12:06:18 -0400
In most cases I've seen, the "extra" bytes are usually the result of
either a bug or a limited view of the world.  Let me explain a bit.

When programming, extra bytes may be added to an in memory structure
by the compiler to align members for better performance.  These extra
bytes can be removed (to save memory) by packing the structure but at
the cost of slower access.  (In many instances unaligned, 32 bit or
64 bit, memory references will be faster than byte aligned memory
references.)

Now, when it is desired for data to go out "on the wire", it is usually
desirable to send the minimum number of bytes needed; for performance.

So here is where the problems can come in...

If a programmer uses the "sizeof" a structure to determine how much to
read/write, then extra bytes may be added unless the structure has been
packed or byte aligned.

As long as the information stays between members of the same platform
(e.g., Windows to Windows) this is not usually a problem.  However, when
going cross platform (e.g., Windows to *nix) it can be a problem.

The possible bug is the developer writing the code may not realize this
structure member alignment is taking place and cause problems because
the
length is not what is expected.

I hope this helps.

- Mark