From owner-freebsd-net@FreeBSD.ORG Fri Jun 6 07:30:49 2008 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EE231106566B for ; Fri, 6 Jun 2008 07:30:49 +0000 (UTC) (envelope-from marc.loerner@hob.de) Received: from mailgate.hob.de (mailgate.hob.de [212.185.199.3]) by mx1.freebsd.org (Postfix) with ESMTP id A358B8FC20 for ; Fri, 6 Jun 2008 07:30:49 +0000 (UTC) (envelope-from marc.loerner@hob.de) Received: from imap.hob.de (mail2.hob.de [172.25.1.102]) by mailgate.hob.de (Postfix) with ESMTP id 462A6520032; Fri, 6 Jun 2008 09:30:48 +0200 (CEST) Received: from [172.22.0.190] (linux03.hob.de [172.22.0.190]) by imap.hob.de (Postfix on SuSE eMail Server 2.0) with ESMTP id C6B67FD381; Fri, 6 Jun 2008 09:30:47 +0200 (CEST) From: Marc =?iso-8859-1?q?L=F6rner?= Organization: hob To: Rui Paulo Date: Fri, 6 Jun 2008 09:30:28 +0200 User-Agent: KMail/1.6.2 References: <200806051712.47048.marc.loerner@hob.de> <20080605155646.GC6864@epsilon.local> In-Reply-To: <20080605155646.GC6864@epsilon.local> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200806060930.28527.marc.loerner@hob.de> Cc: freebsd-net@freebsd.org Subject: Re: Probable Bug in tcp.h X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Jun 2008 07:30:50 -0000 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