sysctl
![]() |
![]() |
![]() |
![]() |
sysctl()
Get or set information about the socket manager
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 );
Arguments:
- name
- An array of integers that specifies the Management Information Base (MIB) stylename of the item that you want to set or get; see below.
- namelen
- The length of the name.
- oldp
- NULL, or a pointer to a buffer where the function can store the old value.
- oldlenp
- NULL, or a pointer to a location that initially specifies the size of the oldp buffer. The function changes the value in this location to be the size of the old information stored in the oldp buffer
- newp
- NULL, or a pointer to a buffer that holds the new value.
- newlen
- The size of the new value.
Library:
libsocket
Use the -l socket option to qcc to link against this library.
Description:
The sysctl() function retrieves information about the socket manager and allows processes with appropriate privileges to set this 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 you don't need the old value, you can set oldp and oldlenp to NULL.
You can determine the size of the available data by calling sysctl() with a NULL parameter for oldp. The function stores the size of the available data 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 specify a new value, set newp 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>. QNX 4 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 |
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.

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 contains 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 an unknown value.
- EPERM
- An attempt was 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:
| Safety: | |
|---|---|
| Cancellation point | Yes |
| Interrupt handler | No |
| Signal handler | No |
| Thread | Yes |
See also:
ROUTE protocol
sysctl in the Utilities Reference
![]() |
![]() |
![]() |
![]() |
![[Previous]](../prev.gif)
![[Contents]](../contents.gif)
![[Index]](../keyword_index.gif)
![[Next]](../next.gif)