From owner-freebsd-net@FreeBSD.ORG Thu Jul 1 14:11:37 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 0253F16A4CF for ; Thu, 1 Jul 2004 14:11:37 +0000 (GMT) Received: from tigra.ip.net.ua (tigra.ip.net.ua [82.193.96.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 48E9D43D31 for ; Thu, 1 Jul 2004 14:11:36 +0000 (GMT) (envelope-from ru@ip.net.ua) Received: from heffalump.ip.net.ua (heffalump.ip.net.ua [82.193.96.213]) by tigra.ip.net.ua (8.12.11/8.12.11) with ESMTP id i61EHKof031739 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 Jul 2004 17:17:21 +0300 (EEST) (envelope-from ru@ip.net.ua) Received: (from ru@localhost) by heffalump.ip.net.ua (8.12.11/8.12.11) id i61EAvMa045837; Thu, 1 Jul 2004 17:10:57 +0300 (EEST) (envelope-from ru) Date: Thu, 1 Jul 2004 17:10:56 +0300 From: Ruslan Ermilov To: Anil Madhavapeddy Message-ID: <20040701141056.GA45665@ip.net.ua> References: <122AE07F-CB5B-11D8-99F8-000A95DA50A6@recoil.org> <40E40839.20500@cronyx.ru> <931572E3-CB5E-11D8-99F8-000A95DA50A6@recoil.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Q68bSM7Ycu6FN28Q" Content-Disposition: inline In-Reply-To: <931572E3-CB5E-11D8-99F8-000A95DA50A6@recoil.org> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) cc: net@FreeBSD.org cc: Roman Kurakin 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 14:11:37 -0000 --Q68bSM7Ycu6FN28Q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 01, 2004 at 02:00:06PM +0100, Anil Madhavapeddy wrote: > On 1 Jul 2004, at 13:48, Roman Kurakin wrote: > > > >If this is a problem why can't you make some wrapper that will=20 > >pack/unpack written on C, > >which will be a lib for you? >=20 > Because I want to minimise the size of the foreign bindings - this=20 > would require C code for every single Netgraph struct. If they were=20 > packed, I could just do it all in OCaml. >=20 > Isn't this a problem for other language bindings as well, or is=20 > everyone doing Netgraph userland hacking in C at the moment? >=20 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. /* A netgraph message */ struct ng_mesg { struct ng_msghdr { u_char version; /* must =3D=3D NG_V= ERSION */ u_char spare; /* pad to 2 bytes */ u_int16_t arglen; /* length of data */ u_int32_t flags; /* message status */ u_int32_t token; /* match with reply= */ u_int32_t typecookie; /* node's type cook= ie */ u_int32_t cmd; /* command identifi= er */ u_char cmdstr[NG_CMDSTRLEN+1]; /* cmd string + \0 = */ } header; char data[0]; /* placeholder for actual data */ }; : $ cat a.c : #include : #include : #include :=20 : int : main(void) : { :=20 : printf("%d %d\n", sizeof(struct ng_mesg), : 2 + sizeof(u_int16_t) + sizeof(u_int32_t) * 4 + (NG_CMDSTRLEN= + 1)); : return (0); : } : $ make a : cc -O -pipe a.c -o a : $ ./a : 36 36 Cheers, --=20 Ruslan Ermilov ru@FreeBSD.org FreeBSD committer --Q68bSM7Ycu6FN28Q Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFA5BtwqRfpzJluFF4RAt/7AJ9/nsMI8OpuFRyDeL4f4a61eeM0fQCghryc 07FxtWyyViY7gen+1Xt+gaQ= =mXDe -----END PGP SIGNATURE----- --Q68bSM7Ycu6FN28Q--