5331 want sockaddr(3SOCKET)
[illumos-gate.git] / usr / src / man / man3head / socket.h.3head
blob781dcf14f10b92d03c8db39c6c8a98c7fd6200e3
1 '\" te
2 .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved.
3 .\" Portions Copyright (c) 2009, Sun Microsystems, Inc.  All Rights Reserved.
4 .\" 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/.
5 .\" 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
6 .\" are reprinted and reproduced in electronic form in the Sun OS 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
7 .\" 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.
8 .\"  This notice shall appear on any product containing this material.
9 .\" 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.
10 .\" 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.
11 .\" 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]
12 .TH SOCKET.H 3HEAD "Jan 28, 2009"
13 .SH NAME
14 socket.h, socket \- Internet Protocol family
15 .SH SYNOPSIS
16 .LP
17 .nf
18 \fB#include <sys/socket.h>\fR
19 .fi
21 .SH DESCRIPTION
22 .LP
23 The \fB<sys/socket.h>\fR header defines the unsigned integral type
24 \fBsa_family_t\fR through \fBtypedef\fR.
25 .sp
26 .LP
27 The \fB<sys/socket.h>\fR header defines the \fBsockaddr\fR structure that
28 includes the following members:
29 .sp
30 .in +2
31 .nf
32 sa_family_t   sa_family     /* address family */
33 char          sa_data[]     /* socket   address (variable-length
34                                 data) */
35 .fi
36 .in -2
38 .SS "\fBlibxnet\fR Interfaces"
39 .LP
40 The \fB<sys/socket.h>\fR header defines the \fBmsghdr\fR structure for
41 \fBlibxnet\fR interfaces that includes the following members:
42 .sp
43 .in +2
44 .nf
45 void            *msg_name         /* optional address */
46 socklen_t       msg_namelen       /* size of address */
47 struct iovec    *msg_iov          /* scatter/gather array */
48 int             msg_iovlen        /* members in msg_iov */
49 void            *msg_control      /* ancillary data, see below */
50 socklen_t       msg_controllen    /* ancillary data buffer len */
51 int             msg_flags         /* flags on received message */
52 .fi
53 .in -2
55 .sp
56 .LP
57 The \fB<sys/socket.h>\fR header defines the \fBcmsghdr\fR structure for
58 \fBlibxnet\fR that includes the following members:
59 .sp
60 .in +2
61 .nf
62 socklen_t  cmsg_len      /* data byte count, including hdr */
63 int        cmsg_level    /* originating protocol */
64 int        cmsg_type     /* protocol-specific type */
65 .fi
66 .in -2
68 .sp
69 .LP
70 Ancillary data consists of a sequence of pairs, each consisting of a
71 \fBcmsghdr\fR structure followed by a data array. The data array contains the
72 ancillary data message, and the \fBcmsghdr\fR structure contains descriptive
73 information that allows an application to correctly parse the data.
74 .sp
75 .LP
76 The values for \fBcmsg_level\fR will be legal values for the level argument to
77 the \fBgetsockopt()\fR and \fBsetsockopt()\fR functions. The \fBSCM_RIGHTS\fR
78 type is supported for level \fBSOL_SOCKET\fR.
79 .sp
80 .LP
81 Ancillary data is also possible at the socket level. The \fB<sys/socket.h>\fR
82 header defines the following macros for use as the \fBcmsg_type\fR values when
83 \fBcmsg_level\fR is \fBSOL_SOCKET\fR.
84 .sp
85 .ne 2
86 .na
87 \fB\fBSCM_RIGHTS\fR\fR
88 .ad
89 .RS 14n
90 Indicates that the data array contains the access rights to be sent or
91 received.
92 .RE
94 .sp
95 .ne 2
96 .na
97 \fB\fBSCM_UCRED\fR\fR
98 .ad
99 .RS 14n
100 Indicates that the data array contains a \fBucred_t\fR to be received. The
101 \fBucred_t\fR is the credential of the sending process at the time the message
102 was sent. This is a Sun-specific, Evolving interface. See \fBucred_get\fR(3C).
107 The IPv4 data formats generally use the same values for data passed back in
108 \fBcmsghdr\fR as for \fBsetsockopt()\fR to enable the feature. The IPv4 data
109 formats are listed below with the associated payload for each.
111 .ne 2
113 \fB\fBIPPROTO_IP\fR\fR
117 \fB\fBIP_RECVDSTADDR\fR\fR
119 .sp .6
120 .RS 4n
121 \fBipaddr_t\fR, IP address
125 .ne 2
127 \fB\fBIPPROTO_IP\fR\fR
131 \fB\fBIP_RECVOPTS\fR\fR
133 .sp .6
134 .RS 4n
135 variable-length IP options, up to 40 bytes
139 .ne 2
141 \fB\fBIPPROTO_IP\fR\fR
145 \fB\fBIP_RECVIF\fR\fR
147 .sp .6
148 .RS 4n
149 \fBuint_t\fR, \fBifIndex\fR number
153 .ne 2
155 \fB\fBIPPROTO_IP\fR\fR
159 \fB\fBIP_RECVSLLA\fR\fR
161 .sp .6
162 .RS 4n
163 \fBstruct sockaddr_dl\fR, link layer address
167 .ne 2
169 \fB\fBIPPROTO_IP\fR\fR
173 \fB\fBIP_RECVTTL\fR\fR
175 .sp .6
176 .RS 4n
177 \fBuint8_t\fR
181 .ne 2
183 \fB\fBSOL_SOCKET\fR\fR
187 \fB\fBSO_RECVUCRED\fR\fR
189 .sp .6
190 .RS 4n
191 \fBucred_t\fR \(em \fBcmsghdr.cmsg_type\fR is \fBSCM_UCRED\fR, not
192 \fBSO_RECVUCRED\fR
197 The IPv6 data formats use different values for enabling the option and for
198 passing the value back to the application. The IPv6 data formats are listed
199 below with the associated payload for each.
201 .ne 2
203 \fB\fBIPPROTO_IPV6\fR\fR
207 \fB\fBIPV6_RECVPKTINFO\fR\fR
209 .sp .6
210 .RS 4n
211 \fBin_pktinfo\fR, \fBcmsg_type\fR \fBIPV6_PKTINFO\fR
215 .ne 2
217 \fB\fBIPPROTO_IPV6\fR\fR
221 \fB\fBIPV6_RECVTCLASS\fR\fR
223 .sp .6
224 .RS 4n
225 \fBuint_t\fR, \fBcmsg_type\fR \fBIPV6_TCLASS\fR
229 .ne 2
231 \fB\fBIPPROTO_IPV6\fR\fR
235 \fB\fBIPV6_RECVPATHMTU\fR\fR
237 .sp .6
238 .RS 4n
239 \fBip6_mtuinfo\fR, \fBcmsg_type\fR \fBIPV6_PATHMTU\fR
243 .ne 2
245 \fB\fBIPPROTO_IPV6\fR\fR
249 \fB\fBIPV6_RECVHOPLIMIT\fR\fR
251 .sp .6
252 .RS 4n
253 \fBuint_t\fR, \fBcmsg_type\fR \fBIPV6_HOPLIMIT\fR
257 .ne 2
259 \fB\fBIPPROTO_IPV6\fR\fR
263 \fB\fBIPV6_RECVHOPOPTS\fR\fR
265 .sp .6
266 .RS 4n
267 variable-length IPv6 options, \fBcmsg_type\fR \fBIPV6_HOPOPTS\fR
271 .ne 2
273 \fB\fBIPPROTO_IPV6\fR\fR
277 \fB\fBIPV6_RECVDSTOPTS\fR\fR
279 .sp .6
280 .RS 4n
281 variable-length IPv6 options, \fBcmsg_type\fR \fBIPV6_DSTOPTS\fR
285 .ne 2
287 \fB\fBIPPROTO_IPV6\fR\fR
291 \fB\fBIPV6_RECVRTHDR\fR\fR
293 .sp .6
294 .RS 4n
295 variable-length IPv6 options, \fBcmsg_type\fR \fBIPV6_RTHDR\fR
299 .ne 2
301 \fB\fBIPPROTO_IPV6\fR\fR
305 \fB\fBIPV6_RECVRTHDRDSTOPTS\fR\fR
307 .sp .6
308 .RS 4n
309 variable-length IPv6 options, \fBcmsg_type\fR \fBIPV6_DSTOPTS\fR
314 The \fB<sys/socket.h>\fR header defines the following macros to gain access to
315 the data arrays in the ancillary data associated with a message header:
317 .ne 2
319 \fB\fBCMSG_DATA(\fR\fIcmsg\fR)\fR
321 .sp .6
322 .RS 4n
323 If the argument is a pointer to a \fBcmsghdr\fR structure, this macro returns
324 an unsigned character pointer to the data array associated with the
325 \fBcmsghdr\fR structure.
329 .ne 2
331 \fB\fBCMSG_NXTHDR(\fR\fImhdr\fR, \fIcmsg\fR)\fR
333 .sp .6
334 .RS 4n
335 If the first argument is a pointer to a \fBmsghdr\fR structure and the second
336 argument is a pointer to a \fBcmsghdr\fR structure in the ancillary data,
337 pointed to by the \fBmsg_control\fR field of that \fBmsghdr\fR structure, this
338 macro returns a pointer to the next \fBcmsghdr\fR structure, or a null pointer
339 if this structure is the last \fBcmsghdr\fR in the ancillary data.
343 .ne 2
345 \fB\fBCMSG_FIRSTHDR(\fR\fImhdr\fR)\fR
347 .sp .6
348 .RS 4n
349 If the argument is a pointer to a \fBmsghdr\fR structure, this macro returns a
350 pointer to the first \fBcmsghdr\fR structure in the ancillary data associated
351 with this \fBmsghdr\fR structure, or a null pointer if there is no ancillary
352 data associated with the \fBmsghdr\fR structure.
356 .ne 2
358 \fB\fBCMSG_SPACE\fR(\fIlen\fR)\fR
360 .sp .6
361 .RS 4n
362 Given the length of an ancillary data object, \fBCMSG_SPACE()\fR returns the
363 space required by the object and its \fBcmsghdr\fR structure, including any
364 padding needed to satisfy alignment requirements. This macro can be used, for
365 example, to allocate space dynamically for the ancillary data. This macro
366 should not be used to initialize the \fBcmsg_len\fR member of a \fBcmsghdr\fR
367 structure. Use the \fBCMSG_LEN()\fR macro instead.
371 .ne 2
373 \fB\fBCMSG_LEN\fR(\fIlen\fR)\fR
375 .sp .6
376 .RS 4n
377 Given the length of an ancillary data object, \fBCMSG_LEN()\fR returns the
378 value to store in the cmsg_len member of the \fBcmsghdr\fR structure, taking
379 into account any padding needed to satisfy alignment requirements.
384 The \fB<sys/socket.h>\fR header defines the \fBlinger\fR structure that
385 includes the following members:
387 .in +2
389 int   l_onoff   /* indicates  whether  linger option is enabled */
390 int   l_linger  /* linger time, in seconds */
392 .in -2
396 The \fB<sys/socket.h>\fR header defines the following macros:
398 .ne 2
400 \fB\fBSOCK_DGRAM\fR\fR
402 .RS 18n
403 Datagram socket
407 .ne 2
409 \fB\fBSOCK_STREAM\fR\fR
411 .RS 18n
412 Byte-stream socket
416 .ne 2
418 \fB\fBSOCK_SEQPACKET\fR\fR
420 .RS 18n
421 Sequenced-packet socket
426 The \fB<sys/socket.h>\fR header defines the following macros for use as the
427 \fIlevel\fR argument of \fBsetsockopt()\fR and \fBgetsockopt()\fR.
429 .ne 2
431 \fB\fBSOL_SOCKET\fR\fR
433 .RS 14n
434 Options to be accessed at the socket level, not the protocol level.
438 .ne 2
440 \fB\fBSOL_ROUTE\fR\fR
442 .RS 14n
443 Options to be accessed at the routing socket level, not the protocol level.
448 The \fB<sys/socket.h>\fR header defines the following macros for use as the
449 \fIoption_name\fR argument of \fBgetsockopt()\fR or \fBsetsockopt()\fR calls:
451 .ne 2
453 \fB\fBSO_DEBUG\fR\fR
455 .RS 17n
456 Debugging information is being recorded.
460 .ne 2
462 \fB\fBSO_ACCEPTCONN\fR\fR
464 .RS 17n
465 Socket is accepting connections.
469 .ne 2
471 \fB\fBSO_BROADCAST\fR\fR
473 .RS 17n
474 Transmission of broadcast messages is supported.
478 .ne 2
480 \fB\fBSO_REUSEADDR\fR\fR
482 .RS 17n
483 Reuse of local addresses is supported.
487 .ne 2
489 \fB\fBSO_KEEPALIVE\fR\fR
491 .RS 17n
492 Connections are kept alive with periodic messages.
496 .ne 2
498 \fB\fBSO_LINGER\fR\fR
500 .RS 17n
501 Socket lingers on close.
505 .ne 2
507 \fB\fBSO_OOBINLINE\fR\fR
509 .RS 17n
510 Out-of-band data is transmitted in line.
514 .ne 2
516 \fB\fBSO_SNDBUF\fR\fR
518 .RS 17n
519 Send buffer size.
523 .ne 2
525 \fB\fBSO_RCVBUF\fR\fR
527 .RS 17n
528 Receive buffer size.
532 .ne 2
534 \fB\fBSO_ERROR\fR\fR
536 .RS 17n
537 Socket error status.
541 .ne 2
543 \fB\fBSO_TYPE\fR\fR
545 .RS 17n
546 Socket type.
550 .ne 2
552 \fB\fBSO_RECVUCRED\fR\fR
554 .RS 17n
555 Request the reception of user credential ancillary data. This is a
556 Sun-specific, Evolving interface. See \fBucred_get\fR(3C).
560 .ne 2
562 \fB\fBSO_MAC_EXEMPT\fR\fR
564 .RS 17n
565 Mandatory Access Control (\fBMAC\fR) exemption for unlabeled peers. This option
566 is available only if the system is configured with Trusted Extensions.
570 .ne 2
572 \fB\fBSO_ALLZONES\fR\fR
574 .RS 17n
575 Bypass zone boundaries (privileged).
580 The \fB<sys/socket.h>\fR header defines the following macros for use as the
581 valid values for the \fBmsg_flags\fR field in the \fBmsghdr\fR structure, or
582 the flags parameter in \fBrecvfrom()\fR, \fBrecvmsg()\fR, \fBsendto()\fR, or
583 \fBsendmsg()\fR calls:
585 .ne 2
587 \fB\fBMSG_CTRUNC\fR\fR
589 .RS 15n
590 Control data truncated.
594 .ne 2
596 \fB\fBMSG_EOR\fR\fR
598 .RS 15n
599 Terminates a record (if supported by the protocol).
603 .ne 2
605 \fB\fBMSG_OOB\fR\fR
607 .RS 15n
608 Out-of-band data.
612 .ne 2
614 \fB\fBMSG_PEEK\fR\fR
616 .RS 15n
617 Leave received data in queue.
621 .ne 2
623 \fB\fBMSG_TRUNC\fR\fR
625 .RS 15n
626 Normal data truncated.
630 .ne 2
632 \fB\fBMSG_WAITALL\fR\fR
634 .RS 15n
635 Wait for complete message.
640 The \fB<sys/socket.h>\fR header defines the following macros:
642 .ne 2
644 \fB\fBAF_UNIX\fR\fR
646 .RS 11n
647 UNIX domain sockets
651 .ne 2
653 \fB\fBAF_INET\fR\fR
655 .RS 11n
656 Internet domain sockets
661 The \fB<sys/socket.h>\fR header defines the following macros:
663 .ne 2
665 \fB\fBSHUT_RD\fR\fR
667 .RS 13n
668 Disables further receive operations.
672 .ne 2
674 \fB\fBSHUT_WR\fR\fR
676 .RS 13n
677 Disables further send operations.
681 .ne 2
683 \fB\fBSHUT_RDWR\fR\fR
685 .RS 13n
686 Disables further send and receive operations.
689 .SS "\fBlibsocket\fR Interfaces"
691 The \fB<sys/socket.h>\fR header defines the \fBmsghdr\fR structure for
692 \fBlibsocket\fR interfaces that includes the following members:
694 .in +2
696 void           *msg_name        /* optional address */
697 socklen_t      msg_namelen      /* size of address */
698 struct iovec   *msg_iov         /* scatter/gather array */
699 int            msg_iovlen       /* # elements in msg_iov */
700 caddr_t        msg_accrights    /* access rights sent/received */
702 .in -2
706 The \fImsg_name\fR and \fImsg_namelen\fR parameters specify the destination
707 address when the socket is unconnected The \fImsg_name\fR can be specified as a
708 \fINULL\fR pointer if no names are desired or required. The \fImsg_iov\fR and
709 \fImsg_iovlen\fR parameters describe the scatter-gather locations, as described
710 in \fBread\fR(2). The \fImsg_accrights\fR parameter specifies the buffer in
711 which access rights sent along with the message are received. The
712 \fImsg_accrightslen\fR specifies the length of the buffer.
713 .SH ATTRIBUTES
715 See \fBattributes\fR(5) for descriptions of the following attributes:
720 box;
721 c | c
722 l | l .
723 ATTRIBUTE TYPE  ATTRIBUTE VALUE
725 Interface Stability     Standard
728 .SH SEE ALSO
730 \fBaccept\fR(3SOCKET), \fBaccept\fR(3XNET), \fBbind\fR(3SOCKET),
731 \fBbind\fR(3XNET), \fBconnect\fR(3SOCKET), \fBconnect\fR(3XNET),
732 \fBgetpeername\fR(3SOCKET), \fBgetpeername\fR(3XNET), \fBgetpeerucred\fR(3C),
733 \fBgetsockname\fR(3SOCKET), \fBgetsockname\fR(3XNET),
734 \fBgetsockopt\fR(3SOCKET), \fBgetsockopt\fR(3XNET), \fBlibsocket\fR(3LIB),
735 \fBlisten\fR(3SOCKET), \fBlisten\fR(3XNET), \fBrecv\fR(3SOCKET),
736 \fBrecv\fR(3XNET), \fBrecvfrom\fR(3SOCKET), \fBrecvfrom\fR(3XNET),
737 \fBrecvmsg\fR(3SOCKET), \fBrecvmsg\fR(3XNET), \fBsend\fR(3SOCKET),
738 \fBsend\fR(3XNET), \fBsendmsg\fR(3SOCKET), \fBsendmsg\fR(3XNET),
739 \fBsendto\fR(3SOCKET), \fBsendto\fR(3XNET), \fBsetsockopt\fR(3SOCKET),
740 \fBsetsockopt\fR(3XNET), \fBshutdown\fR(3SOCKET), \fBshutdown\fR(3XNET),
741 \fBsockaddr\fR(3SOCKET),
742 \fBsocket\fR(3SOCKET), \fBsocket\fR(3XNET), \fBsocketpair\fR(3SOCKET),
743 \fBsocketpair\fR(3XNET), \fBucred_get\fR(3C), \fBattributes\fR(5),
744 \fBstandards\fR(5)