1socket.h(3HEAD)                     Headers                    socket.h(3HEAD)
2
3
4

NAME

6       socket.h, socket - Internet Protocol family
7

SYNOPSIS

9       #include <sys/socket.h>
10
11

DESCRIPTION

13       The  <sys/socket.h>  header  defines the unsigned integral type sa_fam‐
14       ily_t through typedef.
15
16
17       The <sys/socket.h> header defines the sockaddr structure that  includes
18       the following members:
19
20         sa_family_t   sa_family     /* address family */
21         char          sa_data[]     /* socket   address (variable-length
22                                         data) */
23
24
25   libxnet Interfaces
26       The  <sys/socket.h>  header  defines  the  msghdr structure for libxnet
27       interfaces that includes the following members:
28
29         void            *msg_name         /* optional address */
30         socklen_t       msg_namelen       /* size of address */
31         struct iovec    *msg_iov          /* scatter/gather array */
32         int             msg_iovlen        /* members in msg_iov */
33         void            *msg_control      /* ancillary data, see below */
34         socklen_t       msg_controllen    /* ancillary data buffer len */
35         int             msg_flags         /* flags on received message */
36
37
38
39       The <sys/socket.h> header defines the  cmsghdr  structure  for  libxnet
40       that includes the following members:
41
42         socklen_t  cmsg_len      /* data byte count, including hdr */
43         int        cmsg_level    /* originating protocol */
44         int        cmsg_type     /* protocol-specific type */
45
46
47
48       Ancillary  data  consists  of a sequence of pairs, each consisting of a
49       cmsghdr structure followed by a data array. The data array contains the
50       ancillary  data message, and the cmsghdr structure contains descriptive
51       information that allows an application to correctly parse the data.
52
53
54       The values for cmsg_level will be legal values for the  level  argument
55       to  the getsockopt() and setsockopt() functions. The SCM_RIGHTS type is
56       supported for level SOL_SOCKET.
57
58
59       Ancillary data is also possible at the socket level. The <sys/socket.h>
60       header  defines  the  following  macros for use as the cmsg_type values
61       when cmsg_level is SOL_SOCKET.
62
63       SCM_RIGHTS    Indicates that the data array contains the access  rights
64                     to be sent or received.
65
66
67       SCM_UCRED     Indicates  that  the  data array contains a ucred_t to be
68                     received. The ucred_t is the credential  of  the  sending
69                     process  at the time the message was sent. This is a Sun-
70                     specific, Evolving interface. See ucred_get(3C).
71
72
73
74       The IPv4 data formats generally use the same  values  for  data  passed
75       back  in  cmsghdr  as  for setsockopt() to enable the feature. The IPv4
76       data formats are listed below with the associated payload for each.
77
78       IPPROTO_IP
79       IP_RECVDSTADDR
80
81           ipaddr_t, IP address
82
83
84       IPPROTO_IP
85       IP_RECVOPTS
86
87           variable-length IP options, up to 40 bytes
88
89
90       IPPROTO_IP
91       IP_RECVIF
92
93           uint_t, ifIndex number
94
95
96       IPPROTO_IP
97       IP_RECVSLLA
98
99           struct sockaddr_dl, link layer address
100
101
102       IPPROTO_IP
103       IP_RECVTTL
104
105           uint8_t
106
107
108       SOL_SOCKET
109       SO_RECVUCRED
110
111           ucred_t cmsghdr.cmsg_type is SCM_UCRED, not SO_RECVUCRED
112
113
114
115       The IPv6 data formats use different values for enabling the option  and
116       for  passing  the  value back to the application. The IPv6 data formats
117       are listed below with the associated payload for each.
118
119       IPPROTO_IPV6
120       IPV6_RECVPKTINFO
121
122           in_pktinfo, cmsg_type IPV6_PKTINFO
123
124
125       IPPROTO_IPV6
126       IPV6_RECVTCLASS
127
128           uint_t, cmsg_type IPV6_TCLASS
129
130
131       IPPROTO_IPV6
132       IPV6_RECVPATHMTU
133
134           ip6_mtuinfo, cmsg_type IPV6_PATHMTU
135
136
137       IPPROTO_IPV6
138       IPV6_RECVHOPLIMIT
139
140           uint_t, cmsg_type IPV6_HOPLIMIT
141
142
143       IPPROTO_IPV6
144       IPV6_RECVHOPOPTS
145
146           variable-length IPv6 options, cmsg_type IPV6_HOPOPTS
147
148
149       IPPROTO_IPV6
150       IPV6_RECVDSTOPTS
151
152           variable-length IPv6 options, cmsg_type IPV6_DSTOPTS
153
154
155       IPPROTO_IPV6
156       IPV6_RECVRTHDR
157
158           variable-length IPv6 options, cmsg_type IPV6_RTHDR
159
160
161       IPPROTO_IPV6
162       IPV6_RECVRTHDRDSTOPTS
163
164           variable-length IPv6 options, cmsg_type IPV6_DSTOPTS
165
166
167
168       The <sys/socket.h> header defines the following macros to  gain  access
169       to  the  data  arrays  in  the ancillary data associated with a message
170       header:
171
172       CMSG_DATA(cmsg)
173
174           If the argument is a pointer to a  cmsghdr  structure,  this  macro
175           returns  an unsigned character pointer to the data array associated
176           with the cmsghdr structure.
177
178
179       CMSG_NXTHDR(mhdr, cmsg)
180
181           If the first argument is a pointer to a msghdr  structure  and  the
182           second  argument  is a pointer to a cmsghdr structure in the ancil‐
183           lary data, pointed to by  the  msg_control  field  of  that  msghdr
184           structure,  this macro returns a pointer to the next cmsghdr struc‐
185           ture, or a null pointer if this structure is the  last  cmsghdr  in
186           the ancillary data.
187
188
189       CMSG_FIRSTHDR(mhdr)
190
191           If  the  argument  is  a  pointer to a msghdr structure, this macro
192           returns a pointer to the first cmsghdr structure in  the  ancillary
193           data  associated  with  this msghdr structure, or a null pointer if
194           there is no ancillary data associated with the msghdr structure.
195
196
197       CMSG_SPACE(len)
198
199           Given the length of an ancillary data object, CMSG_SPACE()  returns
200           the space required by the object and its cmsghdr structure, includ‐
201           ing any padding needed  to  satisfy  alignment  requirements.  This
202           macro  can  be used, for example, to allocate space dynamically for
203           the ancillary data. This macro should not be used to initialize the
204           cmsg_len  member  of  a cmsghdr structure. Use the CMSG_LEN() macro
205           instead.
206
207
208       CMSG_LEN(len)
209
210           Given the length of an ancillary data  object,  CMSG_LEN()  returns
211           the value to store in the cmsg_len member of the cmsghdr structure,
212           taking  into  account  any  padding  needed  to  satisfy  alignment
213           requirements.
214
215
216
217       The  <sys/socket.h>  header  defines the linger structure that includes
218       the following members:
219
220         int   l_onoff   /* indicates  whether  linger option is enabled */
221         int   l_linger  /* linger time, in seconds */
222
223
224
225       The <sys/socket.h> header defines the following macros:
226
227       SOCK_DGRAM        Datagram socket
228
229
230       SOCK_STREAM       Byte-stream socket
231
232
233       SOCK_SEQPACKET    Sequenced-packet socket
234
235
236
237       The <sys/socket.h> header defines the following macros for use  as  the
238       level argument of setsockopt() and getsockopt().
239
240       SOL_SOCKET    Options  to be accessed at the socket level, not the pro‐
241                     tocol level.
242
243
244       SOL_ROUTE     Options to be accessed at the routing socket  level,  not
245                     the protocol level.
246
247
248
249       The  <sys/socket.h>  header defines the following macros for use as the
250       option_name argument of getsockopt() or setsockopt() calls:
251
252       SO_DEBUG         Debugging information is being recorded.
253
254
255       SO_ACCEPTCONN    Socket is accepting connections.
256
257
258       SO_BROADCAST     Transmission of broadcast messages is supported.
259
260
261       SO_REUSEADDR     Reuse of local addresses is supported.
262
263
264       SO_KEEPALIVE     Connections are kept alive with periodic messages.
265
266
267       SO_LINGER        Socket lingers on close.
268
269
270       SO_OOBINLINE     Out-of-band data is transmitted in line.
271
272
273       SO_SNDBUF        Send buffer size.
274
275
276       SO_RCVBUF        Receive buffer size.
277
278
279       SO_ERROR         Socket error status.
280
281
282       SO_TYPE          Socket type.
283
284
285       SO_RECVUCRED     Request the reception  of  user  credential  ancillary
286                        data.  This is a Sun-specific, Evolving interface. See
287                        ucred_get(3C).
288
289
290       SO_MAC_EXEMPT    Mandatory Access Control (MAC) exemption for unlabeled
291                        peers.  This option is available only if the system is
292                        configured with Trusted Extensions.
293
294
295       SO_ALLZONES      Bypass zone boundaries (privileged).
296
297
298
299       The <sys/socket.h> header defines the following macros for use  as  the
300       valid  values  for  the msg_flags field in the msghdr structure, or the
301       flags parameter in recvfrom(), recvmsg(), sendto(), or sendmsg() calls:
302
303       MSG_CTRUNC     Control data truncated.
304
305
306       MSG_EOR        Terminates a record (if supported by the protocol).
307
308
309       MSG_OOB        Out-of-band data.
310
311
312       MSG_PEEK       Leave received data in queue.
313
314
315       MSG_TRUNC      Normal data truncated.
316
317
318       MSG_WAITALL    Wait for complete message.
319
320
321
322       The <sys/socket.h> header defines the following macros:
323
324       AF_UNIX    UNIX domain sockets
325
326
327       AF_INET    Internet domain sockets
328
329
330
331       The <sys/socket.h> header defines the following macros:
332
333       SHUT_RD      Disables further receive operations.
334
335
336       SHUT_WR      Disables further send operations.
337
338
339       SHUT_RDWR    Disables further send and receive operations.
340
341
342   libsocket Interfaces
343       The <sys/socket.h> header defines the msghdr  structure  for  libsocket
344       interfaces that includes the following members:
345
346         void           *msg_name        /* optional address */
347         socklen_t      msg_namelen      /* size of address */
348         struct iovec   *msg_iov         /* scatter/gather array */
349         int            msg_iovlen       /* # elements in msg_iov */
350         caddr_t        msg_accrights    /* access rights sent/received */
351
352
353
354       The msg_name and msg_namelen parameters specify the destination address
355       when the socket is unconnected The msg_name can be specified as a  NULL
356       pointer if no names are desired or required. The msg_iov and msg_iovlen
357       parameters describe  the  scatter-gather  locations,  as  described  in
358       read(2).  The  msg_accrights  parameter  specifies  the buffer in which
359       access  rights  sent  along  with  the  message   are   received.   The
360       msg_accrightslen specifies the length of the buffer.
361

