sendmsg(2) — System Calls
NAME
sendmsg - Sends a message from a socket using a message structure
SYNOPSIS
#include <sys/types.h> #include <sys/socket.h> int sendmsg ( int socket,
struct msghdr ∗message,
int flags );
PARAMETERS
socketSpecifies the socket descriptor.
messagePoints 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. 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.
flagsAllows 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:
MSG_OOBProcesses out-of-band data on sockets that support out-of-band data.
MSG_DONTROUTE
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 number of directly supplied parameters to the function call. The <sys/socket.h> file contains the msghdr structure and defines the structure members.
To broadcast on a socket, the application program must first issue a setsockopt() function using the SO_BROADCAST option to gain broadcast permissions.
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:
[EBADF]The socket parameter is not valid.
[EMSGSIZE]The message is too large to be sent all at once, as the socket requires.
[ENOTSOCK]The socket parameter refers to a file, not a socket.
[EWOULDBLOCK]
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)