setsockopt()

set options associated with a socket

Synopsis:

#include <sys/types.h>
#include <sys/socket.h>

int setsockopt( int s, 
                int level, 
                int optname, 
                const void *optval, 
                int optlen );

Description:

The setsockopt() function sets options associated with a socket. Options may exist at multiple protocol levels; they're always present at the uppermost ``socket'' level.

When manipulating a socket option, you must specify the option's name and the level at which the option resides:

The optval and optlen arguments specify the option's value and the value's length. If no option value is to be supplied, optval may be NULL. To enable a boolean option, specify a nonzero value for optval; to disable the option specify a value of 0.

The parameter optname and any specified options are passed uninterpreted to the appropriate protocol module for interpretation. The include file <sys/socket.h> contains definitions for socket-level options; for information about these options, see getsockopt(). Options at other protocol levels vary in format and name.

Returns:

0
Success.
-1
An error occurred; errno is set.

Errors:

If an error occurred, errno could contain one of the following:

EBADF
The argument s isn't a valid descriptor.
EDOM
Value was set out of range.
EFAULT
The address pointed to by optval isn't in a valid part of the process address space.
ENOPROTOOPT
The option is unknown at the level indicated.

Classification:

POSIX 1003.1g (draft)

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

ICMP, IP, TCP, and UDP protocols, getsockopt()