The sysctl() function retrieves system information and allows processes
with appropriate privileges to set system information. The information
available from sysctl() consists of integers, strings, and tables.
The state is described using a "Management Information Base" (MIB) style
name, listed in name, which is a namelen length array of integers.
The information is copied into the buffer specified by oldp. The size of
the buffer is given by the location specified by oldlenp before the call,
and that location gives the amount of data copied after a successful call
and after a call that returns with the error code ENOMEM. If the amount
of data available is greater than the size of the buffer supplied, the
call supplies as much data as fits in the buffer provided and returns
with the error code ENOMEM. If the old value is not desired, oldp and
oldlenp should be set to NULL.
The size of the available data can be determined by calling sysctl() with
the NULL argument for oldp. The size of the available data will be
returned in the location pointed to by oldlenp. For some operations, the
amount of space may change often. For these operations, the system
attempts to round up so that the returned size is large enough for a call
to return the data shortly thereafter.
To set a new value, newp is set to point to a buffer of length newlen
from which the requested value is to be taken. If a new value is not to
be set, newp should be set to NULL and newlen set to 0.
The sysctlnametomib() function accepts an ASCII representation of the
name, looks up the integer name vector, and returns the numeric
representation in the mib array pointed to by mibp. The number of
elements in the mib array is given by the location specified by sizep
before the call, and that location gives the number of entries copied
after a successful call. The resulting mib and size may be used in
subsequent sysctl() calls to get the data associated with the requested
ASCII name. This interface is intended for use by applications that want
to repeatedly request the same variable (the sysctl() function runs in
about a third the time as the same request made via the sysctlbyname()
The number of elements in the mib array can be determined by calling
sysctlnametomib() with the NULL argument for mibp.
The sysctlnametomib() function is also useful for fetching mib prefixes.
If size on input is greater than the number of elements written, the
array still contains the additional elements which may be written
name - ASCII representation of the name
mibp - Integer array containing the corresponding name vector.
size - On input, number of elements in the returned array; on output,
the number of entries copied.