]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (c) 1983, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
12 | .\" 3. All advertising materials mentioning features or use of this software | |
13 | .\" must display the following acknowledgement: | |
14 | .\" This product includes software developed by the University of | |
15 | .\" California, Berkeley and its contributors. | |
16 | .\" 4. Neither the name of the University nor the names of its contributors | |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
32 | .\" $Id: getsockopt.2,v 1.1 1999/05/24 14:57:04 freitag Exp $ | |
33 | .\" | |
34 | .\" Modified Sat Jul 24 16:19:32 1993 by Rik Faith (faith@cs.unc.edu) | |
35 | .\" Modified Mon Apr 22 02:29:06 1996 by Martin Schulze (joey@infodrom.north.de) | |
36 | .\" Modified Tue Aug 27 10:52:51 1996 by Andries Brouwer (aeb@cwi.nl) | |
37 | .\" Modified Thu Jan 23 13:29:34 1997 by Andries Brouwer (aeb@cwi.nl) | |
38 | .\" Modified Sun Mar 28 21:26:46 1999 by Andries Brouwer (aeb@cwi.nl) | |
c13182ef | 39 | .\" Modified 1999 by Andi Kleen <ak@muc.de>. |
35478399 | 40 | .\" Removed most stuff because it is in socket.7 now. |
fea681da MK |
41 | .\" |
42 | .TH GETSOCKOPT 2 1999-05-24 "Linux Man Page" "Linux Programmer's Manual" | |
43 | .SH NAME | |
44 | getsockopt, setsockopt \- get and set options on sockets | |
45 | .SH SYNOPSIS | |
521bf584 | 46 | .nf |
fea681da MK |
47 | .B #include <sys/types.h> |
48 | .br | |
49 | .B #include <sys/socket.h> | |
521bf584 | 50 | .sp |
fea681da | 51 | .BI "int getsockopt(int " s ", int " level ", int " optname , |
521bf584 | 52 | .BI " void *" optval ", socklen_t *" optlen ); |
fea681da MK |
53 | .sp |
54 | .BI "int setsockopt(int " s ", int " level ", int " optname , | |
521bf584 MK |
55 | .BI " const void *" optval ", socklen_t " optlen ); |
56 | .fi | |
fea681da | 57 | .SH DESCRIPTION |
7145b9a9 | 58 | .BR getsockopt () |
fea681da | 59 | and |
e511ffb6 | 60 | .BR setsockopt () |
fea681da MK |
61 | manipulate the |
62 | .I options | |
c13182ef MK |
63 | associated with a socket. |
64 | Options may exist at multiple | |
fea681da MK |
65 | protocol levels; they are always present at the uppermost |
66 | .B socket | |
67 | level. | |
68 | ||
69 | When manipulating socket options the level at which the | |
70 | option resides and the name of the option must be specified. | |
71 | To manipulate options at the socket level, | |
72 | .I level | |
73 | is specified as | |
74 | .BR SOL_SOCKET . | |
75 | To manipulate options at any | |
76 | other level the protocol number of the appropriate protocol | |
c13182ef MK |
77 | controlling the option is supplied. |
78 | For example, | |
fea681da MK |
79 | to indicate that an option is to be interpreted by the |
80 | .B TCP | |
81 | protocol, | |
82 | .I level | |
83 | should be set to the protocol number of | |
84 | .BR TCP ; | |
85 | see | |
86 | .BR getprotoent (3). | |
87 | ||
88 | The parameters | |
89 | .I optval | |
90 | and | |
91 | .I optlen | |
92 | are used to access option values for | |
e511ffb6 | 93 | .BR setsockopt (). |
fea681da | 94 | For |
e511ffb6 | 95 | .BR getsockopt () |
fea681da | 96 | they identify a buffer in which the value for the |
c13182ef MK |
97 | requested option(s) are to be returned. |
98 | For | |
e511ffb6 | 99 | .BR getsockopt (), |
fea681da MK |
100 | .I optlen |
101 | is a value-result parameter, initially containing the | |
102 | size of the buffer pointed to by | |
103 | .IR optval , | |
104 | and modified on return to indicate the actual size of | |
c13182ef MK |
105 | the value returned. |
106 | If no option value is to be supplied or returned, | |
fea681da MK |
107 | .I optval |
108 | may be NULL. | |
109 | ||
110 | .I Optname | |
111 | and any specified options are passed uninterpreted to the appropriate | |
c13182ef MK |
112 | protocol module for interpretation. |
113 | The include file | |
fea681da | 114 | .I <sys/socket.h> |
c13182ef MK |
115 | contains definitions for socket level options, described below. |
116 | Options at | |
fea681da MK |
117 | other protocol levels vary in format and name; consult the appropriate |
118 | entries in section 4 of the manual. | |
119 | ||
120 | Most socket-level options utilize an | |
121 | .I int | |
122 | parameter for | |
123 | .IR optval . | |
124 | For | |
e511ffb6 | 125 | .BR setsockopt (), |
fea681da MK |
126 | the parameter should be non-zero to enable a boolean option, or zero if the |
127 | option is to be disabled. | |
fea681da MK |
128 | .PP |
129 | For a description of the available socket options see | |
130 | .BR socket (7) | |
131 | and the appropriate protocol man pages. | |
fea681da | 132 | .SH "RETURN VALUE" |
c13182ef MK |
133 | On success, zero is returned. |
134 | On error, \-1 is returned, and | |
fea681da MK |
135 | .I errno |
136 | is set appropriately. | |
137 | .SH ERRORS | |
138 | .TP 10 | |
139 | .B EBADF | |
140 | The argument | |
141 | .I s | |
142 | is not a valid descriptor. | |
143 | .TP | |
144 | .B EFAULT | |
c13182ef | 145 | The address pointed to by |
fea681da | 146 | .I optval |
c13182ef MK |
147 | is not in a valid part of the process address space. |
148 | For | |
e511ffb6 | 149 | .BR getsockopt (), |
fea681da MK |
150 | this error may also be returned if |
151 | .I optlen | |
152 | is not in a valid part of the process address space. | |
153 | .TP | |
154 | .B EINVAL | |
155 | .I optlen | |
c13182ef | 156 | invalid in |
1e321034 | 157 | .BR setsockopt (). |
fea681da MK |
158 | .TP |
159 | .B ENOPROTOOPT | |
160 | The option is unknown at the level indicated. | |
161 | .TP | |
162 | .B ENOTSOCK | |
163 | The argument | |
164 | .I s | |
165 | is a file, not a socket. | |
166 | .SH "CONFORMING TO" | |
c13182ef | 167 | SVr4, 4.4BSD (these system calls first appeared in 4.2BSD), |
bc07c514 | 168 | POSIX.1-2001. |
97c1eac8 | 169 | .\" SVr4 documents additional ENOMEM and ENOSR error codes, but does |
c13182ef | 170 | .\" not document the |
97c1eac8 MK |
171 | .\" .BR SO_SNDLOWAT ", " SO_RCVLOWAT ", " SO_SNDTIMEO ", " SO_RCVTIMEO |
172 | .\" options | |
fea681da | 173 | .SH NOTE |
c13182ef | 174 | The |
97c1eac8 | 175 | .I optlen |
c13182ef | 176 | argument of |
fea681da | 177 | .BR getsockopt " and " setsockopt |
c13182ef | 178 | is in reality an |
97c1eac8 MK |
179 | .I "int [*]" |
180 | (and this is what 4.x BSD and libc4 and libc5 have). | |
c13182ef MK |
181 | Some POSIX confusion resulted in the present |
182 | .IR socklen_t , | |
97c1eac8 | 183 | also used by glibc. |
fea681da MK |
184 | See also |
185 | .BR accept (2). | |
186 | .SH BUGS | |
187 | Several of the socket options should be handled at lower levels of the | |
188 | system. | |
189 | .SH "SEE ALSO" | |
190 | .BR ioctl (2), | |
191 | .BR socket (2), | |
192 | .BR getprotoent (3), | |
193 | .BR protocols (5), | |
194 | .BR socket (7), | |
195 | .BR tcp (7), | |
196 | .BR unix (7) |