[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [lwip-users] Struct packing/alignment problems
From: |
Mountifield, Tony |
Subject: |
RE: [lwip-users] Struct packing/alignment problems |
Date: |
Mon, 26 Apr 2004 09:24:56 +0100 |
> I considered solving the problem by changing the ip_addr struct from:
> struct ip_addr {
> u32_t addr;
> }
> To something like:
> struct ip_addr {
> u8_t addr0;
> u8_t addr1;
> u8_t addr2;
> u8_t addr3;
> }
>
> But I found that this struct is used in tons of places.
> That's alot of code to
> rewrite..
> Have anyone solved this problem without introducing padding?
Yes, I had to use a similar approach to what you suggested:
struct ip_addr {
u8_t addrb[4];
}
I changed the name to ensure the compiler would catch all occurrences.
I then used macros to access the address. When copying, I used structure copy,
i.e. instead of "p->addr = x->y.addr;" I did "*p = x->y;". I defined htonlb()
and ntohlb() functions too.
A lot of the required changes are actually in LWIP_DEBUGF statements.
The next thing I found was that similar changes were needed for the seqno and
ackno in the TCP header, which are also unaligned, and so need redefinition as
u8_t arrays. It is then necessary to be careful about byte order. Instead of
rewriting the header in the received buffer, I left the seqno and ackno in
network byte order in the header, but transformed to native order when copying
to local variables.
I have hesitated to submit my changes yet, because there are still a few
kludges and also I haven't yet ensured portability back to CPUs and compilers
that don't need all this trickery. Also because I've been doing it as paid work.
Cheers,
Tony
***********************************************************************************
This email, its content and any attachments is PRIVATE AND
CONFIDENTIAL to TANDBERG Television. If received in error please
notify the sender and destroy the original message and attachments.
www.tandbergtv.com
***********************************************************************************
- [lwip-users] Struct packing/alignment problems, d99tibr, 2004/04/23
- RE: [lwip-users] Struct packing/alignment problems,
Mountifield, Tony <=
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/04/26
- Re: [lwip-users] Struct packing/alignment problems, Jani Monoses, 2004/04/26
- Re: [lwip-users] Struct packing/alignment problems, K.J. Mansley, 2004/04/26
- Re: [lwip-users] Struct packing/alignment problems, d99tibr, 2004/04/26
- Re: [lwip-users] Struct packing/alignment problems, K.J. Mansley, 2004/04/26
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/04/26
- Re: [lwip-users] Struct packing/alignment problems, Timmy Brolin, 2004/04/26
- Re: [lwip-users] Struct packing/alignment problems, Atte Kojo, 2004/04/27
- Re: [lwip-users] Struct packing/alignment problems, Leon Woestenberg, 2004/04/26
- Re: [lwip-users] Struct packing/alignment problems, d99tibr, 2004/04/26