248 lines
9.3 KiB
HTML
248 lines
9.3 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>recvfrom</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="recvfrom"></a> <a name="tag_03_601"></a><!-- recvfrom -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_601_01"></a>NAME</h4>
|
|
|
|
<blockquote>recvfrom - receive a message from a socket</blockquote>
|
|
|
|
<h4><a name="tag_03_601_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/sys/socket.h.html">sys/socket.h</a>><br>
|
|
<br>
|
|
ssize_t recvfrom(int</tt> <i>socket</i><tt>, void *restrict</tt> <i>buffer</i><tt>, size_t</tt> <i>length</i><tt>,<br>
|
|
int</tt> <i>flags</i><tt>, struct sockaddr *restrict</tt> <i>address</i><tt>,<br>
|
|
socklen_t *restrict</tt> <i>address_len</i><tt>);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_601_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>recvfrom</i>() function shall receive a message from a connection-mode or connectionless-mode socket. It is normally used
|
|
with connectionless-mode sockets because it permits the application to retrieve the source address of received data.</p>
|
|
|
|
<p>The <i>recvfrom</i>() function takes the following arguments:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>socket</i></dt>
|
|
|
|
<dd>Specifies the socket file descriptor.</dd>
|
|
|
|
<dt><i>buffer</i></dt>
|
|
|
|
<dd>Points to the buffer where the message should be stored.</dd>
|
|
|
|
<dt><i>length</i></dt>
|
|
|
|
<dd>Specifies the length in bytes of the buffer pointed to by the <i>buffer</i> argument.</dd>
|
|
|
|
<dt><i>flags</i></dt>
|
|
|
|
<dd>Specifies the type of message reception. Values of this argument are formed by logically OR'ing zero or more of the following
|
|
values:
|
|
|
|
<dl compact>
|
|
<dt>MSG_PEEK</dt>
|
|
|
|
<dd>Peeks at an incoming message. The data is treated as unread and the next <i>recvfrom</i>() or similar function shall still
|
|
return this data.</dd>
|
|
|
|
<dt>MSG_OOB</dt>
|
|
|
|
<dd>Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific.</dd>
|
|
|
|
<dt>MSG_WAITALL</dt>
|
|
|
|
<dd>On SOCK_STREAM sockets this requests that the function block until the full amount of data can be returned. The function may
|
|
return the smaller amount of data if the socket is a message-based socket, if a signal is caught, if the connection is terminated,
|
|
if MSG_PEEK was specified, or if an error is pending for the socket.</dd>
|
|
</dl>
|
|
</dd>
|
|
|
|
<dt><i>address</i></dt>
|
|
|
|
<dd>A null pointer, or points to a <b>sockaddr</b> structure in which the sending address is to be stored. The length and format of
|
|
the address depend on the address family of the socket.</dd>
|
|
|
|
<dt><i>address_len</i></dt>
|
|
|
|
<dd>Specifies the length of the <b>sockaddr</b> structure pointed to by the <i>address</i> argument.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>recvfrom</i>() function shall return the length of the message written to the buffer pointed to by the <i>buffer</i>
|
|
argument. For message-based sockets, such as <sup>[<a href="javascript:open_code('RS')">RS</a>]</sup> <img src=
|
|
"../images/opt-start.gif" alt="[Option Start]" border="0"> SOCK_RAW, <img src="../images/opt-end.gif" alt="[Option End]"
|
|
border="0"> SOCK_DGRAM, and SOCK_SEQPACKET, the entire message shall be read in a single operation. If a message is too long to fit
|
|
in the supplied buffer, and MSG_PEEK is not set in the <i>flags</i> argument, the excess bytes shall be discarded. For stream-based
|
|
sockets, such as SOCK_STREAM, message boundaries shall be ignored. In this case, data shall be returned to the user as soon as it
|
|
becomes available, and no data shall be discarded.</p>
|
|
|
|
<p>If the MSG_WAITALL flag is not set, data shall be returned only up to the end of the first message.</p>
|
|
|
|
<p>Not all protocols provide the source address for messages. If the <i>address</i> argument is not a null pointer and the protocol
|
|
provides the source address of messages, the source address of the received message shall be stored in the <b>sockaddr</b>
|
|
structure pointed to by the <i>address</i> argument, and the length of this address shall be stored in the object pointed to by the
|
|
<i>address_len</i> argument.</p>
|
|
|
|
<p>If the actual length of the address is greater than the length of the supplied <b>sockaddr</b> structure, the stored address
|
|
shall be truncated.</p>
|
|
|
|
<p>If the <i>address</i> argument is not a null pointer and the protocol does not provide the source address of messages, the value
|
|
stored in the object pointed to by <i>address</i> is unspecified.</p>
|
|
|
|
<p>If no messages are available at the socket and O_NONBLOCK is not set on the socket's file descriptor, <i>recvfrom</i>() shall
|
|
block until a message arrives. If no messages are available at the socket and O_NONBLOCK is set on the socket's file descriptor,
|
|
<i>recvfrom</i>() shall fail and set <i>errno</i> to [EAGAIN] or [EWOULDBLOCK].</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_601_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, <i>recvfrom</i>() shall return the length of the message in bytes. If no messages are available to
|
|
be received and the peer has performed an orderly shutdown, <i>recvfrom</i>() shall return 0. Otherwise, the function shall return
|
|
-1 and set <i>errno</i> to indicate the error.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_601_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>recvfrom</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EAGAIN] or [EWOULDBLOCK]</dt>
|
|
|
|
<dd><br>
|
|
The socket's file descriptor is marked O_NONBLOCK and no data is waiting to be received; or MSG_OOB is set and no out-of-band data
|
|
is available and either the socket's file descriptor is marked O_NONBLOCK or the socket does not support blocking to await
|
|
out-of-band data.</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>recvfrom</i>() before any data was available.</dd>
|
|
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>The MSG_OOB flag is set and no out-of-band data is available.</dd>
|
|
|
|
<dt>[ENOTCONN]</dt>
|
|
|
|
<dd>A receive is attempted on a connection-mode socket that 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 specified flags are not supported for this socket type.</dd>
|
|
|
|
<dt>[ETIMEDOUT]</dt>
|
|
|
|
<dd>The connection timed out during connection establishment, or due to a transmission timeout on active connection.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>recvfrom</i>() function may 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>[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>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_601_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_601_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 data is available to be received.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_601_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_601_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_601_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="poll.html"><i>poll</i>()</a> , <a href="read.html"><i>read</i>()</a> , <a href="recv.html"><i>recv</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="sendto.html"><i>sendto</i>()</a> , <a href="shutdown.html"><i>shutdown</i>()</a> ,
|
|
<a href="socket.html"><i>socket</i>()</a> , <a href="write.html"><i>write</i>()</a> , the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/sys/socket.h.html"><i><sys/socket.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_601_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® 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>
|
|
|