Date: Thu, 1 Jul 2004 17:10:56 +0300 From: Ruslan Ermilov <ru@FreeBSD.org> To: Anil Madhavapeddy <anil@recoil.org> Cc: Roman Kurakin <rik@cronyx.ru> Subject: Re: Packing netgraph structs Message-ID: <20040701141056.GA45665@ip.net.ua> In-Reply-To: <931572E3-CB5E-11D8-99F8-000A95DA50A6@recoil.org> References: <122AE07F-CB5B-11D8-99F8-000A95DA50A6@recoil.org> <40E40839.20500@cronyx.ru> <931572E3-CB5E-11D8-99F8-000A95DA50A6@recoil.org>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
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
> >pack/unpack written on C,
> >which will be a lib for you?
>
> Because I want to minimise the size of the foreign bindings - this
> would require C code for every single Netgraph struct. If they were
> packed, I could just do it all in OCaml.
>
> Isn't this a problem for other language bindings as well, or is
> everyone doing Netgraph userland hacking in C at the moment?
>
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 == NG_VERSION */
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 cookie */
u_int32_t cmd; /* command identifier */
u_char cmdstr[NG_CMDSTRLEN+1]; /* cmd string + \0 */
} header;
char data[0]; /* placeholder for actual data */
};
: $ cat a.c
: #include <sys/types.h>
: #include <netgraph/ng_message.h>
: #include <stdio.h>
:
: int
: main(void)
: {
:
: 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,
--
Ruslan Ermilov
ru@FreeBSD.org
FreeBSD committer
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)
iD8DBQFA5BtwqRfpzJluFF4RAt/7AJ9/nsMI8OpuFRyDeL4f4a61eeM0fQCghryc
07FxtWyyViY7gen+1Xt+gaQ=
=mXDe
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040701141056.GA45665>
