[Previous] [Contents] [Index] [Next]

sysctl()

Get or set the system information

Synopsis:

#include <sys/param.h>
#include <sys/sysctl.h>

int sysctl( int * name,
            u_int namelen,
            void * oldp,
            size_t * oldlenp,
            void * newp,
            size_t newlen );

Library:

socket3r.lib, socket3s.lib

Description:

The sysctl() function retrieves system information and allows processes with appropriate privileges to set system information. The data available from sysctl() consists of integers and tables. You can also get or set data using the sysctl utility at the command line.

The state is described using a Management Information Base (MIB) stylename, specified 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 delivers as much data as fits in the buffer provided and returns with the error code ENOMEM. If the old value isn't 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 is 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 you're not setting a new value, set newp to NULL and newlen to 0.

The top-level names are defined with a CTL_ prefix in <sys/sysctl.h>. QNX4 supports CTL_NET only. The next and subsequent levels down are found in the following header files:

This header file Contains definitions for
<sys/sysctl.h> Top-level identifiers
<sys/socket.h> Second-level network identifiers
<netinet/in.h> Third-level Internet identifiers and fourth-level IP identifiers
<netinet/icmp_var.h> Fourth-level ICMP identifiers
<netinet/tcp_var.h> Fourth-level TCP identifiers
<netinet/udp_var.h> Fourth-level UDP identifiers

The following code fragment checks whether the UDP packets checksum is enabled:

int mib[5], val;
size_t len;

mib[0] = CTL_NET;
mib[1] = AF_INET;
mib[2] = IPPROTO_UDP;
mib[3] = UDPCTL_CHECKSUM;
len = sizeof(val);
sysctl(mib, 4, &val, &len, NULL, 0);

CTL_NET

The table 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 Changeable
PF_INET internet values yes

PF_INET

PF_INET gets or sets global information about internet protocols.

The third-level name is the protocol. The fourth-level name is the variable name. Here are the currently defined protocols and names:

Protocol name Variable name Type Changeable
ip forwarding integer yes
redirect integer yes
ttl integer yes
forwsrcrt integer yes
directed-broadcast integer yes
allowsrcrt integer yes
subnetsarelocal integer yes
mtudisc integer yes
maxfragpackets integer yes
sourcecheck integer yes
sourcecheck_logint integer yes
icmp maskrepl integer yes
tcp rfc1323 integer yes
sendspace integer yes
recvspace integer yes
mssdflt integer yes
syn_cache_limit integer yes
syn_bucket_limit integer yes
syn_cache_interval integer yes
udp checksum integer yes
sendspace integer yes
recvspace integer yes

where 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. Normally, this option should be enabled on all systems.
ip.ttl
The maximum time-to-live (hop count) value for an IP packet sourced by the system. This value applies to normal transport protocols, not to ICMP.
ip.forwsrcrt
Returns 1 when forwarding of source-routed packets is enabled for the host. This value may be changed only if the kernel security level is less than 1.
ip.directed-broadcast
Returns 1 if directed-broadcast behavior is enabled for the host.
ip.allowsrcrt
Returns 1 if the host accepts source-routed packets.
ip.subnetsarelocal
Returns 1 if subnets are to be considered local addresses.
ip.mtudisc
Returns 1 if path MTU discovery is enabled.
ip.maxfragpackets
Returns the maximum number of fragmented IP packets in the IP reassembly queue.
ip.sourcecheck
Returns 1 if source check for received packets is enabled.
ip.sourcecheck_logint
Returns the time interval when IP source address verification messages are logged. A value of zero disables the logging.
icmp.maskrepl
Returns 1 if ICMP network mask requests are to be answered.
tcp.rfc1323
Returns 1 if RFC1323 extensions to TCP are enabled.
tcp.sendspace
Returns the default TCP send buffer size.
tcp.recvspace
Returns the default TCP receive buffer size.
tcp.mssdflt
Returns the default TCP maximum segment size.
tcp.syn_cache_limit
Returns the maximum number of entries allowed in the TCP compressed state engine.
tcp.syn_bucket_limit
Returns the maximum number of entries allowed per hash bucket in the TCP compressed state engine.
tcp.syn_cache_interval
Returns the TCP compressed state engine's timer interval.
udp.checksum
Returns 1 when UDP checksums are being computed and checked.
Note: Disabling UDP checksums is strongly discouraged.

udp.sendspace
Returns the default UDP send buffer size.
udp.recvspace
Returns the default UDP receive buffer size.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EFAULT
The buffers: name, oldp, newp, or the length pointer oldlenp contain an invalid address.
EINVAL
The name array is less than two or greater than CTL_MAXNAME; or a non-NULL newp is given and its specified length in newlen is too large or too small.
ENOMEM
The length pointed to by oldlenp is too short to hold the requested value.
ENOTDIR
The name array specifies an intermediate rather than terminal name.
EOPNOTSUPP
The name array specifies a value that is unknown.
EPERM
An attempt is made to set a read-only value; a process, without appropriate privilege, attempts to set or change a value protected by the current system security level.

Classification:

Unix

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

ROUTE protocol

sysctl in the TCP/IP User's Guide


[Previous] [Contents] [Index] [Next]