sysctlmibinfo2 2.0.1

Posted on March 16, 2021

sysctlmibinfo2 version 2.0.1 is out!

The sysctlmibinfo2 library provides an API to explore the FreeBSD sysctl MIB and to get the properties of an object, so it is useful to handle an object correctly or/and to build a sysctl-like utility; it is used by sysctlview, nsysctl, sysctl-mib-html and mixertui.

New version improvements:

New kernel features:

This versione takes advantages of the improvements of sysctlinfo 20210222 and sysctlbyname 20210223: improved efficiency to build a sysctlmif_object and new features to get info about an object: handler and nextbyname.

New functions:

sysctlmif_hashandler(), sysctlmif_hashandlerbyname() sysctlmif_nextnodebyname(), sysctlmif_nextleafbyname(), sysctlmif_leaves() and sysctlmif_leavesbyname().

Complete README:

The README provides: Introduction, Description, Getting started, API, Examples and Real world use cases.

New examples:

Examples in the Public Domain to build new projects.

Updated manual:


To install the port devel/libsysctlmibinfo2:

# cd /usr/ports/devel/libsysctlmibinfo2/ && make install clean

To add the package:

# pkg install libsysctlmibinfo2

Example to implement “sysctl -aN” and “nsysctl -aN” using the new feature sysctlmif_nextnodebyname():

#include <sys/param.h>

#include <stdio.h>
#include <string.h>
#include <sysctlmibinfo2.h>

/* Example to implement "/sbin/sysctl -aN" */
int main()
        char name[MAXPATHLEN], next[MAXPATHLEN];
        size_t nextlen = MAXPATHLEN;

        strcpy(next, "kern");
	do {
                strncpy(name, next, nextlen);
                printf("%s\n", name);
                nextlen = MAXPATHLEN;
        } while(sysctlmif_nextnodebyname(name, next, &nextlen) == 0);

        return (0);

Example to implement “sysctl -d hw.snd” or “nsysctl -d hw.snd”:

#include <stdio.h>
#include <sysctlmibinfo2.h>

/* Example to implement "sysctl -d hw.snd" */
int main()
	struct sysctlmif_list *list;
	struct sysctlmif_object *obj;

	if ((list = sysctlmif_grouplistbyname("hw.snd")) == NULL)
		return (1);

	SLIST_FOREACH(obj, list, object_link)
		printf("%s: %s\n", obj->name, obj->desc);


	return (0);

To compile:

% cc -I/usr/local/include example.c -L/usr/local/lib -lsysctlmibinfo2 -o example

To know more: