ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/sendto.htm

684 lines
18 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>sendto()--Send Data</title>
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- Begin Header Records ========================================== -->
<!-- Unix8 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
<!--End Header Records -->
<!-- Edited by Kersten Feb 02 -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<a name="Top_Of_Page"></a>
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<h2>sendto()--Send Data</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;BSD 4.3 Syntax<br>
<pre>
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
int sendto(int <em>socket_descriptor</em>,
char *<em>buffer</em>,
int <em>buffer_length</em>,
int <em>flags</em>,
struct sockaddr *<em>destination_address</em>,
int <em>address_length</em>)
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QSOSRV1<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<br>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;<a href="_xopen_source.htm">UNIX 98 Compatible Syntax</a><br>
<pre>
#define _XOPEN_SOURCE 520
#include &lt;sys/socket.h&gt;
ssize_t sendto(int <em>socket_descriptor</em>,
const void *<em>buffer</em>,
size_t <em>buffer_length</em>,
int <em>flags</em>,
const struct sockaddr *<em>destination_address</em>,
socklen_t <em>address_length</em>)
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QSOSRV1<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <em>sendto()</em> function is used to send data through a connected or
unconnected socket.</p>
<p> There are two versions of
the API, as shown above. The base i5/OS API uses BSD 4.3 structures and
syntax. The other uses syntax and structures compatible with the UNIX 98
programming interface specifications. You can select the UNIX 98 compatible
interface with the <a href="_xopen_source.htm">_XOPEN_SOURCE</a> macro.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>socket_descriptor</strong></dt>
<dd>(Input) The socket descriptor that is to be written to.<br>
<br>
</dd>
<dt><strong>buffer</strong></dt>
<dd>(Input) The pointer to the buffer in which the data that is to be written
is stored.<br>
<br>
</dd>
<dt><strong>buffer_length</strong></dt>
<dd>(Input) The length of the <em>buffer</em>.<br>
<br>
</dd>
<dt><strong>flags</strong></dt>
<dd>(Input) A flag value that controls the transmission of the data. The
<em>flags</em> value is either zero, or is obtained by performing an OR
operation on one or more of the following constants:
<table cellpadding="5">
<!-- cols="15 85" -->
<tr>
<td align="left" valign="top"><em><samp>MSG_EOR</samp></em></td>
<td align="left" valign="top">Terminate a record, if supported by the
protocol.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em><samp>MSG_OOB</samp></em></td>
<td align="left" valign="top">Send data as out-of-band data. Valid only for
sockets with an address family of <samp>AF_INET</samp> or <samp>AF_INET6</samp> and type <samp>SOCK_STREAM</samp>.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em><samp>MSG_DONTROUTE</samp></em></td>
<td align="left" valign="top">Bypass routing. Valid only for sockets with
address family of <samp>AF_INET</samp>. It is ignored for other address
families.</td>
</tr>
</table>
<br>
</dd>
<dt><strong>destination_address</strong></dt>
<dd>(Input) A pointer to a buffer of type <strong>struct sockaddr</strong> that
contains the destination address to which the data is to be sent. The structure
<strong>sockaddr</strong> is defined in <strong>&lt;sys/socket.h&gt;</strong>.
<p> The BSD 4.3 structure
is:</p>
<pre>
struct sockaddr {
u_short sa_family;
char sa_data[14];
};
</pre>
<p>The BSD 4.4/UNIX 98 compatible structure is:</p>
<pre>
typedef uchar sa_family_t;
struct sockaddr {
uint8_t sa_len;
sa_family_t sa_family;
char sa_data[14];
};
</pre>
<p>The BSD 4.4 <em>sa_len</em> field is the length of the address. The <em>sa_family</em> field identifies
the address family to which the address belongs, and <em>sa_data</em> is the
address whose format is dependent on the address family.</p>
</dd>
<dt><strong>address_length</strong></dt>
<dd>(Input) The length of the <em>destination_address</em>.</dd>
</dl>
<br>
<h3>Authorities</h3>
<p>When the address family of the socket identified by the
<strong><em>socket_descriptor</em></strong> is AF_INET and is running IP over
SNA, the thread must have retrieve, insert, delete, and update authority to the
APPC device. When the thread does not have this level of authority, an
<em>errno</em> of EACCES is returned.</p>
<br>
<h3>Return Value</h3>
<p><em>sendto()</em> returns an integer. Possible values are:</p>
<ul>
<li>-1 (unsuccessful)<br>
<br>
</li>
<li>n (successful), where n is the number of bytes sent.</li>
</ul>
<br>
<h3>Error Conditions</h3>
<p>When <em>sendto()</em> fails, <em>errno</em> can be set to one of the
following:</p>
<table cellpadding="5">
<!-- cols="20 80" -->
<tr>
<td align="left" valign="top"><em>[EACCES]</em></td>
<td align="left" valign="top">Permission denied.
<p>The process does not have the appropriate privileges to the destination
address.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EADDRNOTAVAIL]</em></td>
<td align="left" valign="top">Address not available.
<p>A socket with an address family of <samp>AF_INET</samp> or <samp>AF_INET6</samp>, is using a connectionless transport
service, and the socket was not bound. The system tried to bind the socket but
could not because a port was not available.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EBADF]</em></td>
<td align="left" valign="top">Descriptor not valid.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ECONNREFUSED]</em></td>
<td align="left" valign="top">The destination socket refused an attempted
connect operation.
<p>This error code can only be returned on sockets that use a connectionless
transport service.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EDESTADDRREQ]</em></td>
<td align="left" valign="top">Operation requires destination address.
<p>A destination address has not been associated with the socket pointed to by
the <em>socket_descriptor</em> parameter and a destination address was not
passed in as an argument on the <em>sendto()</em>. This error code can only be
returned on sockets that use a connectionless transport service.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EFAULT]</em></td>
<td align="left" valign="top">Bad address.
<p>The system detected an address which was not valid while attempting to
access the <em>buffer</em> or <em>destination_address</em> parameter.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EHOSTDOWN]</em></td>
<td align="left" valign="top">A remote host is not available.
<p>This error code can only be returned on sockets that use a connectionless
transport service.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EHOSTUNREACH]</em></td>
<td align="left" valign="top">A route to the remote host is not available.
<p>This error code can only be returned on sockets that use a connectionless
transport service.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EINTR]</em></td>
<td align="left" valign="top">Interrupted function call.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EINVAL]</em></td>
<td align="left" valign="top">Parameter not valid.
<p>This error code indicates one of the following:</p>
<ul>
<li>The <em>buffer_length</em> parameter specifies a negative value.<br>
<br>
</li>
<li>The socket is using a connectionless transport service and the
<em>address_length</em> parameter specifies a length that is not valid for the
address family.<br>
<br>
</li>
<li>The <em>socket_descriptor</em> points to a socket with an address family of
<samp>AF_UNIX_CCSID</samp>, and the CCSID specified in <em>sunc_qlg</em> in the
<strong>sockaddr_unc</strong> structure (pointed to by <em>local_address</em>)
cannot be converted to the current default CCSID for integrated file system
path names.<br>
<br>
</li>
<li>The <em>socket_descriptor</em> points to a socket with an address family of
<samp>AF_UNIX_CCSID</samp>, and there was an incomplete character or shift
state sequence at the end of <em>sunc_path</em> in the
<strong>sockaddr_unc</strong> structure (pointed to by
<em>local_address</em>).<br>
<br>
</li>
<li>The <em>socket_descriptor</em> points to a socket with an address family of
<samp>AF_UNIX_CCSID</samp>, and the <strong>sockaddr_unc</strong> structure
(pointed to by <em>local_address</em>) was not valid:
<ul>
<li>The sunc_format was not set to SO_UNC_DEFAULT or SO_UNC_USE_QLG.<br>
<br>
</li>
<li>The sunc_zero was not initialized to zeros.<br>
<br>
</li>
<li>The sunc_format field was set to SO_UNC_USE_QLG and the sunc_qlg structure
was not valid:
<ul>
<li>The path type was less than 0 or greater than 3.<br>
<br>
</li>
<li>The path length was less than 0 or out of bounds. For example, a
single-byte path name was greater than 126 bytes or a double-byte path name was
greater than 252 bytes.<br>
<br>
</li>
<li>A reserved field was not initialized to zeros.</li>
</ul>
</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EIO]</em></td>
<td align="left" valign="top">Input/output error.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EISCONN]</em></td>
<td align="left" valign="top">A connection has already been established.
<p>A destination address was set, but the socket pointed to by the
<em>socket_descriptor</em> parameter already has a destination address
associated with it.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ELOOP]</em></td>
<td align="left" valign="top">A loop exists in symbolic links encountered
during pathname resolution.
<p>This error code refers to the destination address, and can only be returned
on sockets that use the <samp>AF_UNIX</samp> or <samp>AF_UNIX_CCSID</samp>
address family.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EMSGSIZE]</em></td>
<td align="left" valign="top">Message size out of range.
<p>The data to be sent could not be sent atomically because the total size of
the data to be sent is too large.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENAMETOOLONG]</em></td>
<td align="left" valign="top">File name too long.
<p>This error code refers to the destination address, and can only be returned
on sockets that use the <samp>AF_UNIX</samp> or <samp>AF_UNIX_CCSID</samp>
address family.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENETDOWN]</em></td>
<td align="left" valign="top">The network is not currently available.
<p>This error code can only be returned on sockets that use a connectionless
transport service.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENETUNREACH]</em></td>
<td align="left" valign="top">Cannot reach the destination network.
<p>This error code can only be returned on sockets that use a connectionless
transport service.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENOBUFS]</em></td>
<td align="left" valign="top">There is not enough buffer space for the
requested operation.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENOENT]</em></td>
<td align="left" valign="top">No such file or directory.
<p>This error code refers to the destination address, and can only be returned
on sockets that use the <samp>AF_UNIX</samp> or <samp>AF_UNIX_CCSID</samp>
address family.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENOSYS]</em></td>
<td align="left" valign="top">Function not implemented.
<p>This error code refers to the destination address, and can only be returned
on sockets that use the <samp>AF_UNIX</samp> or <samp>AF_UNIX_CCSID</samp>
address family.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENOTCONN]</em></td>
<td align="left" valign="top">Requested operation requires a connection.
<p>This error code can only be returned on sockets that use a
connection-oriented transport service.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENOTDIR]</em></td>
<td align="left" valign="top">Not a directory.
<p>This error code refers to the destination address, and can only be returned
on sockets that use the <samp>AF_UNIX</samp> or <samp>AF_UNIX_CCSID</samp>
address family.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENOTSOCK]</em></td>
<td align="left" valign="top">The specified descriptor does not reference a
socket.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EOPNOTSUPP]</em></td>
<td align="left" valign="top">Operation not supported.
<p>This error code indicates one of the following:</p>
<ul>
<li>The <em>flags</em> parameter specifies a value that includes the
<samp>MSG_OOB</samp> flag, but the <em>socket_descriptor</em> parameter points
to a connectionless socket.<br>
<br>
</li>
<li>The <em>flags</em> parameter specifies a value that includes the
<samp>MSG_OOB</samp> flag, but the <em>socket_descriptor</em> parameter points
to a socket that does not have an address family of <samp>AF_INET</samp> or <samp>AF_INET6</samp>.</li>
</ul>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EPIPE]</em></td>
<td align="left" valign="top">Broken pipe.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EPROTOTYPE]</em></td>
<td align="left" valign="top">The socket type or protocols are not compatible.
<p>This error code is only returned on sockets that use the
<samp>AF_UNIX</samp> or the <samp>AF_UNIX_CCSID</samp> address family.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EUNATCH]</em></td>
<td align="left" valign="top">The protocol required to support the specified
address family is not available at this time.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EUNKNOWN]</em></td>
<td align="left" valign="top">Unknown system state.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EWOULDBLOCK]</em></td>
<td align="left" valign="top">Operation would have caused the thread to be
suspended.<br>
<br>
</td>
</tr>
</table>
<br>
<br>
<h3>Error Messages</h3>
<table width="100%" cellpadding="5">
<!-- cols="15 85" -->
<tr>
<th align="left" valign="top">Message ID</th>
<th align="left" valign="top">Error Message Text</th>
</tr>
<tr>
<td width="15%" valign="top">CPE3418 E</td>
<td width="85%" valign="top">Possible APAR condition or hardware failure.</td>
</tr>
<tr>
<td align="left" valign="top">CPF9872 E</td>
<td align="left" valign="top">Program or service program &amp;1 in library
&amp;2 ended. Reason code &amp;3.</td>
</tr>
<tr>
<td align="left" valign="top">CPFA081 E</td>
<td align="left" valign="top">Unable to set return value or error code.</td>
</tr>
</table>
<br>
<br>
<h3>Usage Notes</h3>
<ol>
<li>A destination address cannot be specified if the socket pointed to by the
<em>socket_descriptor</em> parameter already has a destination address
associated with it. To <strong>not</strong> specify an address, users must set
the <em>destination_address</em> field to NULL or set the
<em>address_length</em> field to zero. (Not specifying an address by setting
the <em>address_length</em> field to zero is an IBM extension.)
<p><strong>Note:</strong> The <em>destination_address</em> and
<em>address_length</em> fields are ignored if the socket is using a
connection-oriented transport service.</p>
</li>
<li>If the socket is using a connectionless transport device, the socket is not
bound to an address, and the socket type is <samp>SOCK_DGRAM</samp>, the system
automatically selects an address (INADDR_ANY or in6addr_any and an available port number) and binds it to the socket
before sending the data.<br>
<br>
</li>
<li>To broadcast on an <samp>AF_INET</samp> socket, the socket option
<samp>SO_BROADCAST</samp> must be set (with a <em>setsockopt()</em>).<br>
<br>
</li>
<li>When using a connection-oriented transport service, all errors except
<samp>[EUNATCH]</samp> and <samp>[EUNKNOWN]</samp> are mapped to
<samp>[EPIPE]</samp> on an output operation when either of the following
occurs:
<ul>
<li>A connection that is in progress is unsuccessful.</li>
<li>An established connection is broken.</li>
</ul>
<p>To get the actual error, use <em>getsockopt()</em> with the
<samp>SO_ERROR</samp> option, or perform an input operation (for example,
<em>read()</em>).</p>
</li>
<li>If the socket is using an address family of <samp>AF_UNIX</samp>, the
destination address (which is a path name) is assumed to be in the default
coded character set identifier (CCSID) currently in effect for the job. For
<samp>AF_UNIX_CCSID</samp>, the destination address is assumed to be in the
format and coded character set identifier (CCSID) specified in the
<strong>sockaddr_unc</strong>.<br>
<br>
</li>
<li>When you develop in C-based
languages and an application is compiled with the _XOPEN_SOURCE macro defined
to the value 520 or greater, the <em>sendto()</em> API is mapped to
<em>qso_sendto98()</em>.</li>
</ol>
<br>
<h3>Related Information</h3>
<ul>
<li><a href=
"_xopen_source.htm">_XOPEN_SOURCE</a>--Using _XOPEN_SOURCE for the UNIX 98
compatible interface<br>
<br>
</li>
<li><a href="fcntl.htm">fcntl()</a>--Perform File Control Command<br>
<br>
</li>
<li><a href="ioctl.htm">ioctl()</a>--Perform I/O Control Request<br>
<br>
</li>
<li><a href="send.htm">send()</a>--Send Data<br>
<br>
</li>
<li><a href="sendms.htm">sendmsg()</a>--Send Data or Descriptors or Both</li>
</ul>
<br>
<hr>
API introduced: V3R1
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> |
<a href="unix.htm">UNIX-Type APIs</a> |
<a href="aplist.htm">APIs by category</a> </td>
</tr>
</table>
</center>
</body>
</html>