sysctl command with struct
Pham Viet Ha
hapvbk at yahoo.co.uk
Fri May 4 21:54:08 UTC 2012
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
More information about the freebsd-net
mailing list