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

308 lines
9.7 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>sendto</title>
</head>
<body bgcolor="white">
<basefont size="3"> <a name="sendto"></a> <a name="tag_03_643"></a><!-- sendto -->
<!--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_643_01"></a>NAME</h4>
<blockquote>sendto - send a message on a socket</blockquote>
<h4><a name="tag_03_643_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 sendto(int</tt> <i>socket</i><tt>, const void *</tt><i>message</i><tt>, size_t</tt> <i>length</i><tt>,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int</tt> <i>flags</i><tt>, const struct sockaddr *</tt><i>dest_addr</i><tt>,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; socklen_t</tt> <i>dest_len</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_643_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>sendto</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 <i>dest_addr</i>. If the socket is connection-mode,
<i>dest_addr</i> shall be ignored.</p>
<p>The <i>sendto</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 buffer containing the message to be sent.</dd>
<dt><i>length</i></dt>
<dd>Specifies the size of the message in bytes.</dd>
<dt><i>flags</i></dt>
<dd>Specifies the type of message transmission. Values of this argument are formed by logically OR'ing zero or more of the
following flags:
<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-band data. The significance and semantics of out-of-band data are
protocol-specific.</dd>
</dl>
</dd>
<dt><i>dest_addr</i></dt>
<dd>Points to a <b>sockaddr</b> structure containing the destination address. The length and format of the address depend on the
address family of the socket.</dd>
<dt><i>dest_len</i></dt>
<dd>Specifies the length of the <b>sockaddr</b> structure pointed to by the <i>dest_addr</i> argument.</dd>
</dl>
<p>If the socket protocol supports broadcast and the specified address is a broadcast address for the socket protocol,
<i>sendto</i>() shall fail if the SO_BROADCAST option is not set for the socket.</p>
<p>The <i>dest_addr</i> argument specifies the address of the target. The <i>length</i> argument specifies the length of the
message.</p>
<p>Successful completion of a call to <i>sendto</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, <i>sendto</i>() 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, <i>sendto</i>() shall fail.</p>
<p>The socket in use may require the process to have appropriate privileges to use the <i>sendto</i>() function.</p>
</blockquote>
<h4><a name="tag_03_643_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>sendto</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_643_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>sendto</i>() function shall fail if:</p>
<dl compact>
<dt>[EAFNOSUPPORT]</dt>
<dd>
Addresses in the specified address family cannot be used with this socket.</dd>
<dt>[EAGAIN] or [EWOULDBLOCK]</dt>
<dd>
The socket's file descriptor is marked O_NONBLOCK and the requested operation would block.</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>sendto</i>() before any data was transmitted.</dd>
<dt>[EMSGSIZE]</dt>
<dd>The message is too large to be sent all at once, as the socket requires.</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>sendto</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 pathname 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>sendto</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>[EINVAL]</dt>
<dd>The <i>dest_len</i> argument is not a valid length for the address family.</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. This error may or may not be returned for connection
mode sockets.</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>sendto</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_643_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_643_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_643_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_643_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_643_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="sendmsg.html"><i>sendmsg</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_643_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>