From owner-freebsd-questions@FreeBSD.ORG Tue Aug 31 11:30:22 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4E34E16A4CE for ; Tue, 31 Aug 2004 11:30:22 +0000 (GMT) Received: from lakermmtao09.cox.net (lakermmtao09.cox.net [68.230.240.30]) by mx1.FreeBSD.org (Postfix) with ESMTP id CC1E143D31 for ; Tue, 31 Aug 2004 11:30:21 +0000 (GMT) (envelope-from tbird-contact@cox.net) Received: from yourxu5v9frokn ([24.252.34.192]) by lakermmtao09.cox.net (InterMail vM.6.01.03.02.01 201-2131-111-104-103-20040709) with SMTP id <20040831112945.KHGE16771.lakermmtao09.cox.net@yourxu5v9frokn>; Tue, 31 Aug 2004 07:29:45 -0400 Message-ID: <000f01c48f4d$d583b990$c022fc18@yourxu5v9frokn> From: "Lucas (a.k.a T-Bird or bsdfan3)" To: "Dan Nelson" References: <000301c48efa$bfa00500$c022fc18@yourxu5v9frokn> <20040831021047.GC33896@dan.emsphone.com> Date: Tue, 31 Aug 2004 06:29:52 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 cc: freebsd-questions@freebsd.org Subject: Re: Variable length packets? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Aug 2004 11:30:22 -0000 I'll try using __attribute__ ((packed)) on the declaration of struct packet_t. ----- Original Message ----- From: "Dan Nelson" To: "Lucas (a.k.a T-Bird or bsdfan3)" Cc: Sent: Monday, August 30, 2004 9:10 PM Subject: Re: Variable length packets? > In the last episode (Aug 30), Lucas (a.k.a T-Bird or bsdfan3) said: >> I am trying to implement a custom protocol that sends and receives >> variable-length packets on top of TCP/IPv4. The problem is that the >> length field of the packet is silently being mangled first becoming 0 >> and then getting turned into a very large number (about 2-3 billion). >> The length field is a u_int32_t and I am using the byteorder >> routines. Source code snippets follow: >> >> --decl of struct packet_t-- >> struct packet_t >> { >> u_int16_t num; >> u_int32_t len; >> char data[0]; >> }; > > If these are different OSes, the structure may be packed differently. > There's almost certainly two bytes of padding between num and len to > ensure that len is 32-bit aligned, for example. > > If you run ktrace on your client (or server), the kdump output will > include a hexdump of all data read or written, which might help you > determine what's going wrong. > > -- > Dan Nelson > dnelson@allantgroup.com >