Skip site navigation (1)Skip section navigation (2)
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,=0A=0AI am writing a code using sysctl to manipulate a kernel variab=
le. The variable is a data structure with two fields, protocol number (uint=
16_t) and description (char *).=0A=0AI have some difficulties with sysctl c=
ommand 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=A0sysctl_handl=
e_opaque to read data.=A0=0A=0AIt 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=
.=A0=0A=0Astruct protodesc {=A0=0Auint16_t protonumber;=A0=0Achar descripti=
on[256];=0A}Add the proc:=A0=0A=0ASYSCTL_ADD_PROC(&ctx, SYSCTL_CHILDREN(tre=
e_oidp), OID_AUTO,=0A =A0 =A0"protodesc", CTLTYPE_OPAQUE | CTLFLAG_RW, 0, 0=
,=0A =A0 =A0sysctl_protodesc_update, "S,protodesc",=0A =A0 =A0"To update pr=
otocol and description");=0A=0AIn=A0sysctl_protodesc_update, a call to=A0sy=
sctl_handle_opaque:=A0=0A=0Aerror =3D sysctl_handle_opaque(oidp, &entry, si=
zeof entry, req);=0A=0Aentry is of type protodesc.=A0=0A=0ACompilation and =
running both ok. The only issue is that I cannot type in the values for pro=
todesc at sysctl command. I don't know what the format is.=A0=0AError messa=
ge:=A0sysctl: oid 'protodesc' is type 5, cannot set that.=A0=0A=0A=0AThanks=
 for any help.=A0=0A=0AP/S: I sent an=A0incomplete=A0email by accident. Sor=
ry for that.=A0=0A=0AHAPVBK



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