summaryrefslogtreecommitdiff
path: root/usr/src/man/man3head/socket.h.3head
blob: 5a9dee8c2ca5e640cd57c70f1bb6ee0c27abda4e (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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
.\"
.\" 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) 2009, Sun Microsystems, Inc.  All Rights Reserved.
.\" Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
.\"
.TH SOCKET.H 3HEAD "Sep 18, 2020"
.SH NAME
socket.h, socket, CMSG_DATA, CMSG_FIRSTHDR, CMSG_LEN, CMSG_NXTHDR, CMSG_SPACE \- Internet Protocol family
.SH SYNOPSIS
.nf
\fB#include <sys/socket.h>\fR
.fi

.SH DESCRIPTION
The \fB<sys/socket.h>\fR header defines the unsigned integral type
\fBsa_family_t\fR through \fBtypedef\fR.
.sp
.LP
The \fB<sys/socket.h>\fR header defines the \fBsockaddr\fR structure that
includes the following members:
.sp
.in +2
.nf
sa_family_t   sa_family     /* address family */
char          sa_data[]     /* socket   address (variable-length
                                data) */
.fi
.in -2

.SS "\fBlibxnet\fR Interfaces"
The \fB<sys/socket.h>\fR header defines the \fBmsghdr\fR structure for
\fBlibxnet\fR interfaces that includes the following members:
.sp
.in +2
.nf
void            *msg_name         /* optional address */
socklen_t       msg_namelen       /* size of address */
struct iovec    *msg_iov          /* scatter/gather array */
int             msg_iovlen        /* members in msg_iov */
void            *msg_control      /* ancillary data, see below */
socklen_t       msg_controllen    /* ancillary data buffer len */
int             msg_flags         /* flags on received message */
.fi
.in -2

.sp
.LP
The \fB<sys/socket.h>\fR header defines the \fBcmsghdr\fR structure for
\fBlibxnet\fR that includes the following members:
.sp
.in +2
.nf
socklen_t  cmsg_len      /* data byte count, including hdr */
int        cmsg_level    /* originating protocol */
int        cmsg_type     /* protocol-specific type */
.fi
.in -2

.sp
.LP
Ancillary data consists of a sequence of pairs, each consisting of a
\fBcmsghdr\fR structure followed by a data array. The data array contains the
ancillary data message, and the \fBcmsghdr\fR structure contains descriptive
information that allows an application to correctly parse the data.
.sp
.LP
The values for \fBcmsg_level\fR will be legal values for the level argument to
the \fBgetsockopt()\fR and \fBsetsockopt()\fR functions. The \fBSCM_RIGHTS\fR
type is supported for level \fBSOL_SOCKET\fR.
.sp
.LP
Ancillary data is also possible at the socket level. The \fB<sys/socket.h>\fR
header defines the following macros for use as the \fBcmsg_type\fR values when
\fBcmsg_level\fR is \fBSOL_SOCKET\fR.
.sp
.ne 2
.na
\fBSCM_RIGHTS\fR
.ad
.RS 14n
Indicates that the data array contains the access rights (set of open file
descriptors) to be sent or received.
.RE

.sp
.ne 2
.na
\fBSCM_UCRED\fR
.ad
.RS 14n
Indicates that the data array contains a \fBucred_t\fR to be received. The
\fBucred_t\fR is the credential of the sending process at the time the message
was sent. This is a Sun-specific, Evolving interface. See \fBucred_get\fR(3C).
.RE

.sp
.LP
The IPv4 ancillary data formats are listed below by \fBcmsg_level\fR and
\fBcmsg_type\fR, along with the associated payload for each.
.sp
.ne 2
.na
\fBIPPROTO_IP\fR, \fBIP_RECVDSTADDR\fR \(em \fBSOCK_DGRAM\fR only
.ad
.sp .6
.RS 4n
\fBipaddr_t\fR, IP address
.RE

.sp
.ne 2
.na
\fBIPPROTO_IP\fR, \fBIP_RECVIF\fR
.ad
.sp .6
.RS 4n
\fBuint_t\fR, \fBifIndex\fR number
.RE

.sp
.ne 2
.na
\fBIPPROTO_IP\fR, \fBIP_RECVOPTS\fR \(em \fBSOCK_DGRAM\fR only
.ad
.sp .6
.RS 4n
variable-length IP options, up to 40 bytes
.RE

.sp
.ne 2
.na
\fBIPPROTO_IP\fR, \fBIP_RECVPKTINFO\fR \(em \fBSOCK_DGRAM\fR only
.ad
.sp .6
.RS 4n
\fBin_pktinfo_t\fR
.RE

.sp
.ne 2
.na
\fBIPPROTO_IP\fR, \fBIP_RECVSLLA\fR \(em \fBSOCK_DGRAM\fR only
.ad
.sp .6
.RS 4n
\fBstruct sockaddr_dl\fR, link layer address
.RE

.sp
.ne 2
.na
\fBIPPROTO_IP\fR, \fBIP_RECVTTL\fR \(em \fBSOCK_DGRAM\fR only
.ad
.sp .6
.RS 4n
\fBuint8_t\fR, the IP TTL (time to live)
.RE

.sp
.ne 2
.na
\fBIPPROTO_IP\fR, \fBIP_RECVTOS\fR
.ad
.sp .6
.RS 4n
\fBuint8_t\fR, the IP TOS (type of service)
.RE

.sp
.ne 2
.na
\fBSOL_SOCKET\fR, \fBSO_UCRED\fR
.ad
.sp .6
.RS 4n
\fBucred_t\fR
.RE

.sp
.LP
The IPv6 ancillary data formats are listed below by \fBcmsg_level\fR and
\fBcmsg_type\fR, along with the associated payload for each.
.sp
.ne 2
.na
\fBIPPROTO_IPV6\fR, \fBIPV6_PKTINFO\fR
.ad
.sp .6
.RS 4n
\fBin_pktinfo_t\fR
.RE

.sp
.ne 2
.na
\fBIPPROTO_IPV6\fR, \fBIPV6_TCLASS\fR
.ad
.sp .6
.RS 4n
\fBuint_t\fR
.RE

.sp
.ne 2
.na
\fBIPPROTO_IPV6\fR, \fBIPV6_PATHMTU\fR
.ad
.sp .6
.RS 4n
\fBip6_mtuinfo\fR
.RE

.sp
.ne 2
.na
\fBIPPROTO_IPV6\fR, \fBIPV6_HOPLIMIT\fR
.ad
.sp .6
.RS 4n
\fBuint_t\fR
.RE

.sp
.ne 2
.na
\fBIPPROTO_IPV6\fR, \fBIPV6_HOPOPTS\fR
.ad
.sp .6
.RS 4n
variable-length IPv6 options
.RE

.sp
.ne 2
.na
\fBIPPROTO_IPV6\fR, \fBIPV6_DSTOPTS\fR
.ad
.sp .6
.RS 4n
variable-length IPv6 options
.RE

.sp
.ne 2
.na
\fBIPPROTO_IPV6\fR, \fBIPV6_RTHDR\fR
.ad
.sp .6
.RS 4n
variable-length IPv6 options
.RE

.sp
.ne 2
.na
\fBIPPROTO_IPV6\fR, \fBIPV6_DSTOPTS\fR
.ad
.sp .6
.RS 4n
variable-length IPv6 options
.RE

.sp
.LP
The \fB<sys/socket.h>\fR header defines the following macros to gain access to
the data arrays in the ancillary data associated with a message header:
.sp
.ne 2
.na
\fB\fBCMSG_DATA(\fR\fIcmsg\fR)\fR
.ad
.sp .6
.RS 4n
If the argument is a pointer to a \fBcmsghdr\fR structure, this macro returns
an unsigned character pointer to the data array associated with the
\fBcmsghdr\fR structure.
.RE

.sp
.ne 2
.na
\fB\fBCMSG_NXTHDR(\fR\fImhdr\fR, \fIcmsg\fR)\fR
.ad
.sp .6
.RS 4n
If the first argument is a pointer to a \fBmsghdr\fR structure and the second
argument is a pointer to a \fBcmsghdr\fR structure in the ancillary data,
pointed to by the \fBmsg_control\fR field of that \fBmsghdr\fR structure, this
macro returns a pointer to the next \fBcmsghdr\fR structure, or a null pointer
if this structure is the last \fBcmsghdr\fR in the ancillary data.
.RE

.sp
.ne 2
.na
\fB\fBCMSG_FIRSTHDR(\fR\fImhdr\fR)\fR
.ad
.sp .6
.RS 4n
If the argument is a pointer to a \fBmsghdr\fR structure, this macro returns a
pointer to the first \fBcmsghdr\fR structure in the ancillary data associated
with this \fBmsghdr\fR structure, or a null pointer if there is no ancillary
data associated with the \fBmsghdr\fR structure.
.RE

.sp
.ne 2
.na
\fB\fBCMSG_SPACE\fR(\fIlen\fR)\fR
.ad
.sp .6
.RS 4n
Given the length of an ancillary data object, \fBCMSG_SPACE()\fR returns the
space required by the object and its \fBcmsghdr\fR structure, including any
padding needed to satisfy alignment requirements. This macro can be used, for
example, to allocate space dynamically for the ancillary data. This macro
should not be used to initialize the \fBcmsg_len\fR member of a \fBcmsghdr\fR
structure. Use the \fBCMSG_LEN()\fR macro instead.
.RE

.sp
.ne 2
.na
\fB\fBCMSG_LEN\fR(\fIlen\fR)\fR
.ad
.sp .6
.RS 4n
Given the length of an ancillary data object, \fBCMSG_LEN()\fR returns the
value to store in the cmsg_len member of the \fBcmsghdr\fR structure, taking
into account any padding needed to satisfy alignment requirements.
.RE

.sp
.LP
The \fB<sys/socket.h>\fR header defines the \fBlinger\fR structure that
includes the following members:
.sp
.in +2
.nf
int   l_onoff   /* indicates  whether  linger option is enabled */
int   l_linger  /* linger time, in seconds */
.fi
.in -2

.sp
.LP
The \fB<sys/socket.h>\fR header defines the following macros:
.sp
.ne 2
.na
\fBSOCK_DGRAM\fR
.ad
.RS 18n
Datagram socket
.RE

.sp
.ne 2
.na
\fBSOCK_STREAM\fR
.ad
.RS 18n
Byte-stream socket
.RE

.sp
.ne 2
.na
\fBSOCK_SEQPACKET\fR
.ad
.RS 18n
Sequenced-packet socket
.RE

.sp
.LP
The \fB<sys/socket.h>\fR header defines the following macros for use as the
\fIlevel\fR argument of \fBsetsockopt()\fR and \fBgetsockopt()\fR.
.sp
.ne 2
.na
\fBSOL_SOCKET\fR
.ad
.RS 14n
Options to be accessed at the socket level, not the protocol level.
.RE

.sp
.ne 2
.na
\fBSOL_ROUTE\fR
.ad
.RS 14n
Options to be accessed at the routing socket level, not the protocol level.
.RE

.sp
.LP
The \fB<sys/socket.h>\fR header defines the following macros for use as the
\fIoption_name\fR argument of \fBgetsockopt()\fR or \fBsetsockopt()\fR calls:
.sp
.ne 2
.na
\fBSO_DEBUG\fR
.ad
.RS 17n
Debugging information is being recorded.
.RE

.sp
.ne 2
.na
\fBSO_ACCEPTCONN\fR
.ad
.RS 17n
Socket is accepting connections.
.RE

.sp
.ne 2
.na
\fBSO_BROADCAST\fR
.ad
.RS 17n
Transmission of broadcast messages is supported.
.RE

.sp
.ne 2
.na
\fBSO_REUSEADDR\fR
.ad
.RS 17n
Reuse of local addresses is supported.
.RE

.sp
.ne 2
.na
\fBSO_KEEPALIVE\fR
.ad
.RS 17n
Connections are kept alive with periodic messages.
.RE

.sp
.ne 2
.na
\fBSO_LINGER\fR
.ad
.RS 17n
Socket lingers on close.
.RE

.sp
.ne 2
.na
\fBSO_OOBINLINE\fR
.ad
.RS 17n
Out-of-band data is transmitted in line.
.RE

.sp
.ne 2
.na
\fBSO_SNDBUF\fR
.ad
.RS 17n
Send buffer size.
.RE

.sp
.ne 2
.na
\fBSO_RCVBUF\fR
.ad
.RS 17n
Receive buffer size.
.RE

.sp
.ne 2
.na
\fBSO_ERROR\fR
.ad
.RS 17n
Socket error status.
.RE

.sp
.ne 2
.na
\fBSO_TYPE\fR
.ad
.RS 17n
Socket type.
.RE

.sp
.ne 2
.na
\fBSO_RECVUCRED\fR
.ad
.RS 17n
Request the reception of user credential ancillary data. This is a
Sun-specific, Evolving interface. See \fBucred_get\fR(3C).
.RE

.sp
.ne 2
.na
\fBSO_MAC_EXEMPT\fR
.ad
.RS 17n
Mandatory Access Control (\fBMAC\fR) exemption for unlabeled peers. This option
is available only if the system is configured with Trusted Extensions.
.RE

.sp
.ne 2
.na
\fBSO_ALLZONES\fR
.ad
.RS 17n
Bypass zone boundaries (privileged).
.RE

.sp
.LP
The \fB<sys/socket.h>\fR header defines the following macros for use as the
valid values for the \fBmsg_flags\fR field in the \fBmsghdr\fR structure, or
the flags parameter in \fBrecvfrom()\fR, \fBrecvmsg()\fR, \fBsendto()\fR, or
\fBsendmsg()\fR calls:
.sp
.ne 2
.na
\fBMSG_CTRUNC\fR
.ad
.RS 15n
Control data truncated.
.RE

.sp
.ne 2
.na
\fBMSG_EOR\fR
.ad
.RS 15n
Terminates a record (if supported by the protocol).
.RE

.sp
.ne 2
.na
\fBMSG_OOB\fR
.ad
.RS 15n
Out-of-band data.
.RE

.sp
.ne 2
.na
\fBMSG_PEEK\fR
.ad
.RS 15n
Leave received data in queue.
.RE

.sp
.ne 2
.na
\fBMSG_TRUNC\fR
.ad
.RS 15n
Normal data truncated.
.RE

.sp
.ne 2
.na
\fBMSG_WAITALL\fR
.ad
.RS 15n
Wait for complete message.
.RE

.sp
.ne 2
.na
\fBMSG_NOSIGNAL\fR
.ad
.RS 15n
Do not generate \fBSIGPIPE\fR signal.
.RE

.sp
.LP
The \fB<sys/socket.h>\fR header defines the following macros:
.sp
.ne 2
.na
\fBAF_UNIX\fR
.ad
.RS 11n
UNIX domain sockets
.RE

.sp
.ne 2
.na
\fBAF_INET\fR
.ad
.RS 11n
Internet domain sockets
.RE

.sp
.LP
The \fB<sys/socket.h>\fR header defines the following macros:
.sp
.ne 2
.na
\fBSHUT_RD\fR
.ad
.RS 13n
Disables further receive operations.
.RE

.sp
.ne 2
.na
\fBSHUT_WR\fR
.ad
.RS 13n
Disables further send operations.
.RE

.sp
.ne 2
.na
\fBSHUT_RDWR\fR
.ad
.RS 13n
Disables further send and receive operations.
.RE

.SS "\fBlibsocket\fR Interfaces"
The \fB<sys/socket.h>\fR header defines the \fBmsghdr\fR structure for
\fBlibsocket\fR interfaces that includes the following members:
.sp
.in +2
.nf
void           *msg_name        /* optional address */
socklen_t      msg_namelen      /* size of address */
struct iovec   *msg_iov         /* scatter/gather array */
int            msg_iovlen       /* # elements in msg_iov */
caddr_t        msg_accrights    /* access rights sent/received */
.fi
.in -2

.sp
.LP
The \fImsg_name\fR and \fImsg_namelen\fR parameters specify the destination
address when the socket is unconnected The \fImsg_name\fR can be specified as a
\fINULL\fR pointer if no names are desired or required. The \fImsg_iov\fR and
\fImsg_iovlen\fR parameters describe the scatter-gather locations, as described
in \fBread\fR(2). The \fImsg_accrights\fR parameter specifies the buffer in
which access rights sent along with the message are received. The
\fImsg_accrightslen\fR specifies the length of the buffer.
.SH ATTRIBUTES
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

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

.SH SEE ALSO
.BR getpeerucred (3C),
.BR ucred_get (3C),
.BR libsocket (3LIB),
.BR accept (3SOCKET),
.BR bind (3SOCKET),
.BR connect (3SOCKET),
.BR getpeername (3SOCKET),
.BR getsockname (3SOCKET),
.BR getsockopt (3SOCKET),
.BR listen (3SOCKET),
.BR recv (3SOCKET),
.BR recvfrom (3SOCKET),
.BR recvmsg (3SOCKET),
.BR send (3SOCKET),
.BR sendmsg (3SOCKET),
.BR sendto (3SOCKET),
.BR setsockopt (3SOCKET),
.BR shutdown (3SOCKET),
.BR sockaddr (3SOCKET),
.BR socket (3SOCKET),
.BR socketpair (3SOCKET),
.BR accept (3XNET),
.BR bind (3XNET),
.BR connect (3XNET),
.BR getpeername (3XNET),
.BR getsockname (3XNET),
.BR getsockopt (3XNET),
.BR listen (3XNET),
.BR recv (3XNET),
.BR recvfrom (3XNET),
.BR recvmsg (3XNET),
.BR send (3XNET),
.BR sendmsg (3XNET),
.BR sendto (3XNET),
.BR setsockopt (3XNET),
.BR shutdown (3XNET),
.BR socket (3XNET),
.BR socketpair (3XNET),
.BR attributes (7),
.BR standards (7)