Problem with zcip's packing of ARP packets?
Rich Felker
dalias at aerifal.cx
Fri Aug 25 05:50:48 UTC 2006
On Thu, Aug 24, 2006 at 09:55:08PM -0700, Andre wrote:
> --- Jason Schoon <floydpink at gmail.com> wrote:
> >
> > I have seen this problem as well, and submitted a patch to the list
> > some time ago. I don't believe it ever got applied though.
> > Here it is again.
>
> Patch looks good except for this:
>
> > + /* This cast is safe because ip is always kept as BE */
> > + if ((*(unsigned long *)p.arp.arp_spa == ip.s_addr)
>
> The cast is NOT safe (but not for the reason you mention... ;-).
>
> p is a packed structure, therefore arp_spa is not necessarily 32bit
> aligned... which means it can't be accessed via an unsigned long
> pointer on architectures which care about alignment...
It's not being accessed as an unsigned long pointer. It's being
accessed as whatever type the arp_spa member is, and then _cast_ to a
pointer to unsigned long. However the code looks wrong. I suspect it
was intended to do what you said, i.e. the intent was:
if ((*(unsigned long *)&p.arp.arp_spa == ip.s_addr)
and this of course is invalid if arp_spa is not aligned. Like you say,
memcmp would be the correct approach.
Rich
More information about the busybox
mailing list