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

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, 
                size_t optlen );

Library:

socket3r.lib, socket3s.lib

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:

EBADF
Invalid file descriptor s.
EDOM
Value was set out of range.
EINVAL
No optval value was specified.
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:

Standard Unix, POSIX 1003.1g (draft)

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

ICMP, IP, TCP, and UDP protocols

getsockopt()


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