sendmsg(2) System Calls Manual sendmsg(2)
NAME
sendmsg - Sends a message from a socket using a message structure
SYNOPSIS
#include <sys/socket.h>
ssize_t sendmsg (
int socket, const struct msghdr *message, int flags);
[Tru64 UNIX] The following definition of the sendmsg() function does not conform to current standards and is supported only for backward
compatibility (see standards(5)):
int sendmsg (
int socket, struct msghdr *message, int flags);
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
sendmsg(): XNS5.0
Refer to the standards(5) reference page for more information about industry standards and associated tags.
PARAMETERS
Specifies the socket file descriptor. Points to a msghdr structure, containing pointers to both the destination address for the outgoing
message and to buffers containing ancillary data. The format of the address is determined by the behavior requested for the socket.
The msghdr structure uses a socklen_t data type for the msg_iovlen field instead of a size_t data type as specified in XNS4.0.
[Tru64 UNIX] If the compile-time option _SOCKADDR_LEN is defined before the <sys/socket.h> header file is included, the msghdr
structure takes 4.4BSD behavior. Otherwise, the default 4.3BSD msghdr structure is used. In 4.4BSD, the msghdr structure has a
separate msg_flags field for holding flags from the received message. In addition, the msg_accrights field is generalized into a
msg_control field. See the recvmsg() function for more information. If _SOCKADDR_LEN is defined, the 4.3BSD msghdr structure is
defined with the name omsghdr. Allows the sender to control the message transmission. The <sys/socket.h> file contains the flags
values. The flags value to send a call is formed by a logical OR of one or both of the following values:
Terminates a record (if supported by the protocol). Processes out-of-band data on sockets that support out-of-band data. [Tru64
UNIX] Sends without using routing tables. (Not recommended; for debugging purposes only.)
DESCRIPTION
The sendmsg() function sends messages through connected or unconnected sockets using the msghdr message structure. This minimizes the num-
ber of directly supplied parameters to the function call. The <sys/socket.h> file contains the msghdr structure and defines the structure
members.
If the sending socket has no space to hold the message to be transmitted, sendmsg() waits until space is available unless the socket is in
non-blocking I/O mode.
To broadcast on a socket, the application program must first issue a setsockopt() function using the SO_BROADCAST option to gain broadcast
permissions.
Use the select() and poll() functions to determine when to send more data.
NOTES
[Tru64 UNIX] When compiled in the X/Open UNIX environment, calls to the sendmsg() function are internally renamed by prepending _E to the
function name. When you are debugging a module that includes the sendmsg() function and for which _XOPEN_SOURCE_EXTENDED has been defined,
use _Esendmsg to refer to the sendmsg() call. See standards(5) for further information.
[Tru64 UNIX] When compiled in the POSIX.1g socket environment, calls to the sendmsg() function are internally renamed by prepending _P to
the function name. When you are debugging a module that includes the sendmsg() function and for which _POSIX_PII_SOCKET has been defined,
use _Psendmsg to refer to the sendmsg() call. See standards(5) for further information.
RETURN VALUES
Upon successful completion, the sendmsg() function returns the number of characters sent. Otherwise, a value of -1 is returned and errno
is set to indicate the error.
ERRORS
If the sendmsg() function fails, errno may be set to one of the following values: Search permission is denied for a component of the path
prefix; or write access to the named socket is denied. You cannot use addresses in the specified address family with this socket. The
socket parameter is not valid. A peer forcibly closed a connection. You did not specify a destination address for the connectionless
socket that also did not have its peer address set. The message parameter; storage pointed to by the msg_name, msg_control, or msg_iov
fields of the message parameter; or storage pointed to by the iovec structures pointed to by the msg_iov field are not in a readable or
writable part of user address-space. The destination host is unreachable. Possible reasons include the host is down or the router has no
route. A signal interrupted sendmsg before any data was transmitted. The sum of the iov_len values overflows an ssize_t. An I/O error
occurred while reading from or writing to the file system. The connection-oriented socket for which a destination address was specified is
already connected. Too many symbolic links were encountered in translating the pathname in the socket address. The message is too large
to be sent all at once, as the socket requires.
The value of the msg_iovlen member of the msghdr structure is less than or equal to zero (0) or is greater than IOV_MAX. For
AF_UNIX sockets, a component of the pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX characters. The
local network connection is not operational. The destination network is unreachable. Insufficient resources were available in the
system to complete the call.
[Tru64 UNIX] The interface driver's send queue is full. If the problem persists, you might increase the value for the ifqmaxlen
system attribute in the net subsystem. See sys_attrs_net(5) for more information. A component of the pathname does not name an
existing file or the pathname is an empty string. The system did not have sufficient memory to fulfill the request. The available
STREAMS resources were insufficient for the operation to complete. A socket is connection-oriented but is not connected. A compo-
nent of the path prefix of the pathname in address is not a directory. The socket parameter refers to a file, not a socket. The
socket argument is associated with a socket that does not support one or more of the values set in flags. 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 SOCK_STREAM, the SIGPIPE signal is generated to the calling process. The socket is marked nonblocking, and no
space is available for the sendmsg() function.
RELATED INFORMATION
Functions: recv(2), recvfrom(2), recvmsg(2), send(2), sendto(2), shutdown(2), socket(2), select(2), getsockopt(2), setsockopt(2)
Standards: standards(5) delim off
sendmsg(2)