1 .\" $NetBSD: getsockopt.2,v 1.7 1995/02/27 12:33:29 cgd Exp $
3 .\" Copyright (c) 1983, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)getsockopt.2 8.3 (Berkeley) 4/19/94
42 .Nd get and set options on sockets
44 .Fd #include <sys/socket.h>
50 .Fa "void *restrict option_value"
51 .Fa "socklen_t *restrict option_len"
58 .Fa "const void *option_value"
59 .Fa "socklen_t option_len"
67 associated with a socket. Options may exist at multiple
68 protocol levels; they are always present at the uppermost
72 When manipulating socket options the level at which the
73 option resides and the name of the option must be specified.
74 To manipulate options at the socket level,
78 To manipulate options at any
79 other level the protocol number of the appropriate protocol
80 controlling the option is supplied. For example,
81 to indicate that an option is to be interpreted by the
85 should be set to the protocol number of
94 are used to access option values for
98 they identify a buffer in which the value for the
99 requested option(s) are to be returned. For
102 is a value-result parameter, initially containing the
103 size of the buffer pointed to by
105 and modified on return to indicate the actual size of
106 the value returned. If no option value is
107 to be supplied or returned,
112 and any specified options are passed uninterpreted to the appropriate
113 protocol module for interpretation.
115 .Ao Pa sys/socket.h Ac
116 contains definitions for
117 socket level options, described below.
118 Options at other protocol levels vary in format and
119 name; consult the appropriate entries in
123 Most socket-level options utilize an
129 the parameter should be non-zero to enable a boolean option,
130 or zero if the option is to be disabled.
134 parameter, defined in
135 .Ao Pa sys/socket.h Ac ,
136 which specifies the desired state of the option and the
137 linger interval (see below).
143 parameter, defined in
144 .Ao Pa sys/time.h Ac .
146 The following options are recognized at the socket level.
147 Except as noted, each may be examined with
151 .Bl -column SO_OOBINLINE -offset indent
152 .It Dv SO_DEBUG Ta "enables recording of debugging information"
153 .It Dv SO_REUSEADDR Ta "enables local address reuse"
154 .It Dv SO_REUSEPORT Ta "enables duplicate address and port bindings"
155 .It Dv SO_KEEPALIVE Ta "enables keep connections alive"
156 .It Dv SO_DONTROUTE Ta "enables routing bypass for outgoing messages"
157 .It Dv SO_LINGER Ta "linger on close if data present"
158 .It Dv SO_BROADCAST Ta "enables permission to transmit broadcast messages"
159 .It Dv SO_OOBINLINE Ta "enables reception of out-of-band data in band"
160 .It Dv SO_SNDBUF Ta "set buffer size for output"
161 .It Dv SO_RCVBUF Ta "set buffer size for input"
162 .It Dv SO_SNDLOWAT Ta "set minimum count for output"
163 .It Dv SO_RCVLOWAT Ta "set minimum count for input"
164 .It Dv SO_SNDTIMEO Ta "set timeout value for output"
165 .It Dv SO_RCVTIMEO Ta "set timeout value for input"
166 .It Dv SO_TYPE Ta "get the type of the socket (get only)"
167 .It Dv SO_ERROR Ta "get and clear error on the socket (get only)"
168 .It Dv SO_NOSIGPIPE Ta "do not generate SIGPIPE, instead return EPIPE"
172 enables debugging in the underlying protocol modules.
174 indicates that the rules used in validating addresses supplied
177 call should allow reuse of local addresses.
179 allows completely duplicate bindings by multiple processes
182 before binding the port.
183 This option permits multiple instances of a program to each
184 receive UDP/IP multicast or broadcast datagrams destined for the bound port.
187 periodic transmission of messages on a connected socket. Should the
188 connected party fail to respond to these messages, the connection is
189 considered broken and processes using the socket are notified via a
191 signal when attempting to send data.
193 indicates that outgoing messages should
194 bypass the standard routing facilities. Instead, messages are directed
195 to the appropriate network interface according to the network portion
196 of the destination address.
199 controls the action taken when unsent messages
200 are queued on socket and a
203 If the socket promises reliable delivery of data and
204 .Dv SO_LINGER is set,
205 the system will block the process on the
207 attempt until it is able to transmit the data or until it decides it
208 is unable to deliver the information (a timeout period, termed the
209 linger interval, is specified in the
218 is issued, the system will process the close in a manner that allows
219 the process to continue as quickly as possible.
223 requests permission to send broadcast datagrams
225 Broadcast was a privileged operation in earlier versions of the system.
226 With protocols that support out-of-band data, the
229 requests that out-of-band data be placed in the normal data input queue
230 as received; it will then be accessible with
237 Some protocols always behave as if this option is set.
241 are options to adjust the normal
242 buffer sizes allocated for output and input buffers, respectively.
243 The buffer size may be increased for high-volume connections,
244 or may be decreased to limit the possible backlog of incoming data.
245 The system places an absolute limit on these values.
248 is an option to set the minimum count for output operations.
249 Most output operations process all of the data supplied by the call,
250 delivering data to the protocol for transmission
251 and blocking as necessary for flow control.
252 Nonblocking output operations will process as much data as permitted
253 (subject to flow control) without blocking,
254 but will process no data if flow control
255 does not allow the smaller of the low-water mark value
256 or the entire request to be processed.
259 operation testing the ability to write to a socket will return true
260 only if the low-water mark amount could be processed.
261 The default value for
263 is set to a convenient size for network efficiency, often 1024.
266 is an option to set the minimum count for input operations.
267 In general, receive calls will block until any (non-zero) amount of data
268 is received, then return with the smaller of the amount available
269 or the amount requested.
270 The default value for
275 is set to a larger value, blocking receive calls
276 normally wait until they have received the smaller
277 of the low-water mark value or the requested amount.
278 Receive calls may still return less than the low-water mark
279 if an error occurs, a signal is caught,
280 or the type of data next in the receive queue
281 is different than that returned.
284 is an option to set a timeout value for output operations.
287 parameter with the number of seconds and microseconds
288 used to limit waits for output operations to complete.
289 If a send operation has blocked for this much time,
290 it returns with a partial count
293 if no data were sent.
294 In the current implementation, this timer is restarted each time additional
295 data are delivered to the protocol,
296 implying that the limit applies to output portions ranging in size
297 from the low-water mark to the high-water mark for output.
300 is an option to set a timeout value for input operations.
303 parameter with the number of seconds and microseconds
304 used to limit waits for input operations to complete.
305 In the current implementation, this timer is restarted each time additional
306 data are received by the protocol,
307 and thus the limit is in effect an inactivity timer.
308 If a receive operation has been blocked for this much time without
309 receiving additional data, it returns with a short count
312 if no data were received.
313 The struct timeval parameter must represent a positive time interval;
316 returns with the error
319 .Dv SO_NOSIGPIPE is an option that prevents SIGPIPE from being raised
320 when a write fails on a socket to which there is no reader;
321 instead, the write to the socket returns with the error
323 when there is no reader.
329 are options used only with
332 returns the type of the socket, such as
334 it is useful for servers that inherit sockets on startup.
336 returns any pending error on the socket and clears
338 It may be used to check for asynchronous errors on connected
339 datagram sockets or for other asynchronous errors.
347 system calls will succeed unless:
353 is not a valid file descriptor.
356 The address pointed to by
358 is not in a valid part of the process address space.
361 this error may also be returned if
363 is not in a valid part of the process address space.
366 The option is invalid at the level indicated.
369 Insufficient memory buffers are available.
371 .It Bq Er ENOPROTOOPT
372 The option is unknown at the level indicated.
377 is not a socket (e.g., a plain file).
382 system call will succeed unless:
393 and a specified option cannot be set
394 while this is the case.
397 .Fd #include <sys/types.h>
398 .Fd #include <sys/socket.h>
409 Several of the socket options should be handled at lower levels of the system.
413 system call appeared in