Skip site navigation (1)Skip section navigation (2)
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

--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 <sys/types.h>
: #include <netgraph/ng_message.h>
: #include <stdio.h>
:=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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040701141056.GA45665>