socket(5) socket(5)
NAME
socket - Internet Protocol family
SYNOPSIS
#include <sys/socket.h>
DESCRIPTION
The <sys/socket.h> header defines the unsigned integral type
safamilyt through typedef.
The <sys/socket.h> header defines the sockaddr structure that includes
at least the following members:
safamilyt safamily /* address family */
char sadata[] /* socket address (variable-length data) */
The <sys/socket.h> header defines the msghdr structure that includes
at least the following members:
void *msgname /* optional address */
sizet msgnamelen /* size of address */
struct iovec *msgiov /* scatter/gather array */
int msgiovlen /* members in msgiov */
void *msgcontrol /* ancillary data, see below */
sizet msgcontrollen /* ancillary data buffer len */
int msgflags /* flags on received message */
The <sys/socket.h> header defines the cmsghdr structure that includes
at least the following members:
sizet cmsglen /* data byte count, including hdr */
int cmsglevel /* originating protocol */
int cmsgtype /* 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 cmsglevel will be legal values for the level argument
to the getsockopt and setsockopt functions. The system documentation
should specify the cmsgtype definitions for the supported protocols.
Ancillary data is also possible at the socket level. The
<sys/socket.h> header defines the following macro for use as the
cmsgtype value when cmsglevel is SOLSOCKET:
SCMRIGHTS Indicates that the data array contains the access
rights to be sent or received.
Page 1 Reliant UNIX 5.44 Printed 11/98
socket(5) socket(5)
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:
CMSGDATA(cmsg) If the argument is a pointer to a cmsghdr struc-
ture, this macro returns an unsigned character
pointer to the data array associated with the
cmsghdr structure.
CMSGNXTHDR(mhdr,cmsg)
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 msgcontrol field of that msghdr struc-
ture, 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.
CMSGFIRSTHDR(mhdr) If the argument is a pointer to a msghdr struc-
ture, 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.
The <sys/socket.h> header defines the linger structure that includes
at least the following members:
int lonoff /* indicates whether linger option is enabled */
int llinger /* linger time, in seconds */
The <sys/socket.h> header defines the following macros, with distinct
integral values:
SOCKDGRAM Datagram socket.
SOCKSTREAM Byte-stream socket.
SOCKSEQPACKET Sequenced-packet socket.
The <sys/socket.h> header defines the following macro for use as the
level argument of setsockopt and getsockopt.
SOLSOCKET Options to be accessed at socket level, not proto-
col level.
The <sys/socket.h> header defines the following macros, with distinct
integral values, for use as the optionname argument in getsockopt or
setsockopt calls:
SODEBUG Debugging information is being recorded.
Page 2 Reliant UNIX 5.44 Printed 11/98
socket(5) socket(5)
SOACCEPTCONN Socket is accepting connections.
SOBROADCAST Transmission of broadcast messages is supported.
SOREUSEADDR Reuse of local addresses is supported.
SOKEEPALIVE Connections are kept alive with periodic messages.
SOLINGER Socket lingers on close.
SOOOBINLINE Out-of-band data is transmitted in line.
SOSNDBUF Send buffer size.
SORCVBUF Receive buffer size.
SOERROR Socket error status.
SOTYPE Socket type.
The <sys/socket.h> header defines the following macros, with distinct
integral values, for use as the valid values for the msgflags field
in the msghdr structure, or the flags parameter in recvfrom, recvmsg,
sendto, or sendmsg calls:
MSGCTRUNC Control data truncated.
MSGEOR Terminates a record (if supported by the proto-
col).
MSGOOB Out-of-band data.
MSGPEEK Leave received data in queue.
MSGTRUNC Normal data truncated.
MSGWAITALL Wait for complete message.
The <sys/socket.h> header defines the following macros, with distinct
integral values:
AFUNIX UNIX domain sockets.
AFINET Internet domain sockets.
The <sys/socket.h> header defines the following macros, with distinct
integral values:
SHUTRD Disables further receive operations.
SHUTWR Disables further send operations.
Page 3 Reliant UNIX 5.44 Printed 11/98
socket(5) socket(5)
SHUTRDWR Disables further send and receive operations.
The following are declared as functions, and may also be defined as
macros:
int accept(int socket, struct sockaddr *address,
sizet *addresslen);
int bind(int socket, const struct sockaddr *address,
sizet addresslen);
int connect(int socket, const struct sockaddr *address,
sizet addresslen);
int getpeername(int socket, struct sockaddr *address,
sizet *addresslen);
int getsockname(int socket, struct sockaddr *address,
sizet *addresslen);
int getsockopt(int socket, int level, int optionname,
void *optionvalue, sizet *optionlen);
int listen(int socket, int backlog);
ssizet recv(int socket, void *buffer, sizet length, int flags);
ssizet recvfrom(int socket, void *buffer, sizet length,
int flags, struct sockaddr *address, sizet *addresslen);
ssizet recvmsg(int socket, struct msghdr *message, int flags);
ssizet send(int socket, const void *message, sizet length, int flags);
ssizet sendmsg(int socket, const struct msghdr *message, int flags);
ssizet sendto(int socket, const void *message, sizet length, int flags,
const struct sockaddr *destaddr, sizet destlen);
int setsockopt(int socket, int level, int optionname,
const void *optionvalue, sizet optionlen);
int shutdown(int socket, int how);
int socket(int domain, int type, int protocol);
int socketpair(int domain, int type, int protocol,
int socketvector[2]);
SEE ALSO
accept(3N-xs), bind(3N-xs), connect(3N-xs), getpeername(3N-xs),
getsockname(3N-xs), getsockopt(3N-xs), listen(3N-xs), recv(3N-xs),
recvfrom(3N-xs), recvmsg(3N-xs), send(3N-xs), sendmsg(3N-xs),
sendto(3N-xs), setsockopt(3N-xs), shutdown(3N-xs), socket(3N-xs),
socketpair(3N-xs).
Page 4 Reliant UNIX 5.44 Printed 11/98