sysctl sysctl
sysctl - get or set system information
#include <sys/sysctl.h>
#include <sys/socket.h>
sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen)
The sysctl function retrieves system information. The information
available from sysctl consists of integers, strings, and tables, and is a
small subset of that available from the function of the same name in
4.4BSD-Lite.
Unless explicitly noted below, sysctl returns a consistent snapshot of
the data requested. Consistency is obtained by locking the destination
buffer into memory so that the data may be copied out without blocking.
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. 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 a
NULL parameter 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 top level names are defined with a CTL_ prefix in <sys/sysctl.h>, and
are as follows. The next and subsequent levels down are found in the
include files listed here, and described in separate sections below.
Name Next level names Description
CTL_NET sys/socket.h Networking
Page 1
sysctl sysctl
CTL_NET [Toc] [Back]
The string and integer information available for the CTL_NET level is
detailed below. The changeable column shows whether a process with
appropriate privilege may change the value.
Second level name Type
PF_ROUTE routing messages
PF_INET internet values
PF_ROUTE
Return the entire routing table or a subset of it. The data is
returned as a sequence of routing messages. See route(7p) for the
header file, format and meaning). The length of each message is
contained in the message header.
The third level name is a protocol number, which is currently always
0. The fourth level name is an address family, which may be set to
0 to select all address families. The fifth and sixth level names
are as follows:
Fifth level name Sixth level is: Table
NET_RT_FLAGS rtflags Routing
NET_RT_DUMP None Routing (by flags)
NET_RT_IFLIST None Interface list
PF_INET
Get or set various global information about the internet protocols.
The third level name is the protocol. The fourth level name is the
variable name. The currently defined protocols and names are:
Protocol name Variable name Type
ip forwarding integer
ip redirect integer
udp checksum integer
The variables are as follows:
ip.forwarding
Returns 1 when IP forwarding is enabled for the host, meaning that
the host is acting as a router.
ip.redirect
Returns 1 when ICMP redirects may be sent by the host. This option
is ignored unless the host is routing IP packets, and should
normally be enabled on all systems.
udp.checksum
Returns 1 when UDP checksums are being computed and checked.
Disabling UDP checksums is strongly discouraged.
PPPPaaaaggggeeee 2222 [ Back ]
|