[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Struct packing/alignment problems
From: |
d99tibr |
Subject: |
Re: [lwip-users] Struct packing/alignment problems |
Date: |
Tue, 4 May 2004 16:41:52 +0200 |
User-agent: |
Internet Messaging Program (IMP) 3.2.1 |
> On Tue, 2004-05-04 at 01:04, Timmy Brolin wrote:
> > Mandatory
> > alignment would render all those STRUCT_PACK macros unnecessary,
> > resulting in cleaner code, and significantly increased portability (ANSI
> > C conformant, no alignment problem, and no need to define architecture
> > specific struct packing macros)
>
> Padding of the start of the struct does not guarantee the alignment of
> subsequent elements in that struct, so the packing is still required.
>
> Kieran
Oh but it does.
The fields in the IP and TCP headers are properly aligned relative to the start
of the headers by design. The problem is that the ethernet header is 14 bytes
which is not a factor of four, so the starting address of the subsequent IP and
TCP structs become unaligned.
A compiler normaly fix struct alignment problems by silently inserting padding
between the fields in the struct (this is of course not acceptable). In order
to keep the compiler from doing so, there are struct packing compiler
directives in the lwip code. Theese compiler directives tell the compiler to
pack the structs even if they are unaligned. Not all compilers and processors
support this, it is not ANSI C, and the implementation is highly compiler
specific.
By padding the ethernet header to 16 bytes, we ensure that the IP and TCP
structs are correctly aligned. And since there are no alignment problems, the
compiler will not add any padding. Thus, we don't need the struct packing
directives.
Note that this problem does not exist at all for PPP and other link layers
where the link layer header is a factor of four.
Timmy
-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/01
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/05/03
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/03
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, K.J. Mansley, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems,
d99tibr <=
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Leon Woestenberg, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Leon Woestenberg, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/04
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/05/05
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/05/05
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/05/05
- Re: [lwip-users] Struct packing/alignment problems, K.J. Mansley, 2004/05/04