Index Click this button to go to the index for this section.


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 ); [Digital] 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(): XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags.

PARAMETERS

socket Specifies the socket descriptor. message 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. [Digital] 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. flags 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: MSG_OOB Processes 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.

NOTES

[Digital] 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.

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: [EACCESS] Search permission is denied for a component of the path prefix; or write access to the named socket is denied. [EAFNOSUPPORT] Addresses in the specified address family cannot be used with this socket. [EBADF] The socket parameter is not valid. [ECONNRESET] A connection was forcibly closed by a peer. [EINTR] A signal interrupted sendmsg before any data was transmitted. [EINVAL] The sum of the iov_len values overflows an ssize_t. [EIO] An I/O error occurred while reading from or writing to the file system. [ELOOP] Too many symbolic links were encountered in translating the pathname in the socket address. [EMSGSIZE] The message is too large to be sent all at once, as the socket requires. [ENAMETOOLONG] A component of the pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX characters. [ENOENT] A component of the pathname does not name an existing file or the pathname is an empty string. [ENOTCONN] A socket is connection-oriented but is not connected. [ENOTDIR] A component of the path prefix of the pathname in address is not a directory. [ENOTSOCK] The socket parameter refers to a file, not 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 SOCK_STREAM, the SIGPIPE signal is generated to the calling process. [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) Standards: standards(5)