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.
Copyright 2024 Oxide Computer Company
#include <sys/socket.h>
The <sys/socket.h> header defines the sockaddr structure that includes the following members:
sa_family_t sa_family /* address family */ char sa_data[] /* socket address (variable-length data) */
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 */
The <sys/socket.h> header defines the cmsghdr structure for libxnet that includes the following members:
socklen_t cmsg_len /* data byte count, including hdr */ int cmsg_level /* originating protocol */ int cmsg_type /* protocol-specific type */
Ancillary data consists of a sequence of pairs, each consisting of a cmsghdr structure followed by a data array. The data array contains the ancillary data message, and the cmsghdr structure contains descriptive information that allows an application to correctly parse the data.
The values for cmsg_level will be legal values for the level argument to the getsockopt() and setsockopt() functions. The SCM_RIGHTS type is supported for level SOL_SOCKET.
Ancillary data is also possible at the socket level. The <sys/socket.h> header defines the following macros for use as the cmsg_type values when cmsg_level is SOL_SOCKET. SCM_RIGHTS
Indicates that the data array contains the access rights (set of open file descriptors) to be sent or received. Each file descriptor requires one int to send or receive.
Indicates that the data array contains a ucred_t to be received. The ucred_t is the credential of the sending process at the time the message was sent. This is a Sun-specific, Evolving interface. See ucred_get(3C).
The IPv4 ancillary data formats are listed below by cmsg_level and cmsg_type, along with the associated payload for each. IPPROTO_IP, IP_RECVDSTADDR \(em SOCK_DGRAM only
ipaddr_t, IP address
uint_t, ifIndex number
variable-length IP options, up to 40 bytes
in_pktinfo_t
struct sockaddr_dl, link layer address
uint8_t, the IP TTL (time to live)
uint8_t, the IP TOS (type of service)
ucred_t
The IPv6 ancillary data formats are listed below by cmsg_level and cmsg_type, along with the associated payload for each. IPPROTO_IPV6, IPV6_PKTINFO
in_pktinfo_t
uint_t
ip6_mtuinfo
uint_t
variable-length IPv6 options
variable-length IPv6 options
variable-length IPv6 options
variable-length IPv6 options
The <sys/socket.h> header defines the following macros to gain access to the data arrays in the ancillary data associated with a message header: CMSG_DATA(cmsg)
If the argument is a pointer to a cmsghdr structure, this macro returns an unsigned character pointer to the data array associated with the cmsghdr structure.
If the first argument is a pointer to a msghdr structure and the second argument is a pointer to a cmsghdr structure in the ancillary data, pointed to by the msg_control field of that msghdr structure, this macro returns a pointer to the next cmsghdr structure, or a null pointer if this structure is the last cmsghdr in the ancillary data.
If the argument is a pointer to a msghdr structure, this macro returns a pointer to the first cmsghdr structure in the ancillary data associated with this msghdr structure, or a null pointer if there is no ancillary data associated with the msghdr structure.
Given the length of an ancillary data object, CMSG_SPACE() returns the space required by the object and its cmsghdr 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 cmsg_len member of a cmsghdr structure. Use the CMSG_LEN() macro instead.
Given the length of an ancillary data object, CMSG_LEN() returns the value to store in the cmsg_len member of the cmsghdr structure, taking into account any padding needed to satisfy alignment requirements.
The <sys/socket.h> header defines the linger structure that includes the following members:
int l_onoff /* indicates whether linger option is enabled */ int l_linger /* linger time, in seconds */
The <sys/socket.h> header defines the following macros which indicate types of sockets: SOCK_DGRAM
Datagram socket
Byte-stream socket
Raw protocol interface
Reliably delivered message
Sequenced-packet socket
In some cases, the above types are bitwise-inclusive-ORed with zero or more of the following macros which modify the socket's default behavior: SOCK_CLOEXEC
The socket should have the close-on-exec, FD_CLOEXEC file descriptor flag set on it. The socket will be closed when the process calls any of the exec(2) family of functions.
The socket should have the close-on-fork, FD_CLOFORK file descriptor flag set on it. The socket will be closed in any child process created with the fork(2) family of functions.
The socket should have the O_NDELAY flag set. See open(2) for a discussion of the specific non-blocking behavior this implies.
The socket should have the O_NONBLOCK flag set. See open(2) for a discussion of the specific non-blocking behavior this implies.
The <sys/socket.h> header defines the following macros for use as the level argument of setsockopt() and getsockopt(). SOL_SOCKET
Options to be accessed at the socket level, not the protocol level.
Options to be accessed at the routing socket level, not the protocol level.
The <sys/socket.h> header defines the following macros for use as the option_name argument of getsockopt() or setsockopt() calls: SO_DEBUG
Debugging information is being recorded.
Socket is accepting connections.
Transmission of broadcast messages is supported.
Reuse of local addresses is supported.
Connections are kept alive with periodic messages.
Socket lingers on close.
Out-of-band data is transmitted in line.
Send buffer size.
Receive buffer size.
Socket error status.
Socket family.
Socket type.
Socket protocol.
Request the reception of user credential ancillary data. This is a Sun-specific, Evolving interface. See ucred_get(3C).
Mandatory Access Control (MAC) exemption for unlabeled peers. This option is available only if the system is configured with Trusted Extensions.
Bypass zone boundaries (privileged).
The <sys/socket.h> header defines the following macros for use as the valid values for the msg_flags field in the msghdr structure, or the flags parameter in recvfrom(), recvmsg(), sendto(), or sendmsg() calls: MSG_CTRUNC
Control data truncated.
Terminates a record (if supported by the protocol).
Out-of-band data.
Leave received data in queue.
Normal data truncated.
Wait for complete message.
Do not generate SIGPIPE signal.
When receiving a message with the SCM_RIGHTS ancillary data present, all file descriptors should have the close-on-exec, FD_CLOEXEC flag set on them. They will be closed when the process successfully calls any of the exec(2) family of functions. This has no effect when sending SCM_RIGHTS ancillary data.
When receiving a message with the SCM_RIGHTS ancillary data present, all file descriptors should have the close-on-fork, FD_CLOFORK flag set on them. They will be closed in any child processes created with the fork(2) family of functions. This has no effect when sending SCM_RIGHTS ancillary data.
The <sys/socket.h> header defines the following macros: AF_UNIX
UNIX domain sockets
Internet domain sockets
The <sys/socket.h> header defines the following macros: SHUT_RD
Disables further receive operations.
Disables further send operations.
Disables further send and receive operations.
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 */
The msg_name and msg_namelen parameters specify the destination address when the socket is unconnected The msg_name can be specified as a NULL pointer if no names are desired or required. The msg_iov and msg_iovlen parameters describe the scatter-gather locations, as described in read(2). The msg_accrights parameter specifies the buffer in which access rights sent along with the message are received. The msg_accrightslen specifies the length of the buffer.
ATTRIBUTE TYPE ATTRIBUTE VALUE |
Interface Stability Standard |