2 getsockopt, setsockopt - get and set options on sockets
7 int getsockopt(int s, int level, int optname, void *opt
8 val, socklen_t *optlen);
10 int setsockopt(int s, int level, int optname, const void
11 *optval, socklen_t optlen);
14 Getsockopt and setsockopt manipulate the options associ
15 ated with a socket. Options may exist at multiple proto
16 col levels; they are always present at the uppermost
19 When manipulating socket options the level at which the
20 option resides and the name of the option must be speci
21 fied. To manipulate options at the socket level, level is
22 specified as SOL_SOCKET. To manipulate options at any
23 other level the protocol number of the appropriate proto
24 col controlling the option is supplied. For example, to
25 indicate that an option is to be interpreted by the TCP
26 protocol, level should be set to the protocol number of
27 TCP; see getprotoent(3).
29 The parameters optval and optlen are used to access option
30 values for setsockopt. For getsockopt they identify a
31 buffer in which the value for the requested option(s) are
32 to be returned. For getsockopt, optlen is a value-result
33 parameter, initially containing the size of the buffer
34 pointed to by optval, and modified on return to indicate
35 the actual size of the value returned. If no option value
36 is to be supplied or returned, optval may be NULL.
38 Optname and any specified options are passed uninterpreted
39 to the appropriate protocol module for interpretation.
40 The include file <sys/socket.h> contains definitions for
41 socket level options, described below. Options at other
42 protocol levels vary in format and name; consult the
43 appropriate entries in section 4 of the manual.
45 Most socket-level options utilize an int parameter for
46 optval. For setsockopt, the parameter should be non-zero
47 to enable a boolean option, or zero if the option is to be
50 For a description of the available socket options see
51 socket(7) and the appropriate protocol man pages.
54 On success, zero is returned. On error, -1 is returned,
55 and errno is set appropriately.
58 EBADF The argument s is not a valid descriptor.
61 The argument s is a file, not a socket.
64 The option is unknown at the level indicated.