1 .\" $OpenBSD: getsockopt.2,v 1.50 2016/06/13 21:24:43 bluhm Exp $
2 .\" $NetBSD: getsockopt.2,v 1.7 1995/02/27 12:33:29 cgd Exp $
4 .\" Copyright (c) 1983, 1991, 1993
5 .\" The Regents of the University of California. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)getsockopt.2 8.3 (Berkeley) 4/19/94
39 .Nd get and set options on sockets
43 .Fn getsockopt "int s" "int level" "int optname" "void *optval" "socklen_t *optlen"
45 .Fn setsockopt "int s" "int level" "int optname" "const void *optval" "socklen_t optlen"
52 associated with a socket.
53 Options may exist at multiple protocol levels;
54 they are always present at the uppermost
58 When manipulating socket options the level at which the
59 option resides and the name of the option must be specified.
60 To manipulate options at the socket level,
64 To manipulate options at any other level the protocol number of the
65 appropriate protocol controlling the option is supplied.
66 For example, to indicate that an option is to be interpreted by the
69 should be set to the protocol number of TCP; see
76 are used to access option values for
80 they identify a buffer in which the value for the
81 requested option(s) are to be returned.
85 is a value-result parameter, initially containing the
86 size of the buffer pointed to by
88 and modified on return to indicate the actual size of the value returned.
89 If no option value is to be supplied or returned,
95 and any specified options are passed uninterpreted to the appropriate
96 protocol module for interpretation.
99 contains definitions for socket level options, described below.
100 Options at other protocol levels vary in format and name.
101 consult the appropriate entries in section 7P of the manual.
103 Most socket-level options utilize an
109 the parameter should be non-zero to enable a boolean option,
110 or zero if the option is to be disabled.
114 parameter, defined in
116 which specifies the desired state of the option and the
117 linger interval (see below).
123 parameter, defined in
126 The following options are recognized at the socket level.
127 Except as noted, each may be examined with
132 .Bl -tag -width SO_OOBINLINE -offset indent -compact
134 enables recording of debugging information
136 enables local address reuse
138 enables keep connections alive
140 enables routing bypass for outgoing messages
142 linger on close if data present
144 enables permission to transmit broadcast messages
146 enables reception of out-of-band data in band
148 set buffer size for output
150 set buffer size for input
152 set timeout value for output
154 set timeout value for input
156 enables reception of a timestamp with datagrams
157 .It Dv SO_DGRAM_ERRIND
158 application wants delayed error
160 enables exclusive binding of the socket
162 bypass zone boundaries (privileged)
164 get the type of the socket (get only)
166 get and clear error on the socket (get only)
168 get the domain used in the socket (get only)
170 get the protocol type of the socket (get only)
174 enables debugging in the underlying protocol modules.
176 indicates that the rules used in validating addresses supplied in a
178 call should allow reuse of local addresses.
180 enables the periodic transmission of messages on a connected socket.
181 Should the connected party fail to respond to these messages, the connection
182 is considered broken and processes using the socket are notified via a
184 signal when attempting to send data.
187 option indicates that outgoing messages should bypass the standard
188 routing facilities. Messages are directed to the appropriate network
189 interface according to the destination address.
192 controls the action taken when unsent messages
193 are queued on socket and a
196 If the socket promises reliable delivery of data and
198 is set, the system will block the process on the
200 attempt until it is able to transmit the data or until it decides it
201 is unable to deliver the information (a timeout period measured in seconds,
202 termed the linger interval, is specified in the
211 is issued, the system will process the close in a manner that allows
212 the process to continue as quickly as possible.
216 requests permission to send broadcast datagrams
218 Broadcast was a privileged operation in earlier versions of the system.
219 With protocols that support out-of-band data, the
221 option requests that out-of-band data be placed in the normal data input
222 queue as received; it will then be accessible with
229 Some protocols always behave as if this option is set.
234 are options to adjust the normal
235 buffer sizes allocated for output and input buffers, respectively.
236 The buffer size may be increased for high-volume connections,
237 or may be decreased to limit the possible backlog of incoming data.
238 The system places an absolute limit on these values.
241 is an option to set a timeout value for output operations.
244 parameter with the number of seconds and microseconds
245 used to limit waits for output operations to complete.
246 If a send operation has blocked for this much time,
247 it returns with a partial count or with the error
250 In the current implementation, this timer is restarted each time additional
251 data are delivered to the protocol,
252 implying that the limit applies to output portions ranging in size
253 from the low water mark to the high water mark for output.
255 is an option to set a timeout value for input operations.
258 parameter with the number of seconds and microseconds
259 used to limit waits for input operations to complete.
260 In the current implementation, this timer is restarted each time additional
261 data are received by the protocol,
262 and thus the limit is in effect an inactivity timer.
263 If a receive operation has been blocked for this much time without
264 receiving additional data, it returns with a short count
267 if no data were received.
271 option is enabled on a
275 call will return a timestamp corresponding to when the datagram was
277 The msg_control field in the msghdr structure points to a buffer
278 that contains a cmsghdr structure followed by a struct timeval.
279 The cmsghdr fields have the following values:
280 .Bd -literal -offset indent
281 cmsg_len = CMSG_LEN(sizeof(struct timeval))
282 cmsg_level = SOL_SOCKET
283 cmsg_type = SCM_TIMESTAMP
288 is set, certain delayed errors (such as ICMP port unreachable packets)
289 received after completion of
293 will cause a subsequent
297 with the same destination address to fail with the appropriate error.
300 enables the exclusive binding of a socket, overriding the use of
302 The actual semantics of
304 depend on the underlying protocol; see
308 for more information.
311 can be used to bypass zone boundaries between shared-IP zones.
312 Normally, the system prevents a socket from being bound to an address
313 that is not assigned to the current zone. It also prevents a socket
314 that is bound to a wildcard address from receiving traffic for other
315 zones. However, some daemons which run in the global zone might need
316 to send and receive traffic using addresses that belong to other
317 shared-IP zones. If set before a socket is bound,
319 causes the socket to ignore zone boundaries between shared-IP zones
320 and permits the socket to be bound to any address assigned to the
321 shared-IP zones. If the socket is bound to a wildcard address, it
322 receives traffic intended for all shared-IP zones and behaves as if an
323 equivalent socket were bound in each active shared-IP zone.
324 Applications that use the
326 option to initiate connections or send datagram traffic should specify
327 the source address for outbound traffic by binding to a specific
328 address. There is no effect from setting this option in an
329 exclusive-IP zone. Setting this option requires the
340 are options used only with
343 returns the type of the socket, such as
345 it is useful for servers that inherit sockets on startup.
347 returns any pending error on the socket and clears the error status.
348 It may be used to check for asynchronous errors on connected
349 datagram sockets or for other asynchronous errors.
351 returns the address family of the socket, such as
354 returns the underlying protocol number for the socket if it is in the
358 domains, or the address family used if the socket is in the
364 The call succeeds unless:
369 is not a valid descriptor.
373 is a file, not a socket.
374 .It Bq Er ENOPROTOOPT
375 The option is unknown at the level indicated.
377 The option is unsupported.
379 The address pointed to by
381 is not in a valid part of the process address space.
384 this error may also be returned if
386 is not in a valid part of the process address space.
388 Insufficient resources are available in the system to complete the
390 .It Bq Er ENOPROTOOPT
391 The option is unknown at the level indicated.
393 The specified option is invalid at the specified socket level or the
394 socket has been shut down.
396 The calling process does not have the appropriate privileges.
419 system call appeared in
422 Several of the socket options should be handled at lower levels of the system.