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