1 |
1254 |
phoenix |
NAME
|
2 |
|
|
getsockopt, setsockopt - get and set options on sockets
|
3 |
|
|
|
4 |
|
|
SYNOPSIS
|
5 |
|
|
#include <network.h>
|
6 |
|
|
|
7 |
|
|
int getsockopt(int s, int level, int optname, void *opt
|
8 |
|
|
val, socklen_t *optlen);
|
9 |
|
|
|
10 |
|
|
int setsockopt(int s, int level, int optname, const void
|
11 |
|
|
*optval, socklen_t optlen);
|
12 |
|
|
|
13 |
|
|
DESCRIPTION
|
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
|
17 |
|
|
socket level.
|
18 |
|
|
|
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).
|
28 |
|
|
|
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.
|
37 |
|
|
|
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.
|
44 |
|
|
|
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
|
48 |
|
|
disabled.
|
49 |
|
|
|
50 |
|
|
For a description of the available socket options see
|
51 |
|
|
socket(7) and the appropriate protocol man pages.
|
52 |
|
|
|
53 |
|
|
RETURN VALUE
|
54 |
|
|
On success, zero is returned. On error, -1 is returned,
|
55 |
|
|
and errno is set appropriately.
|
56 |
|
|
|
57 |
|
|
ERRORS
|
58 |
|
|
EBADF The argument s is not a valid descriptor.
|
59 |
|
|
|
60 |
|
|
ENOTSOCK
|
61 |
|
|
The argument s is a file, not a socket.
|
62 |
|
|
|
63 |
|
|
ENOPROTOOPT
|
64 |
|
|
The option is unknown at the level indicated.
|
65 |
|
|
|
66 |
|
|
|