sendmsg(3N-xs) (X/OPEN SOCKETS) sendmsg(3N-xs)
NAME
sendmsg - send a message on a socket using a message structure
SYNOPSIS
cc [flag ...] file ... -lxnet [library ...]
#include <sys/socket.h>
ssizet sendmsg(int socket, const struct msghdr *message,
int flags);
DESCRIPTION
The sendmsg function sends a message through a connection-oriented or
connectionless socket. If the socket is connectionless, the message
will be sent to the address specified by msghdr. If the socket is
connection-oriented, the destination address in msghdr is ignored.
The function takes the following arguments:
socket Specifies the socket file descriptor.
message Points to a msghdr structure, containing both the desti-
nation address and the buffers for the outgoing message.
The length and format of the address depend on the
address family of the socket. The msgflags member is
ignored.
flags Specifies the type of message transmission. The applica-
tion may specify 0 or the following flag:
MSGEOR Terminates a record (if supported by the pro-
tocol)
MSGOOB Sends out-of-band data on sockets that support
out-of-bound data. The significance and seman-
tics of out-of-band data are protocol-speci-
fic.
Successful completion of a call to sendmsg does not guarantee delivery
of the message. A return value of -1 indicates only locally-detected
errors.
If space is not available at the sending socket to hold the message to
be transmitted and the socket file descriptor does not have ONONBLOCK
set, sendmsg function blocks until space is available. If space is not
available at the sending socket to hold the message to be transmitted
and the socket file descriptor does have ONONBLOCK set, sendmsg func-
tion will fail.
If the socket protocol supports broadcast and the specified address is
a broadcast address for the socket protocol, sendmsg will fail if the
SOBROADCAST option is not set for the socket.
Page 1 Reliant UNIX 5.44 Printed 11/98
sendmsg(3N-xs) (X/OPEN SOCKETS) sendmsg(3N-xs)
RETURN VALUE
Upon successful completion, sendmsg function returns the number of
bytes sent. Otherwise, -1 is returned and errno is set to indicate the
error.
ERRORS
The sendmsg function will fail if:
EAFNOSUPPORT Addresses in the specified address family cannot be
used with this socket.
EBADF The socket argument is not a valid file descriptor.
ECONNRESET A connection was forcibly closed by a peer.
EINTR A signal interrupted sendmsg before any data was
transmitted.
EINVAL The sum of the iovlen values overflows an ssizet.
EMSGSIZE The message is too large to be sent all at once, as
the socket requires.
ENOTCONN The socket is connection-oriented but is not con-
nected.
ENOTSOCK The socket argument does not refer a socket.
EOPNOTSUPP The socket argument is associated with a socket that
does not support one or more of the values set in
flags.
EPIPE The socket is shut down for writing, or the socket is
connection-oriented and the peer is closed or shut
down for reading. In the latter case, and if the
socket is of type SOCKSTREAM, the SIGPIPE signal is
generated to the calling process.
EWOULDBLOCK or EAGAIN
The socket's file descriptor is marked ONONBLOCK and
the requested operation would block.
If the address family of the socket is AFUNIX, then sendmsg will fail
if:
EACCES Search permission is denied for a component of the
path prefix; or write access to the named socket is
denied.
EIO An I/O error occurred while reading from or writing to
the file system.
Page 2 Reliant UNIX 5.44 Printed 11/98
sendmsg(3N-xs) (X/OPEN SOCKETS) sendmsg(3N-xs)
ELOOP Too many symbolic links were encountered in translat-
ing the pathname in the socket address.
ENAMETOOLONG A component of a pathname exceeded {NAMEMAX} charac-
ters, or an entire pathname exceeded {PATHMAX} char-
acters.
ENOENT A component of the pathname does not name an existing
file or the pathname is an empty string.
ENOTDIR A component of the path prefix of the pathname in the
socket address is not a directory.
The sendmsg function may fail if:
EDESTADDRREQ The socket is not connection-oriented and does not
have its peer address set, and no destination address
was specified.
EHOSTUNREACH The destination host cannot be reached (probably
because the host is down or a remote router cannot
reach it).
EINVAL The msgiovlen member of the msghdr structure pointed
to by msg is less than or equal to 0, or is greater
than {IOVMAX}.
EIO An I/O error occurred while reading from or writing to
the file system.
EISCONN A destination address was specified and the socket is
connection-oriented and is already connected.
ENETDOWN The local interface used to reach the destination is
down.
ENETUNREACH No route to the network is present.
ENOBUFS The resources available in the system were not suffi-
cient to perform the operation.
ENOMEM The memory available was not sufficient to fulfill the
request.
ENOSR The STREAMS resources available were not sufficient to
complete the operation.
If the address family of the socket is AFUNIX, then sendmsg may fail
if:
ENAMETOOLONG Pathname resolution of a symbolic link produced an
intermediate result whose length exceeds {PATHMAX}.
Page 3 Reliant UNIX 5.44 Printed 11/98
sendmsg(3N-xs) (X/OPEN SOCKETS) sendmsg(3N-xs)
APPLICATION USAGE
The select and poll functions can be used to determine when it is pos-
sible to send more data.
SEE ALSO
poll(2), select(3C), getsockopt(3N-xs), recv(3N-xs), recvfrom(3N-xs),
recvmsg(3N-xs), send(3N-xs), sendto(3N-xs), getsockopt(3N-xs),
shutdown(3N-xs), socket(3N-xs).
Page 4 Reliant UNIX 5.44 Printed 11/98