ATTRIBUTES

363       See attributes(5) for descriptions of the following attributes:
364
365
366
367
368       ┌─────────────────────────────┬─────────────────────────────┐
369       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
370       ├─────────────────────────────┼─────────────────────────────┤
371       │Interface Stability          │Standard                     │
372       └─────────────────────────────┴─────────────────────────────┘
373

SEE ALSO

375       accept(3SOCKET),   accept(3XNET),   bind(3SOCKET),   bind(3XNET),  con‐
376       nect(3SOCKET),    connect(3XNET),    getpeername(3SOCKET),     getpeer‐
377       name(3XNET),     getpeerucred(3C),    getsockname(3SOCKET),    getsock‐
378       name(3XNET), getsockopt(3SOCKET),  getsockopt(3XNET),  libsocket(3LIB),
379       listen(3SOCKET),     listen(3XNET),     recv(3SOCKET),     recv(3XNET),
380       recvfrom(3SOCKET), recvfrom(3XNET),  recvmsg(3SOCKET),  recvmsg(3XNET),
381       send(3SOCKET),     send(3XNET),    sendmsg(3SOCKET),    sendmsg(3XNET),
382       sendto(3SOCKET), sendto(3XNET), setsockopt(3SOCKET), setsockopt(3XNET),
383       shutdown(3SOCKET),   shutdown(3XNET),  socket(3SOCKET),  socket(3XNET),
384       socketpair(3SOCKET), socketpair(3XNET),  ucred_get(3C),  attributes(5),
385       standards(5)
386
387
388
389SunOS 5.11                        28 Jan 2009                  socket.h(3HEAD)
Impressum