|
NAMESYSCTLMIF_VERSION ,
SYSCTLMIF_MAXIDLEVEL ,
sysctlmif_nametoid ,
sysctlmif_name ,
SYSCTLMIF_NAMELEN ,
sysctlmif_desc ,
SYSCTLMIF_DESCLEN ,
sysctlmif_label ,
SYSCTLMIF_LABELLEN ,
sysctlmif_info ,
SYSCTLMIF_INFOKIND ,
SYSCTLMIF_INFOTYPE ,
SYSCTLMIF_INFOFLAGS ,
SYSCTLMIF_INFOFMT ,
sysctlmif_nextnode ,
sysctlmif_nextleaf ,
sysctlmif_object ,
sysctlmif_freeobject ,
sysctlmif_filterlist ,
SYSCTLMIF_LIST ,
SYSCTLMIF_MAXDEPTH ,
sysctlmif_grouplist ,
sysctlmif_freelist ,
sysctlmif_tree ,
sysctlmif_freetree ,
sysctlmif_mib ,
sysctlmif_freemib —
sysctl MIB-Tree API
LIBRARYlibrary “libsysctlmibinfo”SYNOPSIS#include <sys/types.h>
#include <sys/queue.h>
#include <sys/sysctl.h>
#include <sysctlmibinfo.h>
int
int
int
int
int
int
int
int
uint32_t
uint8_t
uint32_t
char *
int
int
struct sysctlmif_object *
void
typedef int
struct sysctlmif_list *
struct sysctlmif_list *
struct sysctlmif_list *
void
struct sysctlmif_object *
void
struct sysctlmif_list *
void
DESCRIPTIONThesysctlmibinfo library is an interface to the kernel
sysctl MIB-Tree. It implements wrappers around an undocumented kernel
interface to provide a more easy interface for exploring the sysctl MIB and
for getting the properties 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), it is
represented by a pair int *id and
size_t idlevel, the level should be between 1 and
Please refer to sysctlmibinfo2(3) for an improved and more efficient API on a new kernel interface.
Wrapperssysctlmif_nametoid () sets id and
idlevel like the object with name and
namelen.
SYSCTLMIF_INFOFLAGS (info)
returns flags;SYSCTLMIF_INFOTYPE (info)
returns the type;SYSCTLMIF_INFOKIND (info)
returns flags following by type;SYSCTLMIF_INFOFMT (info)
returns a pointer to the “format string”.The previous functions seek the object with
id and 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
High-level APIThesysctlmibinfo 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 SYSCTLMIF_MAXIDLEVEL */ 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 */ }; /* * OR FLAGS: object fields to set, * id and idlevel are always set, * children list is set by sysctlmif_tree() and sysctlmif_mib(). */ #define SYSCTLMIF_FNAME 0x01 /* name */ #define SYSCTLMIF_FDESC 0x02 /* desc */ #define SYSCTLMIF_FLABEL 0x04 /* label */ #define SYSCTLMIF_FTYPE 0x08 /* type */ #define SYSCTLMIF_FFLAGS 0x10 /* flags */ #define SYSCTLMIF_FFMT 0x20 /* fmt */ #define SYSCTLMIF_FALL /* all */ and a list of objects, struct sysctlmif_list, iterable by the SLIST macros, see queue(3) and EXAMPLES.
RETURN VALUESThesysctlmif_nametoid (),
SYSCTLMIF_NAMELEN (),
sysctlmif_name (),
SYSCTLMIF_DESCLEN (),
sysctlmif_desc (),
SYSCTLMIF_LABELLEN (),
sysctlmif_label (),
sysctlmif_info (),
sysctlmif_nextnode (), and
sysctlmif_nextleaf () 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/sysctlmibinfo/tree/master/examplesIf installed: /usr/local/share/examples/sysctlmibinfo/ Example to print the Sound Driver objects: struct sysctlmif_list *list; struct sysctlmif_object *obj; int id[2], i; size_t idlevel = 2; size_t namelen = strlen("hw.snd") + 1; if ((sysctlmif_nametoid("hw.snd", namelen, id, &idlevel)) != 0) return (1); list = sysctlmif_grouplist(id, idlevel, SYSCTLMIF_FALL, SYSCTLMIF_MAXDEPTH); if (list == NULL) return (1); SLIST_FOREACH(obj, list, object_link) { printf("OID:"); for(i = 0; i < obj->idlevel; i++) printf(" %d", obj->id[i]); printf("\n"); printf("name: %s\n", obj->name); printf("descr: %s\n", obj->desc ? obj->desc : ""); printf("label: %s\n", obj->label ? 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); SEE ALSOqueue(3), sysctl(3), sysctlmibinfo2(3)HISTORYThesysctlmibinfo library first appeared in
FreeBSD 13.0.
AUTHORSAlfonso Sabato Siciliano <alf.siciliano@gmail.com>.CAVEATSsysctlmif_nextleaf () does not return an object with the
CTLFLAG_SKIP .
FreeBSD < 13,
The undocumented interface does not support Capability Mode so the
kernel returns the properties of an object without considering
cap_enter(2),
BUGSThe kernel can store an object with an OID ofCTL_MAXNAME levels but the kernel undocumented
interface can handle an OID up to CTL_MAXNAME-2 ;
except sysctlmif_name (), this library could fail with
a false negative.
Visit the GSP FreeBSD Man Page Interface. |