Packing netgraph structs
Ruslan Ermilov
ru at FreeBSD.org
Thu Jul 1 07:11:37 PDT 2004
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 at FreeBSD.org
FreeBSD committer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-net/attachments/20040701/6faae6ac/attachment.bin
More information about the freebsd-net
mailing list