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

642 lines
17 KiB
HTML
Raw 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>recvfrom()--Receive Data</title>
<!-- Begin Header Records ========================================== -->
<!-- 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. -->
<!-- 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 -->
<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>recvfrom()--Receive 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 recvfrom(int <em>socket_descriptor</em>,
char *<em>buffer</em>,
int <em>buffer_length</em>,
int <em>flags</em>,
struct sockaddr *<em>from_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 recvfrom(int <em>socket_descriptor</em>,
void *<em>buffer</em>,
size_t <em>buffer_length</em>,
int <em>flags</em>,
struct sockaddr *<em>from_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>recvfrom()</em> function is used to receive 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 read from.<br>
<br>
</dd>
<dt><strong>buffer</strong></dt>
<dd>(Input) The pointer to the buffer in which the data that is to be read is
stored.<br>
<br>
</dd>
<dt><strong>buffer_length</strong></dt>
<dd>(Input) The length of the <em>buffer</em>.<br>
<br>
</dd>
<dt>int <strong>flags</strong></dt>
<dd>(Input) A flag value that controls the reception 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_OOB</samp></em></td>
<td align="left" valign="top">Receive 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>.</td>
</tr>
<tr>
<td align="left" valign="top"><em><samp>MSG_PEEK</samp></em></td>
<td align="left" valign="top">Obtain a copy of the message without removing the
message from the socket.</td>
</tr>
<tr>
<td align="left" valign="top"><em><samp>MSG_WAITALL</samp></em></td>
<td align="left" valign="top">Wait for a full request or an error.</td>
</tr>
</table>
<br>
<br>
</dd>
<dt><strong>from_address</strong></dt>
<dd>(Output) A pointer to a buffer of type <strong>struct sockaddr</strong>
that contains the address from which the message was received.
<p>The structure <strong>sockaddr</strong> is defined in
<strong>&lt;sys/socket.h&gt;</strong>.</p>
<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>
<p> <strong>Note:</strong> See
the usage notes about using different address families with
<strong>sockaddr_storage</strong>.</p>
<br>
<br>
</dd>
<dt><strong>address_length</strong></dt>
<dd>(Input/output) This parameter is a value-result field. The caller passes a
pointer to the length of the <em>from_address</em> parameter. On return from
the call, <em>address_length</em> will contain the actual length of the
address.</dd>
</dl>
<br>
<h3>Authorities</h3>
<p>An <em>errno</em> of EACCES is returned when the socket pointed to by the
<strong><em>socket_descriptor</em></strong> field is address family AF_INET and
a nonblocking connect was attempted previously and was not successful. The
nonblocking connect was not successful because the thread did not have
authority to the associated APPC device. The thread performing the nonblocking
connect must have retrieve, insert, delete, and update authority to the APPC
device.</p>
<br>
<h3>Return Value</h3>
<p><em>recvfrom()</em> returns an integer. Possible values are:</p>
<ul>
<li>-1 (unsuccessful)</li>
<li>n (successful), where n is the number of bytes received.</li>
</ul>
<br>
<h3>Error Conditions</h3>
<p>When <em>recvfrom()</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 socket pointed to by the <em>socket_descriptor</em> parameter is using a
connection-oriented transport service, and a <em>connect()</em> was previously
completed. The process, however, does not have the appropriate privileges to
the objects that were needed to establish a connection. For example, the
<em>connect()</em> required the use of an APPC device that the process was not
authorized to.</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>[ECONNABORTED]</em></td>
<td align="left" valign="top">Connection ended abnormally.
<p>This error code indicates that the transport provider ended the connection
abnormally because of one of the following:</p>
<ul>
<li>The retransmission limit has been reached for data that was being sent on
the socket.<br>
<br>
</li>
<li>A protocol error was detected.<br>
</li>
</ul>
</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.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ECONNRESET]</em></td>
<td align="left" valign="top">A connection with a remote socket was reset by
that socket.<br>
<br>
</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>, <em>from_address</em>, or <em>address_length</em>
parameter.</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 <em>flags</em> parameter specifies a value that includes the
<samp>MSG_OOB</samp> flag, but no OOB data was available to be received.<br>
<br>
</li>
<li>The <em>flags</em> parameter specifies a value that includes the
<samp>MSG_OOB</samp> flag, and the socket option <samp>SO_OOBINLINE</samp> has
been set.<br>
<br>
</li>
<li>The <em>socket_descriptor</em> parameter points to a socket that is using a
connectionless transport service, is not a socket of type
<samp>SOCK_RAW</samp>, and is not bound to an address.<br>
</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>[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>[ENOTCONN]</em></td>
<td align="left" valign="top">Requested operation requires a connection.
<p>This error code is returned only on sockets that use a connection-oriented
transport service.</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>.<br>
</li>
</ul>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ETIMEDOUT]</em></td>
<td align="left" valign="top">A remote host did not respond within the timeout
period.
<p>A non-blocking <em>connect()</em> was previously issued that resulted in the
connection establishment timing out. No connection is established. This error
code is returned only on sockets that use a connection-oriented transport
service.</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.</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>For sockets that use a connection-oriented transport service (for example,
sockets with a type of <samp>SOCK_STREAM</samp>), a returned value of zero
indicates one of the following:
<ul>
<li>The partner program has issued a <em>close()</em> for the socket.<br>
<br>
</li>
<li>The partner program has issued a <em>shutdown()</em> to disable writing to
the socket.<br>
<br>
</li>
<li>The connection is broken and the error was returned on a previously issued
socket function.<br>
<br>
</li>
<li>A <em>shutdown()</em> to disable reading was previously done on the
socket.</li>
</ul>
<br>
<br>
</li>
<li>If the socket is using a connection-oriented transport service, the
<em>from_address</em> and <em>address_length</em> parameters are ignored.<br>
<br>
</li>
<li>The following applies to sockets that use a connectionless transport
service (for example, a socket with a type of <samp>SOCK_DGRAM</samp>):
<ul>
<li>If a <em>connect()</em> has been issued previously, then data can be
received only from the address specified in the previous
<em>connect()</em>.<br>
<br>
</li>
<li>If the <em>from_address</em> parameter is set to NULL or
<em>address_length</em> specifies a value of zero, the address from which data
is received is discarded by the system.<br>
<br>
</li>
<li>If the length of the address to be returned exceeds the length of the
<em>from_address</em> parameter, the returned address is truncated.<br><br></li>
<li>The structure
<strong>sockaddr</strong> is a generic structure used for any address family
but it is only 16 bytes long. The actual address returned for some address
families may be much larger. You should declare storage for the address with
the structure <strong>sockaddr_storage</strong>. This structure is large enough
and aligned for any protocol-specific structure. It may then be cast as
<strong>sockaddr</strong> structure for use on the APIs. The <em>ss_family</em>
field of the <strong>sockaddr_storage</strong> will always align with the
family field of any protocol-specific structure.
<p>The BSD 4.3 structure is:</p>
<pre>
#define _SS_MAXSIZE 304
#define _SS_ALIGNSIZE (sizeof (char*))
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(sa_family_t))
#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof(sa_family_t)+
_SS_PAD1SIZE + _SS_ALIGNSIZE))
struct sockaddr_storage {
sa_family_t ss_family;
char _ss_pad1[_SS_PAD1SIZE];
char* _ss_align;
char _ss_pad2[_SS_PAD2SIZE];
};
</pre>
<p>The BSD 4.4/UNIX 98 compatible structure is:</p>
<pre>
#define _SS_MAXSIZE 304
#define _SS_ALIGNSIZE (sizeof (char*))
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - (sizeof(uint8_t) + sizeof(sa_family_t)))
#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof(uint8_t) + sizeof(sa_family_t)+
_SS_PAD1SIZE + _SS_ALIGNSIZE))
struct sockaddr_storage {
uint8_t ss_len;
sa_family_t ss_family;
char _ss_pad1[_SS_PAD1SIZE];
char* _ss_align;
char _ss_pad2[_SS_PAD2SIZE];
};
</pre>
<br>
</li>
<li>If the socket is using an address family of <samp>AF_UNIX</samp>, the
address (which is a path name) is returned in the default coded character set
identifier (CCSID) currently in effect for the job.<br>
<br>
</li>
<li>If the socket is using an address family of <samp>AF_UNIX_CCSID</samp>, the
output structure sockaddr_unc defines the format and coded character set
identifier (CCSID) of the address (which is a path name).<br>
<br>
</li>
<li>The entire message must be read in a single read operation. If the size of
the message is too large to fit in the user supplied buffer, the remaining
bytes of the message are discarded.<br>
<br>
</li>
<li>A returned value of zero indicates one of the following:
<ul>
<li>The partner program has sent a NULL message (a datagram with no user
data).<br>
<br>
</li>
<li>A <em>shutdown()</em> to disable reading was previously done on the
socket.<br>
<br>
</li>
<li>The buffer length specified was zero.</li>
</ul>
</li>
</ul>
<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>recvfrom()</em> API is mapped to
<em>qso_recvfrom98()</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="recv.htm">recv()</a>--Receive Data<br>
<br>
</li>
<li><a href="recvms.htm">recvmsg()</a>--Receive 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>