lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Struct packing/alignment problems


From: Jani Monoses
Subject: Re: [lwip-users] Struct packing/alignment problems
Date: Tue, 4 May 2004 17:50:05 +0300

> 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

packing 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.

/** 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]