sendmsg
![]() |
![]() |
![]() |
![]() |
sendmsg()
Send a message and its header to a socket
Synopsis:
#include <sys/types.h>
#include <sys/socket.h>
ssize_t sendmsg( int s,
const struct msghdr * msg,
int flags );
Arguments:
- s
- The descriptor for the socket; see socket().
- msg
- A pointer to the message that you want to send. For a description of the msghdr structure, see recvmsg().
- flags
- A combination of the following:
- MSG_OOB -- process out-of-band data. Use this bit when you send "out-of-band" data on sockets that support this notion (e.g. SOCK_STREAM). The underlying protocol must also support out-of-band data.
- MSG_DONTROUTE -- bypass routing; create a direct interface. You normally use this bit only in diagnostic or routing programs.

The tiny TCP/IP stack doesn't support MSG_OOB and MSG_DONTROUTE. For more information, see npm-ttcpip.so in the Utilities Reference.
Library:
libsocket
Use the -l socket option to qcc to link against this library.
Description:
The sendmsg() function is used to transmit a message to another socket. You can use send() only when the socket is in a connected state; you can use sendmsg() at any time.
No indication of failure to deliver is implicit in a sendmsg(). Locally detected errors are indicated by a return value of -1.
If no message space is available at the socket to hold the message to be transmitted, then sendmsg() normally blocks, unless the socket has been placed in nonblocking I/O mode. You can use select() to determine when it's possible to send more data.
Returns:
The number of bytes sent, or -1 if an error occurs (errno is set).
Errors:
- EBADF
- An invalid descriptor was specified.
- EDESTADDRREQ
- A destination address is required.
- EFAULT
- An invalid user space address was specified for a parameter.
- EMSGSIZE
- The socket requires that the message be sent atomically, but the size of the message made this impossible.
- ENOBUFS
- The system couldn't allocate an internal buffer. The operation may succeed when buffers become available.
- ENOTSOCK
- The argument s isn't a socket.
- EWOULDBLOCK
- The socket is marked nonblocking and the requested operation would block.
Classification:
| Safety: | |
|---|---|
| Cancellation point | Yes |
| Interrupt handler | No |
| Signal handler | No |
| Thread | Yes |
See also:
getsockopt(), ioctl(), recv(), select(), send(), sendto(), socket(), write()
![]() |
![]() |
![]() |
![]() |

![[Previous]](../prev.gif)
![[Contents]](../contents.gif)
![[Index]](../keyword_index.gif)
![[Next]](../next.gif)
