Date: Fri, 4 May 2012 22:54:00 +0100 (BST) From: Pham Viet Ha <hapvbk@yahoo.co.uk> To: "net@freebsd.org" <net@freebsd.org>, "freebsd-net@freebsd.org" <freebsd-net@freebsd.org> Subject: Re: sysctl command with struct Message-ID: <1336168440.88161.YahooMailNeo@web28805.mail.ir2.yahoo.com> In-Reply-To: <1336168076.28222.YahooMailNeo@web28802.mail.ir2.yahoo.com> References: <1336168076.28222.YahooMailNeo@web28802.mail.ir2.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi all,
I am writing a code using sysctl to manipulate a kernel variable. The variable is a data structure with two fields, protocol number (uint16_t) and description (char *).
I have some difficulties with sysctl command to pass both protocol number and description at a time to the kernel. I used CTLTYPE_OPAQUE in SYSCTL_ADD_PROC call, then I used sysctl_handle_opaque to read data.
It does not work correctly. I don't know how what is the format I have to use when I type in "sysctl ..." at the prompt.
struct protodesc {
uint16_t protonumber;
char description[256];
}Add the proc:
SYSCTL_ADD_PROC(&ctx, SYSCTL_CHILDREN(tree_oidp), OID_AUTO,
"protodesc", CTLTYPE_OPAQUE | CTLFLAG_RW, 0, 0,
sysctl_protodesc_update, "S,protodesc",
"To update protocol and description");
In sysctl_protodesc_update, a call to sysctl_handle_opaque:
error = sysctl_handle_opaque(oidp, &entry, sizeof entry, req);
entry is of type protodesc.
Compilation and running both ok. The only issue is that I cannot type in the values for protodesc at sysctl command. I don't know what the format is.
Error message: sysctl: oid 'protodesc' is type 5, cannot set that.
Thanks for any help.
P/S: I sent an incomplete email by accident. Sorry for that.
HAPVBK
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1336168440.88161.YahooMailNeo>
