Date: Fri, 6 Jun 2008 09:30:28 +0200 From: Marc =?iso-8859-1?q?L=F6rner?= <marc.loerner@hob.de> To: Rui Paulo <rpaulo@FreeBSD.org> Cc: freebsd-net@freebsd.org Subject: Re: Probable Bug in tcp.h Message-ID: <200806060930.28527.marc.loerner@hob.de> In-Reply-To: <20080605155646.GC6864@epsilon.local> References: <200806051712.47048.marc.loerner@hob.de> <20080605155646.GC6864@epsilon.local>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thursday 05 June 2008 17:56, Rui Paulo wrote:
> On Thu, Jun 05, 2008 at 05:12:47PM +0200, =?ISO-8859-1?Q?Marc_L=F6rner_
wrote:
> > Hello,
> > I probably found a bug in declaration of "struct tcphdr"!
> >
> > struct tcphdr {
> > u_short th_sport; /* source port */
> > u_short th_dport; /* destination port */
> > tcp_seq th_seq; /* sequence number */
> > tcp_seq th_ack; /* acknowledgement number */
> > #if BYTE_ORDER == LITTLE_ENDIAN
> > u_int th_x2:4, /* (unused) */ <---here
> > th_off:4; /* data offset */ <---
> > #endif
> > #if BYTE_ORDER == BIG_ENDIAN
> > u_int th_off:4, /* data offset */
> > th_x2:4; /* (unused) */
> > #endif
> > u_char th_flags;
> >
> > First of all I have the problam of misalignment of th_off. Because in
> > this way always 4 bytes are read and the the bits of th_off are replaced.
> > Then the 4 bytes are written back.
> >
> > But should (th_x and th_off) not only be 1 byte in whole -> only read and
> > write 1 byte?
> >
> > I think if this was changed, my misalignment problems would go away!
>
> I'm not sure what you mean.
>
> Please supply more information, like:
> 1) Are you running on little endian? Or big endian?
I'm on itanium-architecture, therefore I can run big and little endian. But
for now it is little endian.
> 2) th_x2 + th_off are 1 byte in size. What do you mean?
th_x2 and th_off are created as a bitfield. But C-Standard says that bitfields
are accessed as integers => 4-bytes
On itanium integers are read with ld4-command but the address of th_x2/th_off
may not be aligned to 4-bytes => we get an unaligned reference fault.
If we'd change to 1 byte-accesses => I won't get any misaligned faults
anymore.
Hope this makes my dilemma a bit clearer,
Marc
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806060930.28527.marc.loerner>
