Commit | Line | Data |
---|---|---|
efbcfcab KM |
1 | .\" Copyright (c) 1983 Regents of the University of California. |
2 | .\" All rights reserved. The Berkeley software License Agreement | |
3 | .\" specifies the terms and conditions for redistribution. | |
4 | .\" | |
a66e777a | 5 | .\" @(#)getsockopt.2 6.1 (Berkeley) %G% |
efbcfcab | 6 | .\" |
a66e777a | 7 | .TH GETSOCKOPT 2 "" |
efbcfcab KM |
8 | .UC 5 |
9 | .SH NAME | |
10 | getsockopt, setsockopt \- get and set options on sockets | |
11 | .SH SYNOPSIS | |
12 | .nf | |
13 | .ft B | |
14 | #include <sys/types.h> | |
15 | #include <sys/socket.h> | |
16 | .PP | |
17 | .ft B | |
18 | getsockopt(s, level, optname, optval, optlen) | |
19 | int s, level, optname; | |
20 | char *optval; | |
21 | int *optlen; | |
22 | .sp | |
23 | setsockopt(s, level, optname, optval, optlen) | |
24 | int s, level, optname; | |
25 | char *optval; | |
26 | int optlen; | |
27 | .fi | |
28 | .SH DESCRIPTION | |
29 | .I Getsockopt | |
30 | and | |
31 | .I setsockopt | |
32 | manipulate | |
33 | .I options | |
34 | associated with a socket. Options may exist at multiple | |
35 | protocol levels; they are always present at the uppermost | |
36 | ``socket'' level. | |
37 | .PP | |
38 | When manipulating socket options the level at which the | |
39 | option resides and the name of the option must be specified. | |
40 | To manipulate options at the ``socket'' level, | |
41 | .I level | |
42 | is specified as SOL_SOCKET. To manipulate options at any | |
43 | other level the protocol number of the appropriate protocol | |
44 | controlling the option is supplied. For example, | |
45 | to indicate an option is to be interpreted by the TCP protocol, | |
46 | .I level | |
47 | should be set to the protocol number of TCP; see | |
48 | .IR getprotoent (3N). | |
49 | .PP | |
50 | The parameters | |
51 | .I optval | |
52 | and | |
53 | .I optlen | |
54 | are used to access option values for | |
55 | .IR setsockopt . | |
56 | For | |
57 | .I getsockopt | |
58 | they identify a buffer in which the value for the | |
59 | requested option(s) are to be returned. For | |
60 | .IR getsockopt , | |
61 | .I optlen | |
62 | is a value-result parameter, initially containing the | |
63 | size of the buffer pointed to by | |
64 | .IR optval , | |
65 | and modified on return to indicate the actual size of | |
66 | the value returned. If no option value is | |
67 | to be supplied or returned, | |
68 | .I optval | |
69 | may be supplied as 0. | |
70 | .PP | |
71 | .I Optname | |
72 | and any specified options are passed uninterpreted to the appropriate | |
73 | protocol module for interpretation. | |
74 | The include file | |
75 | .RI < sys/socket.h > | |
76 | contains definitions for ``socket'' level options; see | |
77 | .IR socket (2). | |
78 | Options at other protocol levels vary in format and | |
79 | name, consult the appropriate entries in (4P). | |
80 | .SH "RETURN VALUE" | |
81 | A 0 is returned if the call succeeds, \-1 if it fails. | |
82 | .SH ERRORS | |
83 | The call succeeds unless: | |
84 | .TP 20 | |
85 | [EBADF] | |
86 | The argument \fIs\fP is not a valid descriptor. | |
87 | .TP 20 | |
88 | [ENOTSOCK] | |
89 | The argument \fIs\fP is a file, not a socket. | |
90 | .TP 20 | |
91 | [ENOPROTOOPT] | |
92 | The option is unknown. | |
93 | .TP 20 | |
94 | [EFAULT] | |
95 | The options are not in a valid part of the | |
96 | process address space. | |
97 | .SH "SEE ALSO" | |
98 | socket(2), getprotoent(3N) |