Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/sendmsg.html
2024-02-19 00:21:47 -05:00

296 lines
9.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>sendmsg</title>
</head>
<body bgcolor="white">
<basefont size="3"> <a name="sendmsg"></a> <a name="tag_03_642"></a><!-- sendmsg -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_642_01"></a>NAME</h4>
<blockquote>sendmsg - send a message on a socket using a message structure</blockquote>
<h4><a name="tag_03_642_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/sys/socket.h.html">sys/socket.h</a>&gt;<br>
<br>
ssize_t sendmsg(int</tt> <i>socket</i><tt>, const struct msghdr *</tt><i>message</i><tt>, int</tt> <i>flags</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_642_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>sendmsg</i>() function shall send a message through a connection-mode or connectionless-mode socket. If the socket is
connectionless-mode, the message shall be sent to the address specified by <b>msghdr</b>. If the socket is connection-mode, the
destination address in <b>msghdr</b> shall be ignored.</p>
<p>The <i>sendmsg</i>() function takes the following arguments:</p>
<dl compact>
<dt><i>socket</i></dt>
<dd>Specifies the socket file descriptor.</dd>
<dt><i>message</i></dt>
<dd>Points to a <b>msghdr</b> structure, containing both the destination address and the buffers for the outgoing message. The
length and format of the address depend on the address family of the socket. The <i>msg_flags</i> member is ignored.</dd>
<dt><i>flags</i></dt>
<dd>Specifies the type of message transmission. The application may specify 0 or the following flag:
<dl compact>
<dt>MSG_EOR</dt>
<dd>Terminates a record (if supported by the protocol).</dd>
<dt>MSG_OOB</dt>
<dd>Sends out-of-band data on sockets that support out-of-bound data. The significance and semantics of out-of-band data are
protocol-specific.</dd>
</dl>
</dd>
</dl>
<p>The <i>msg_iov</i> and <i>msg_iovlen</i> fields of <i>message</i> specify zero or more buffers containing the data to be sent.
<i>msg_iov</i> points to an array of <b>iovec</b> structures; <i>msg_iovlen</i> shall be set to the dimension of this array. In
each <b>iovec</b> structure, the <i>iov_base</i> field specifies a storage area and the <i>iov_len</i> field gives its size in
bytes. Some of these sizes can be zero. The data from each storage area indicated by <i>msg_iov</i> is sent in turn.</p>
<p>Successful completion of a call to <i>sendmsg</i>() does not guarantee delivery of the message. A return value of -1 indicates
only locally-detected errors.</p>
<p>If space is not available at the sending socket to hold the message to be transmitted and the socket file descriptor does not
have O_NONBLOCK set, the <i>sendmsg</i>() function shall block 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 O_NONBLOCK set, the <i>sendmsg</i>() function
shall fail.</p>
<p>If the socket protocol supports broadcast and the specified address is a broadcast address for the socket protocol,
<i>sendmsg</i>() shall fail if the SO_BROADCAST option is not set for the socket.</p>
<p>The socket in use may require the process to have appropriate privileges to use the <i>sendmsg</i>() function.</p>
</blockquote>
<h4><a name="tag_03_642_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>sendmsg</i>() shall return the number of bytes sent. Otherwise, -1 shall be returned and
<i>errno</i> set to indicate the error.</p>
</blockquote>
<h4><a name="tag_03_642_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>sendmsg</i>() function shall fail if:</p>
<dl compact>
<dt>[EAGAIN] or [EWOULDBLOCK]</dt>
<dd>
The socket's file descriptor is marked O_NONBLOCK and the requested operation would block.</dd>
<dt>[EAFNOSUPPORT]</dt>
<dd>
Addresses in the specified address family cannot be used with this socket.</dd>
<dt>[EBADF]</dt>
<dd>The <i>socket</i> argument is not a valid file descriptor.</dd>
<dt>[ECONNRESET]</dt>
<dd>A connection was forcibly closed by a peer.</dd>
<dt>[EINTR]</dt>
<dd>A signal interrupted <i>sendmsg</i>() before any data was transmitted.</dd>
<dt>[EINVAL]</dt>
<dd>The sum of the <i>iov_len</i> values overflows an <b>ssize_t</b>.</dd>
<dt>[EMSGSIZE]</dt>
<dd>The message is too large to be sent all at once (as the socket requires), or the <i>msg_iovlen</i> member of the <b>msghdr</b>
structure pointed to by <i>message</i> is less than or equal to 0 or is greater than {IOV_MAX}.</dd>
<dt>[ENOTCONN]</dt>
<dd>The socket is connection-mode but is not connected.</dd>
<dt>[ENOTSOCK]</dt>
<dd>The <i>socket</i> argument does not refer to a socket.</dd>
<dt>[EOPNOTSUPP]</dt>
<dd>The <i>socket</i> argument is associated with a socket that does not support one or more of the values set in
<i>flags</i>.</dd>
<dt>[EPIPE]</dt>
<dd>The socket is shut down for writing, or the socket is connection-mode and is no longer connected. In the latter case, and if
the socket is of type SOCK_STREAM, the SIGPIPE signal is generated to the calling thread.</dd>
</dl>
<p>If the address family of the socket is AF_UNIX, then <i>sendmsg</i>() shall fail if:</p>
<dl compact>
<dt>[EIO]</dt>
<dd>An I/O error occurred while reading from or writing to the file system.</dd>
<dt>[ELOOP]</dt>
<dd>A loop exists in symbolic links encountered during resolution of the pathname in the socket address.</dd>
<dt>[ENAMETOOLONG]</dt>
<dd>
A component of a pathname exceeded {NAME_MAX} characters, or an entire pathname exceeded {PATH_MAX} characters.</dd>
<dt>[ENOENT]</dt>
<dd>A component of the pathname does not name an existing file or the path name is an empty string.</dd>
<dt>[ENOTDIR]</dt>
<dd>A component of the path prefix of the pathname in the socket address is not a directory.</dd>
</dl>
<p>The <i>sendmsg</i>() function may fail if:</p>
<dl compact>
<dt>[EACCES]</dt>
<dd>Search permission is denied for a component of the path prefix; or write access to the named socket is denied.</dd>
<dt>[EDESTADDRREQ]</dt>
<dd>
The socket is not connection-mode and does not have its peer address set, and no destination address was specified.</dd>
<dt>[EHOSTUNREACH]</dt>
<dd>
The destination host cannot be reached (probably because the host is down or a remote router cannot reach it).</dd>
<dt>[EIO]</dt>
<dd>An I/O error occurred while reading from or writing to the file system.</dd>
<dt>[EISCONN]</dt>
<dd>A destination address was specified and the socket is already connected.</dd>
<dt>[ENETDOWN]</dt>
<dd>The local network interface used to reach the destination is down.</dd>
<dt>[ENETUNREACH]</dt>
<dd>
No route to the network is present.</dd>
<dt>[ENOBUFS]</dt>
<dd>Insufficient resources were available in the system to perform the operation.</dd>
<dt>[ENOMEM]</dt>
<dd>Insufficient memory was available to fulfill the request.</dd>
</dl>
<p>If the address family of the socket is AF_UNIX, then <i>sendmsg</i>() may fail if:</p>
<dl compact>
<dt>[ELOOP]</dt>
<dd>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the pathname in the socket address.</dd>
<dt>[ENAMETOOLONG]</dt>
<dd>
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_642_06"></a>EXAMPLES</h4>
<blockquote>
<p>Done.</p>
</blockquote>
<h4><a name="tag_03_642_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>The <a href="../functions/select.html"><i>select</i>()</a> and <a href="../functions/poll.html"><i>poll</i>()</a> functions can
be used to determine when it is possible to send more data.</p>
</blockquote>
<h4><a name="tag_03_642_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_642_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_642_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="getsockopt.html"><i>getsockopt</i>()</a> , <a href="poll.html"><i>poll</i>()</a> , <a href=
"recv.html"><i>recv</i>()</a> , <a href="recvfrom.html"><i>recvfrom</i>()</a> , <a href="recvmsg.html"><i>recvmsg</i>()</a> , <a
href="select.html"><i>select</i>()</a> , <a href="send.html"><i>send</i>()</a> , <a href="sendto.html"><i>sendto</i>()</a> , <a
href="setsockopt.html"><i>setsockopt</i>()</a> , <a href="shutdown.html"><i>shutdown</i>()</a> , <a href=
"socket.html"><i>socket</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/sys/socket.h.html"><i>&lt;sys/socket.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_642_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</p>
<p>The wording of the mandatory [ELOOP] error condition is updated, and a second optional [ELOOP] error condition is added.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>