lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] [PATCH] fix warning for gcc and possible unaligned acce


From: Leon Woestenberg
Subject: Re: [lwip-users] [PATCH] fix warning for gcc and possible unaligned access
Date: Sun, 23 Apr 2006 14:30:41 +0200
User-agent: Thunderbird 1.5.0.2 (Windows/20060308)

Hello all,

Curt McDowell wrote:
struct ip_addr2 is only used as a hack in etharp.c and should be removed.
etharp_arp_input() should use simple memcpy()s to copy the struct ip_addr,
because that code isn't in a critical path.

  memcpy(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
  memcpy(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));

The following comment in etharp_arp_input() is wrong:

  /* these are aligned properly, whereas the ARP header fields might not be */
  struct ip_addr sipaddr, dipaddr;

Because struct ip_addr is packed, sipaddr and dipaddr have an alignment
requirement of 1.  This booby trap results in really erratic behavior, say if
the "u8_t i" is moved up.  I was using struct ip_addr in my code and this
problem cost me a few hours.  struct ip_addr should not be packed.  Only the
packet format structures that contain it need to be packed.

I think Curt's idea looks good / best. Do I summarize the actions to be taken OK as follows?

- remove packing from "struct ip_addr" globally.
- Byte by byte memory copies (using memcpy() or inline for loop) from packet to/from structure.
- Get rid of ip_addr2.

Regards,

Leon.







reply via email to

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