|
NAMESYSCTLMIF_VERSION ,
sysctlmif_name ,
sysctlmif_oidbyname ,
sysctlmif_oidextendedbyname ,
sysctlmif_desc ,
sysctlmif_descbyname ,
sysctlmif_label ,
sysctlmif_labelbyname ,
sysctlmif_fmt ,
sysctlmif_fmtbyname ,
sysctlmif_hashandler ,
sysctlmif_hashandlerbyname ,
sysctlmif_kind ,
sysctlmif_kindbyname ,
SYSCTLMIF_KINDTYPE ,
SYSCTLMIF_KINDFLAGS ,
sysctlmif_nextnode ,
sysctlmif_nextnodebyname ,
sysctlmif_nextleaf ,
sysctlmif_nextleafbyname ,
sysctlmif_object ,
sysctlmif_objectbyname ,
sysctlmif_freeobject ,
sysctlmif_list ,
sysctlmif_grouplist ,
sysctlmif_grouplistbyname ,
sysctlmif_leaves ,
sysctlmif_leavesbyname ,
sysctlmif_freelist ,
sysctlmif_tree ,
sysctlmif_treebyname ,
sysctlmif_freetree ,
sysctlmif_mib ,
sysctlmif_freemib —
sysctl MIB-Tree API
LIBRARYTo load the required kernel modules at boot time, place the following lines in loader.conf(5):sysctlinfo_load="YES" sysctlbyname_improved_load="YES"
SYNOPSIS#include <sysctlmibinfo2.h>
int
int
int
int
int
int
int
int
int
int
int
int
int
unsigned int
unsigned int
int
int
int
int
struct sysctlmif_object *
struct sysctlmif_object *
void
struct sysctlmif_list *
struct sysctlmif_list *
struct sysctlmif_list *
struct sysctlmif_list *
struct sysctlmif_list *
void
struct sysctlmif_object *
struct sysctlmif_object *
void
struct sysctlmif_list *
void
DESCRIPTIONThesysctlmibinfo2 library is an interface to the kernel
sysctl MIB-Tree. It implements wrappers around the
sysctlinfo(4)
interface and sysctlbyname-improved to explore the sysctl MIB and to get the
info of an object, moreover it defines a struct
sysctlmif_object and provides a convenient API to build data structures
of sysctlmif_object; as it is not designed to get and
set object values, anyone wishing to do this should see
sysctl(3).
An object is identified by an Object Identifier (OID), a series of
numbers, represented by a pair int *id and
size_t idlevel, the level should be between 1 and
Wrapperssysctlmif_name () sets name and
namelen like the object with id /
idlevel.
SYSCTLMIF_KINDFLAGS (kind)
returns flags,SYSCTLMIF_KINDTYPE (kind)
returns type.
The previous functions seek the object with
id / idlevel or
name, then the property is copied into the buffer
(e.g., desc, label,
idnext, etc.). Before the call buflen (e.g.,
desclen, lebellen,
idnextlevel, etc.) gives the size of buffer, after a
successful call buflen gives the amount of data copied; the size of the
property can be determined with the sysctlmif_object APIThesysctlmibinfo2 library defines a struct for the info
of an object:
SLIST_HEAD(sysctlmif_list, sysctlmif_object); struct sysctlmif_object { SLIST_ENTRY(sysctlmif_object) object_link; int *id; /* array of idlevel entries */ size_t idlevel; /* between 1 and CTL_MAXNAME */ char *name; /* name in MIB notation */ char *desc; /* description */ char *label; /* aggregation label */ uint8_t type; /* defined in <sys/sysctl.h> */ uint32_t flags; /* defined in <sys/sysctl.h> */ char *fmt; /* format string */ struct sysctlmif_list *children; /* children list */ }; and a list of objects, struct sysctlmif_list, iterable by the SLIST macros, see queue(3) and EXAMPLES.
Capability ModeIn “capability mode”, see cap_enter(2),sysctlmibinfo2 checks if the object has
CTLFLAG_CAPRD or CTLFLAG_CAPWR
before to return its info, sysctlmif_nextnode (),
sysctlmif_nextnodebyname (),
sysctlmif_nextleaf () and
sysctlmif_nextleafbyname () ignore capability flags to
traverse the tree also in capability mode; properly
sysctlmibinfo2 provides “capability
mode” via
sysctlinfo(4)
interface.
RETURN VALUESThesysctlmif_oidbyname (),
sysctlmif_oidextendedbyname (),
sysctlmif_name (),
sysctlmif_desc (),
sysctlmif_descbyname (),
sysctlmif_label (),
sysctlmif_labelbyname (),
sysctlmif_fmt (),
sysctlmif_fmtbyname (),
sysctlmif_hashandler (),
sysctlmif_hashandlerbyname (),
sysctlmif_kind (),
sysctlmif_kindbyname (),
sysctlmif_nextnode (),
sysctlmif_nextnodebyname (),
sysctlmif_nextleaf (), and
sysctlmif_nextleafbyname () functions return the
value 0 if successful; otherwise the value -1 is returned and
the global variable errno is set to indicate the error.
The EXAMPLESComplete set of examples: https://gitlab.com/alfix/sysctlmibinfo2/tree/master/examplesIf installed: /usr/local/share/examples/sysctlmibinfo2/ Example to print the Sound Driver objects: struct sysctlmif_list *list; struct sysctlmif_object *obj; if ((list = sysctlmif_leavesbyname("hw.snd")) == NULL) return (1); SLIST_FOREACH(obj, list, object_link) { printf("name: %s\n", obj->name); printf("descr.: %s\n", obj->desc); printf("label: %s\n", obj->label); printf("flags: %u\n", obj->flags); printf("type: %u\n", obj->type); printf("fmt: %s\n", obj->fmt); printf("----------------------\n"); } sysctlmif_freelist(list); ERRORSThe following errors may be reported:
SEE ALSOcap_enter(2), queue(3), sysctl(3), sysctlinfo(3), sysctlinfo(4)HISTORYThesysctlmibinfo2 library first appeared in
FreeBSD 13.0.
AUTHORSsysctlmibinfo2 was written by Alfonso
Sabato Siciliano
<alf.siciliano@gmail.com>.
Visit the GSP FreeBSD Man Page Interface. |