summaryrefslogtreecommitdiff
path: root/usr/src/man/man3xnet/getsockopt.3xnet
blob: 8bd3fd7bb45bf46fa114256fefb734fc97d663dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document.  The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
.\" Portions Copyright (c) 2007, Sun Microsystems, Inc.  All Rights Reserved.
.\"
.TH GETSOCKOPT 3XNET "Jan 21, 2007"
.SH NAME
getsockopt \- get the socket options
.SH SYNOPSIS
.LP
.nf
\fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB-lxnet\fR [ \fIlibrary\fR... ]
#include <sys/socket.h>

\fBint\fR \fBgetsockopt\fR(\fBint\fR \fIsocket\fR, \fBint\fR \fIlevel\fR, \fBint\fR \fIoption_name\fR,
     \fBvoid *restrict\fR \fIoption_value\fR, \fBsocklen_t *restrict\fR \fIoption_len\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBgetsockopt()\fR function retrieves the value for the option specified by
the \fIoption_name\fR argument for the socket specified by the \fIsocket\fR
argument. If the size of the option value is greater than \fIoption_len\fR, the
value stored in the object pointed to by the \fIoption_value\fR argument will
be silently truncated. Otherwise, the object pointed to by the \fIoption_len\fR
argument will be modified to indicate the actual length of the value.
.sp
.LP
The \fIlevel\fR argument specifies the protocol level at which the option
resides.  To retrieve options at the socket level, specify the \fIlevel\fR
argument as \fBSOL_SOCKET\fR. To retrieve options at other levels, supply the
appropriate protocol number for the protocol controlling the option. For
example, to indicate that an option will be interpreted by the \fBTCP\fR
(Transport Control Protocol), set \fIlevel\fR to the protocol number of
\fBTCP\fR, as defined in the <\fBnetinet/in.h\fR> header, or as determined by
using \fBgetprotobyname\fR(3XNET) function.
.sp
.LP
The socket in use might require the process to have appropriate privileges to
use the \fBgetsockopt()\fR function.
.sp
.LP
The \fIoption_name\fR argument specifies a single option to be retrieved.  It
can be one of the following values defined in \fB<sys/socket.h>\fR:
.sp
.ne 2
.na
\fB\fBSO_DEBUG\fR\fR
.ad
.RS 17n
Reports whether debugging information is being recorded. This option stores an
\fBint\fR value. This is a boolean option.
.RE

.sp
.ne 2
.na
\fB\fBSO_ACCEPTCONN\fR\fR
.ad
.RS 17n
Reports whether socket listening is enabled. This option stores an \fBint\fR
value.
.RE

.sp
.ne 2
.na
\fB\fBSO_BROADCAST\fR\fR
.ad
.RS 17n
Reports whether transmission of broadcast messages is supported, if this is
supported by the protocol. This option stores an \fBint\fR value. This is a
boolean option.
.RE

.sp
.ne 2
.na
\fB\fBSO_REUSEADDR\fR\fR
.ad
.RS 17n
Reports whether the rules used in validating addresses supplied to
\fBbind\fR(3XNET) should allow reuse of local addresses, if this is supported
by the protocol. This option stores an \fBint\fR value. This is a boolean
option.
.RE

.sp
.ne 2
.na
\fB\fBSO_KEEPALIVE\fR\fR
.ad
.RS 17n
Reports whether connections are kept active with periodic transmission of
messages, if this is supported by the protocol.
.sp
If the connected socket fails to respond to these messages, the connection is
broken and threads writing to that socket are notified with a \fBSIGPIPE\fR
signal. This option stores an \fBint\fR value.
.sp
This is a boolean option.
.RE

.sp
.ne 2
.na
\fB\fBSO_LINGER\fR\fR
.ad
.RS 17n
Reports whether the socket lingers on \fBclose\fR(2) if data is present. If
\fBSO_LINGER\fR is set, the system blocks the process during \fBclose\fR(2)
until it can transmit the data or until the end of the interval indicated by
the \fBl_linger\fR member, whichever comes first. If \fBSO_LINGER\fR is not
specified, and \fBclose\fR(2) is issued, the system handles the call in a way
that allows the process to continue as quickly as possible. This option stores
a \fBlinger\fR structure.
.RE

.sp
.ne 2
.na
\fB\fBSO_OOBINLINE\fR\fR
.ad
.RS 17n
Reports whether the socket leaves received out-of-band data (data marked
urgent) in line. This option stores an \fBint\fR value. This is a boolean
option.
.RE

.sp
.ne 2
.na
\fB\fBSO_SNDBUF\fR\fR
.ad
.RS 17n
Reports send buffer size information. This option stores an \fBint\fR value.
.RE

.sp
.ne 2
.na
\fB\fBSO_RCVBUF\fR\fR
.ad
.RS 17n
Reports receive buffer size information. This option stores an \fBint\fR value.
.RE

.sp
.ne 2
.na
\fB\fBSO_ERROR\fR\fR
.ad
.RS 17n
Reports information about error status and clears it. This option stores an
\fBint\fR value.
.RE

.sp
.ne 2
.na
\fB\fBSO_TYPE\fR\fR
.ad
.RS 17n
Reports the socket type. This option stores an \fBint\fR value.
.RE

.sp
.ne 2
.na
\fB\fBSO_DONTROUTE\fR\fR
.ad
.RS 17n
Reports whether outgoing messages bypass the standard routing facilities. The
destination must be on a directly-connected network, and messages are directed
to the appropriate network interface according to the destination address. The
effect, if any, of this option depends on what protocol is in use. This option
stores an \fBint\fR value. This is a boolean option.
.RE

.sp
.ne 2
.na
\fB\fBSO_MAC_EXEMPT\fR\fR
.ad
.RS 17n
Gets the mandatory access control status of the socket. A socket that has this
option enabled can communicate with an unlabeled peer if the socket is in the
global zone or has a label that dominates the default label of the peer.
Otherwise, the socket must have a label that is equal to the default label of
the unlabeled peer. \fB\fR\fBSO_MAC_EXEMPT\fR is a boolean option that is
available only when the system is configured with Trusted Extensions.
.RE

.sp
.ne 2
.na
\fB\fBSO_ALLZONES\fR\fR
.ad
.RS 17n
Bypasses zone boundaries (privileged). This option stores an \fBint\fR value.
This is a boolean option.
.sp
The \fBSO_ALLZONES\fR option can be used to bypass zone boundaries between
shared-IP zones. Normally, the system prevents a socket from being bound to an
address that is not assigned to the current zone. It also prevents a socket
that is bound to a wildcard address from receiving traffic for other zones.
However, some daemons which run in the global zone might need to send and
receive traffic using addresses that belong to other shared-IP zones. If set
before a socket is bound, \fBSO_ALLZONES\fR causes the socket to ignore zone
boundaries between shared-IP zones and permits the socket to be bound to any
address assigned to the shared-IP zones. If the socket is bound to a wildcard
address, it receives traffic intended for all shared-IP zones and behaves as if
an equivalent socket were bound in each active shared-IP zone. Applications
that use the \fBSO_ALLZONES\fR option to initiate connections or send datagram
traffic should specify the source address for outbound traffic by binding to a
specific address. There is no effect from setting this option in an
exclusive-IP zone. Setting this option requires the \fBsys_net_config\fR
privilege. See \fBzones\fR(5).
.RE

.sp
.ne 2
.na
\fB\fBSO_DOMAIN\fR\fR
.ad
.RS 17n
get the domain used in the socket (get only)
.RE

.sp
.ne 2
.na
\fB\fBSO_PROTOTYPE\fR\fR
.ad
.RS 17n
for socket in domains \fBAF_INET\fR and \fBAF_INET6\fR, get the underlying
protocol number used in the socket. For socket in domain \fBAF_ROUTE\fR, get
the address family used in the socket.
.RE

.sp
.LP
For boolean options, a zero value indicates that the option is disabled and a
non-zero value indicates that the option is enabled.
.sp
.LP
Options at other protocol levels vary in format and name.
.sp
.LP
The socket in use may require the process to have appropriate privileges to use
the \fBgetsockopt()\fR function.
.SH RETURN VALUES
.sp
.LP
Upon successful completion, \fBgetsockopt()\fR returns \fB0\fR. Otherwise,
\fB\(mi1\fR is returned and \fBerrno\fR is set to indicate the error.
.SH ERRORS
.sp
.LP
The \fBgetsockopt()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEBADF\fR\fR
.ad
.RS 15n
The \fIsocket\fR argument is not a valid file descriptor.
.RE

.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 15n
The \fIoption_value\fR or \fIoption_len\fR parameter can not be accessed or
written.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 15n
The specified option is invalid at the specified socket level.
.RE

.sp
.ne 2
.na
\fB\fBENOPROTOOPT\fR\fR
.ad
.RS 15n
The option is not supported by the protocol.
.RE

.sp
.ne 2
.na
\fB\fBENOTSOCK\fR\fR
.ad
.RS 15n
The \fIsocket\fR argument does not refer to a socket.
.RE

.sp
.LP
The \fBgetsockopt()\fR function may fail if:
.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 11n
The calling process does not have the appropriate privileges.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 11n
The socket has been shut down.
.RE

.sp
.ne 2
.na
\fB\fBENOBUFS\fR\fR
.ad
.RS 11n
Insufficient resources are available in the system to complete the call.
.RE

.sp
.ne 2
.na
\fB\fBENOSR\fR\fR
.ad
.RS 11n
There were insufficient STREAMS resources available for the operation to
complete.
.RE

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Standard
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.sp
.LP
\fBclose\fR(2), \fBbind\fR(3XNET), \fBendprotoent\fR(3XNET),
\fBsetsockopt\fR(3XNET), \fBsocket\fR(3XNET), \fBattributes\fR,
\fBstandards\fR(5)