1getsockopt(3XNET)X/Open Networking Services Library Functionsgetsockopt(3XNET)
2
3
4
6 getsockopt - get the socket options
7
9 cc [ flag... ] file... -lxnet [ library... ]
10 #include <sys/socket.h>
11
12 int getsockopt(int socket, int level, int option_name,
13 void *restrict option_value, socklen_t *restrict option_len);
14
15
17 The getsockopt() function retrieves the value for the option specified
18 by the option_name argument for the socket specified by the socket
19 argument. If the size of the option value is greater than option_len,
20 the value stored in the object pointed to by the option_value argument
21 will be silently truncated. Otherwise, the object pointed to by the
22 option_len argument will be modified to indicate the actual length of
23 the value.
24
25
26 The level argument specifies the protocol level at which the option
27 resides. To retrieve options at the socket level, specify the level
28 argument as SOL_SOCKET. To retrieve options at other levels, supply the
29 appropriate protocol number for the protocol controlling the option.
30 For example, to indicate that an option will be interpreted by the TCP
31 (Transport Control Protocol), set level to the protocol number of TCP,
32 as defined in the <netinet/in.h> header, or as determined by using get‐
33 protobyname(3XNET) function.
34
35
36 The socket in use might require the process to have appropriate privi‐
37 leges to use the getsockopt() function.
38
39
40 The option_name argument specifies a single option to be retrieved. It
41 can be one of the following values defined in <sys/socket.h>:
42
43 SO_DEBUG Reports whether debugging information is being
44 recorded. This option stores an int value. This is a
45 boolean option.
46
47
48 SO_ACCEPTCONN Reports whether socket listening is enabled. This
49 option stores an int value.
50
51
52 SO_BROADCAST Reports whether transmission of broadcast messages is
53 supported, if this is supported by the protocol. This
54 option stores an int value. This is a boolean option.
55
56
57 SO_REUSEADDR Reports whether the rules used in validating addresses
58 supplied to bind(3XNET) should allow reuse of local
59 addresses, if this is supported by the protocol. This
60 option stores an int value. This is a boolean option.
61
62
63 SO_KEEPALIVE Reports whether connections are kept active with peri‐
64 odic transmission of messages, if this is supported by
65 the protocol.
66
67 If the connected socket fails to respond to these mes‐
68 sages, the connection is broken and threads writing to
69 that socket are notified with a SIGPIPE signal. This
70 option stores an int value.
71
72 This is a boolean option.
73
74
75 SO_LINGER Reports whether the socket lingers on close(2) if data
76 is present. If SO_LINGER is set, the system blocks the
77 process during close(2) until it can transmit the data
78 or until the end of the interval indicated by the
79 l_linger member, whichever comes first. If SO_LINGER
80 is not specified, and close(2) is issued, the system
81 handles the call in a way that allows the process to
82 continue as quickly as possible. This option stores a
83 linger structure.
84
85
86 SO_OOBINLINE Reports whether the socket leaves received out-of-band
87 data (data marked urgent) in line. This option stores
88 an int value. This is a boolean option.
89
90
91 SO_SNDBUF Reports send buffer size information. This option
92 stores an int value.
93
94
95 SO_RCVBUF Reports receive buffer size information. This option
96 stores an int value.
97
98
99 SO_ERROR Reports information about error status and clears it.
100 This option stores an int value.
101
102
103 SO_TYPE Reports the socket type. This option stores an int
104 value.
105
106
107 SO_DONTROUTE Reports whether outgoing messages bypass the standard
108 routing facilities. The destination must be on a
109 directly-connected network, and messages are directed
110 to the appropriate network interface according to the
111 destination address. The effect, if any, of this
112 option depends on what protocol is in use. This option
113 stores an int value. This is a boolean option.
114
115
116 SO_MAC_EXEMPT Gets the mandatory access control status of the
117 socket. A socket that has this option enabled can com‐
118 municate with an unlabeled peer if the socket is in
119 the global zone or has a label that dominates the
120 default label of the peer. Otherwise, the socket must
121 have a label that is equal to the default label of the
122 unlabeled peer. SO_MAC_EXEMPT is a boolean option that
123 is available only when the system is configured with
124 Trusted Extensions.
125
126
127 SO_ALLZONES Bypasses zone boundaries (privileged). This option
128 stores an int value. This is a boolean option.
129
130 The SO_ALLZONES option can be used to bypass zone
131 boundaries between shared-IP zones. Normally, the sys‐
132 tem prevents a socket from being bound to an address
133 that is not assigned to the current zone. It also pre‐
134 vents a socket that is bound to a wildcard address
135 from receiving traffic for other zones. However, some
136 daemons which run in the global zone might need to
137 send and receive traffic using addresses that belong
138 to other shared-IP zones. If set before a socket is
139 bound, SO_ALLZONES causes the socket to ignore zone
140 boundaries between shared-IP zones and permits the
141 socket to be bound to any address assigned to the
142 shared-IP zones. If the socket is bound to a wildcard
143 address, it receives traffic intended for all shared-
144 IP zones and behaves as if an equivalent socket were
145 bound in each active shared-IP zone. Applications that
146 use the SO_ALLZONES option to initiate connections or
147 send datagram traffic should specify the source
148 address for outbound traffic by binding to a specific
149 address. There is no effect from setting this option
150 in an exclusive-IP zone. Setting this option requires
151 the sys_net_config privilege. See zones(5).
152
153
154 SO_DOMAIN get the domain used in the socket (get only)
155
156
157 SO_PROTOTYPE for socket in domains AF_INET and AF_INET6, get the
158 underlying protocol number used in the socket. For
159 socket in domain AF_ROUTE, get the address family used
160 in the socket.
161
162
163
164 For boolean options, a zero value indicates that the option is disabled
165 and a non-zero value indicates that the option is enabled.
166
167
168 Options at other protocol levels vary in format and name.
169
170
171 The socket in use may require the process to have appropriate privi‐
172 leges to use the getsockopt() function.
173
175 Upon successful completion, getsockopt() returns 0. Otherwise, −1 is
176 returned and errno is set to indicate the error.
177
179 The getsockopt() function will fail if:
180
181 EBADF The socket argument is not a valid file descriptor.
182
183
184 EFAULT The option_value or option_len parameter can not be
185 accessed or written.
186
187
188 EINVAL The specified option is invalid at the specified socket
189 level.
190
191
192 ENOPROTOOPT The option is not supported by the protocol.
193
194
195 ENOTSOCK The socket argument does not refer to a socket.
196
197
198
199 The getsockopt() function may fail if:
200
201 EACCES The calling process does not have the appropriate privi‐
202 leges.
203
204
205 EINVAL The socket has been shut down.
206
207
208 ENOBUFS Insufficient resources are available in the system to com‐
209 plete the call.
210
211
212 ENOSR There were insufficient STREAMS resources available for the
213 operation to complete.
214
215
217 See attributes(5) for descriptions of the following attributes:
218
219
220
221
222 ┌─────────────────────────────┬─────────────────────────────┐
223 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
224 ├─────────────────────────────┼─────────────────────────────┤
225 │Interface Stability │Standard │
226 ├─────────────────────────────┼─────────────────────────────┤
227 │MT-Level │MT-Safe │
228 └─────────────────────────────┴─────────────────────────────┘
229
231 close(2), bind(3XNET), endprotoent(3XNET), setsockopt(3XNET),
232 socket(3XNET), attributes, standards(5)
233
234
235
236SunOS 5.11 21 Jan 2007 getsockopt(3XNET)