set options associated with a socket
#include <sys/types.h> #include <sys/socket.h> int setsockopt( int s, int level, int optname, const void *optval, int optlen );
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.
If an error occurred, errno could contain one of the following:
POSIX 1003.1g (draft)
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
ICMP, IP, TCP, and UDP protocols, getsockopt()