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