int setsockopt (
const void *option_value,
size_t option_len );
[POSIX] The definition of the setsockopt() function in POSIX.1g Draft 6.6 uses a socklen_t data type instead of a size_t data type as specified in XNS4.0 (the previous definition).
[DIGITAL] The following definition of the setsockopt() function does not conform to current standards and is supported only for backward compatibility (see standards(5)):
int setsockopt (
int option_len );
Interfaces documented on this reference page conform to industry standards as follows:
The setsockopt function also supports POSIX.1g Draft 6.6.
Refer to the standards(5) reference page for more information about industry standards and associated tags.
Specifies the file descriptor for the socket. Specifies the protocol level at which the option resides. To set options at the socket level, specify the level parameter as SOL_SOCKET. To set options at other levels, supply the appropriate protocol number for the protocol controlling the option. For example, to indicate that an option will be interpreted by the TCP protocol, set level to the protocol number of TCP, as defined in the netinet/in.h file or as determined by using the getprotobyname() function. Specifies the option to set. The option_name parameter and any specified options are passed uninterpreted to the appropriate protocol module for interpretation. The sys/socket.h header file defines the socket level options. The socket level options can be enabled or disabled. The options are: Turns on recording of debugging information. This option enables or disables debugging in the underlying protocol modules. This option takes an int value. Permits sending of broadcast messages. This option takes an int value. Specifies that the rules used in validating addresses supplied by a bind() function should allow reuse of local addresses. This option takes an int value. Keeps connections active. Enables the periodic transmission of messages on a connected socket. If the connected socket fails to respond to these messages, the connection is broken and processes using that socket are notified with a SIGPIPE signal. [DIGITAL] Indicates that outgoing messages should bypass the standard routing facilities. Instead, they are directed to the appropriate network interface according to the network portion of the destination address. [DIGITAL] Valid only for routing sockets. Determines if a sending socket receives a copy of its own message. Lingers on a close() function if data is present. This option controls the action taken when unsent messages queue on a socket and a close() function is performed. If SO_LINGER is set, the system blocks the process during the close() function until it can transmit the data or until the time expires. If SO_LINGER is not specified and a close() function is issued, the system handles the call in a way that allows the process to continue as quickly as possible. This option takes a struct linger value, defined in the sys/socket.h header file, to specify the state of the option and linger interval. Leaves received out-of-band data (data marked urgent) in line. This option takes an int value. Sets send buffer size. This option takes an int value. Sets receive buffer size. This option takes an int value. [DIGITAL] Sets send low-water mark. This option takes an int value. [DIGITAL] Sets receive low-water mark. This option takes an int value. [DIGITAL] Sets send time out. This option takes a struct timeval value, defined in the sys/time.h header file, to specify the timeout interval. [DIGITAL] Sets receive time out. This option takes a struct timeval value, defined in the sys/time.h header file, to specify the timeout interval. [DIGITAL] Allows more than one process to receive UDP datagrams destined for the same port. The bind system call binding a process to that port must be preceded by a setsockopt system call specifying this option.
[DIGITAL] The maximum values for socket level options like SO_SENDBUF, SO_RCVBUF, SO_SNDLOWAT, and SO_RCVLOWAT are governed by the protocol limits, as well as its implementation. Use the getsockopt(2) routine to verify the values for these options after the socket connection has been established.
To enable a Boolean option or integer value, set the option_value parameter to a nonzero value. To disable an option, set the option_value parameter to 0 (zero). The option_len parameter contains the size of the buffer pointed to by the option_value parameter.
The setsockopt() function sets options associated with a socket. Options may exist at multiple protocol levels. The SO_ options are always present at the uppermost socket level.
The setsockopt() function provides an application program with the means to control a socket communication. An application program can use the setsockopt() function to enable debugging at the protocol level, allocate buffer space, control timeouts, or permit socket data broadcasts. The sys/socket.h file defines all the options available to the setsockopt() function.
When setting socket options, specify the protocol level at which the option resides and the name of the option.
Use the option_value and option_len parameters to access option values for the setsockopt() function. These parameters identify a buffer in which the value for the requested option or options is returned.
Upon successful completion, a value of 0 (zero) is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error.
If the setsockopt() function fails, errno may be set to one of the following values: [POSIX] The calling process does not have appropriate permissions. The socket parameter is not valid. [POSIX] The send and receive timeout values are too large to fit in the timeout fields of the socket structure. The option_len parameter is not valid. [POSIX] The socket is already connected; the specified option cannot be set when the socket is in the connected state. The option_value parameter is not in a readable part of the user address space. [POSIX] Insufficient resources are available in the system to complete the call. The option is unknown. The socket parameter refers to a file, not a socket.
Functions: bind(2), endprotoent(3), getsockopt(2), getprotobynumber(3), getprotoent(3), setprotoent(3), socket(2).
Network Information: ip(7), tcp(7).
Standards: standards(5). delim off