From owner-freebsd-net@FreeBSD.ORG Thu Jul 1 15:33:18 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D17B616A4CE for ; Thu, 1 Jul 2004 15:33:18 +0000 (GMT) Received: from quick.recoil.org (quick.recoil.org [194.70.3.133]) by mx1.FreeBSD.org (Postfix) with SMTP id E6CD743D4C for ; Thu, 1 Jul 2004 15:33:17 +0000 (GMT) (envelope-from anil@recoil.org) Received: (qmail 24170 invoked from network); 1 Jul 2004 15:32:23 -0000 Received: from localhost (HELO ?IPv6:::1?) (127.0.0.1) by quick.recoil.org with SMTP; 1 Jul 2004 15:32:23 -0000 In-Reply-To: <20040701141056.GA45665@ip.net.ua> References: <122AE07F-CB5B-11D8-99F8-000A95DA50A6@recoil.org> <40E40839.20500@cronyx.ru> <931572E3-CB5E-11D8-99F8-000A95DA50A6@recoil.org> <20040701141056.GA45665@ip.net.ua> Mime-Version: 1.0 (Apple Message framework v618) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Anil Madhavapeddy Date: Thu, 1 Jul 2004 16:32:32 +0100 To: Ruslan Ermilov X-Mailer: Apple Mail (2.618) cc: Roman Kurakin cc: net@FreeBSD.org Subject: Re: Packing netgraph structs X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jul 2004 15:33:18 -0000 On 1 Jul 2004, at 15:10, Ruslan Ermilov wrote: > We use Netgraph from within Python, using the netgraph(3) library, > and we pack/unpack various Netgraph related structs just happily. > > Speaking of "struct ng_mesg", if you pack it, it will essentially > stay the same, because I believe it was created with this in mind, > as well as most if not all other user-accessible Netgraph structs. How robust is this solution? Since ng_mesg uses nested structs, and compilers can insert padding at the end of structs at will, this could lead to padding between ng_mesg.header.cmdstr and ng_mesg.data. Alan Mycroft, who wrote the ARM C compiler commented that the C spec is rather ambiguous about padding, and that compilers are quite free to pad as they chose in between structs as well. In other words - is there any harm in adding a packed attribute here to ensure this wont break and lead to hard to track down bugs in the future? It shouldn't even affect the gcc ABI I think ... ? For the moment, I'll get on with just serialising as if it were optimally packed from OCaml, thanks for your help so far! -- Anil Madhavapeddy http://anil.recoil.org University of Cambridge http://www.cl.cam.ac.uk