|
From: | Timmy Brolin |
Subject: | Re: [lwip-users] Struct packing/alignment problems |
Date: | Tue, 04 May 2004 19:02:27 +0200 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) |
Jani Monoses wrote:
Why would they be put on 4 byte boundaries? The natural boundary of u16s is 2 bytes, not 4 bytes. Putting a u16 on a 4 byte boundary changes nothing. There is however a special case problem in the etharp header: Either sipaddr or dipaddr will become unaligned. (Which one depends on the size of ethhdr).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 ethernetpacking directives tell the compiler that it should not pad fields in the struct. So if you have an int16 it does not reserve 4 bytes for it to imporve performance because of alignedness. So padding solves a problem for some compilers but does not solve the other. Consider this struct: without the PACK directives all those u16s would be put at 4 byte boundaries, not what we want.
But this special case has already been discussed and solved. Timmy
/** the ARP message */ struct etharp_hdr { PACK_STRUCT_FIELD(struct eth_hdr ethhdr); PACK_STRUCT_FIELD(u16_t hwtype); PACK_STRUCT_FIELD(u16_t proto); PACK_STRUCT_FIELD(u16_t _hwlen_protolen); PACK_STRUCT_FIELD(u16_t opcode); PACK_STRUCT_FIELD(struct eth_addr shwaddr); PACK_STRUCT_FIELD(struct ip_addr2 sipaddr); PACK_STRUCT_FIELD(struct eth_addr dhwaddr); PACK_STRUCT_FIELD(struct ip_addr2 dipaddr); } PACK_STRUCT_STRUCT; PACK_STRUCT_END _______________________________________________ lwip-users mailing list address@hidden http://mail.gnu.org/mailman/listinfo/lwip-users
[Prev in Thread] | Current Thread | [Next in Thread] |