~ubuntu-branches/ubuntu/precise/manpages-posix/precise

1 by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages.
1
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved 
2 by Francesco Paolo Lovergine
* Alligned to linux main manpages edition.
2
.TH "RECVFROM" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
1 by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages.
3
.\" recvfrom 
4
.SH NAME
5
recvfrom \- receive a message from a socket
6
.SH SYNOPSIS
7
.LP
8
\fB#include <sys/socket.h>
9
.br
10
.sp
11
ssize_t recvfrom(int\fP \fIsocket\fP\fB, void *restrict\fP \fIbuffer\fP\fB,
12
size_t\fP \fIlength\fP\fB,
13
.br
14
\ \ \ \ \ \  int\fP \fIflags\fP\fB, struct sockaddr *restrict\fP \fIaddress\fP\fB,
15
.br
16
\ \ \ \ \ \  socklen_t *restrict\fP \fIaddress_len\fP\fB);
17
.br
18
\fP
19
.SH DESCRIPTION
20
.LP
21
The \fIrecvfrom\fP() function shall receive a message from a connection-mode
22
or connectionless-mode socket. It is normally used
23
with connectionless-mode sockets because it permits the application
24
to retrieve the source address of received data.
25
.LP
26
The \fIrecvfrom\fP() function takes the following arguments:
27
.TP 7
28
\fIsocket\fP
29
Specifies the socket file descriptor.
30
.TP 7
31
\fIbuffer\fP
32
Points to the buffer where the message should be stored.
33
.TP 7
34
\fIlength\fP
35
Specifies the length in bytes of the buffer pointed to by the \fIbuffer\fP
36
argument.
37
.TP 7
38
\fIflags\fP
39
Specifies the type of message reception. Values of this argument are
40
formed by logically OR'ing zero or more of the following
41
values: 
42
.TP 7
43
MSG_PEEK
44
.RS
45
Peeks at an incoming message. The data is treated as unread and the
46
next \fIrecvfrom\fP() or similar function shall still
47
return this data.
48
.RE
49
.TP 7
50
MSG_OOB
51
.RS
52
Requests out-of-band data. The significance and semantics of out-of-band
53
data are protocol-specific.
54
.RE
55
.TP 7
56
MSG_WAITALL
57
.RS
58
On SOCK_STREAM sockets this requests that the function block until
59
the full amount of data can be returned. The function may
60
return the smaller amount of data if the socket is a message-based
61
socket, if a signal is caught, if the connection is terminated,
62
if MSG_PEEK was specified, or if an error is pending for the socket.
63
.RE
64
.sp
65
.TP 7
66
\fIaddress\fP
67
A null pointer, or points to a \fBsockaddr\fP structure in which the
68
sending address is to be stored. The length and format of
69
the address depend on the address family of the socket.
70
.TP 7
71
\fIaddress_len\fP
72
Specifies the length of the \fBsockaddr\fP structure pointed to by
73
the \fIaddress\fP argument.
74
.sp
75
.LP
76
The \fIrecvfrom\fP() function shall return the length of the message
77
written to the buffer pointed to by the \fIbuffer\fP
78
argument. For message-based sockets, such as   \ SOCK_RAW,  SOCK_DGRAM,
79
and SOCK_SEQPACKET, the entire message shall be read in a single operation.
80
If a message is too long to fit
81
in the supplied buffer, and MSG_PEEK is not set in the \fIflags\fP
82
argument, the excess bytes shall be discarded. For stream-based
83
sockets, such as SOCK_STREAM, message boundaries shall be ignored.
84
In this case, data shall be returned to the user as soon as it
85
becomes available, and no data shall be discarded.
86
.LP
87
If the MSG_WAITALL flag is not set, data shall be returned only up
88
to the end of the first message.
89
.LP
90
Not all protocols provide the source address for messages. If the
91
\fIaddress\fP argument is not a null pointer and the protocol
92
provides the source address of messages, the source address of the
93
received message shall be stored in the \fBsockaddr\fP
94
structure pointed to by the \fIaddress\fP argument, and the length
95
of this address shall be stored in the object pointed to by the
96
\fIaddress_len\fP argument.
97
.LP
98
If the actual length of the address is greater than the length of
99
the supplied \fBsockaddr\fP structure, the stored address
100
shall be truncated.
101
.LP
102
If the \fIaddress\fP argument is not a null pointer and the protocol
103
does not provide the source address of messages, the value
104
stored in the object pointed to by \fIaddress\fP is unspecified.
105
.LP
106
If no messages are available at the socket and O_NONBLOCK is not set
107
on the socket's file descriptor, \fIrecvfrom\fP() shall
108
block until a message arrives. If no messages are available at the
109
socket and O_NONBLOCK is set on the socket's file descriptor,
110
\fIrecvfrom\fP() shall fail and set \fIerrno\fP to [EAGAIN] or [EWOULDBLOCK].
111
.SH RETURN VALUE
112
.LP
113
Upon successful completion, \fIrecvfrom\fP() shall return the length
114
of the message in bytes. If no messages are available to
115
be received and the peer has performed an orderly shutdown, \fIrecvfrom\fP()
116
shall return 0. Otherwise, the function shall return
117
-1 and set \fIerrno\fP to indicate the error.
118
.SH ERRORS
119
.LP
120
The \fIrecvfrom\fP() function shall fail if:
121
.TP 7
2 by Francesco Paolo Lovergine
* Alligned to linux main manpages edition.
122
.B EAGAIN \fRor\fP EWOULDBLOCK
1 by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages.
123
.sp
124
The socket's file descriptor is marked O_NONBLOCK and no data is waiting
125
to be received; or MSG_OOB is set and no out-of-band data
126
is available and either the socket's file descriptor is marked O_NONBLOCK
127
or the socket does not support blocking to await
128
out-of-band data.
129
.TP 7
130
.B EBADF
131
The \fIsocket\fP argument is not a valid file descriptor.
132
.TP 7
133
.B ECONNRESET
134
A connection was forcibly closed by a peer.
135
.TP 7
136
.B EINTR
137
A signal interrupted \fIrecvfrom\fP() before any data was available.
138
.TP 7
139
.B EINVAL
140
The MSG_OOB flag is set and no out-of-band data is available.
141
.TP 7
142
.B ENOTCONN
143
A receive is attempted on a connection-mode socket that is not connected.
144
.TP 7
145
.B ENOTSOCK
146
The \fIsocket\fP argument does not refer to a socket.
147
.TP 7
148
.B EOPNOTSUPP
149
The specified flags are not supported for this socket type.
150
.TP 7
151
.B ETIMEDOUT
152
The connection timed out during connection establishment, or due to
153
a transmission timeout on active connection.
154
.sp
155
.LP
156
The \fIrecvfrom\fP() function may fail if:
157
.TP 7
158
.B EIO
159
An I/O error occurred while reading from or writing to the file system.
160
.TP 7
161
.B ENOBUFS
162
Insufficient resources were available in the system to perform the
163
operation.
164
.TP 7
165
.B ENOMEM
166
Insufficient memory was available to fulfill the request.
167
.sp
168
.LP
169
\fIThe following sections are informative.\fP
170
.SH EXAMPLES
171
.LP
172
None.
173
.SH APPLICATION USAGE
174
.LP
175
The \fIselect\fP() and \fIpoll\fP() functions can
176
be used to determine when data is available to be received.
177
.SH RATIONALE
178
.LP
179
None.
180
.SH FUTURE DIRECTIONS
181
.LP
182
None.
183
.SH SEE ALSO
184
.LP
185
\fIpoll\fP() , \fIread\fP() , \fIrecv\fP() , \fIrecvmsg\fP() , \fIselect\fP()
186
, \fIsend\fP() , \fIsendmsg\fP() , \fIsendto\fP() , \fIshutdown\fP()
187
,
188
\fIsocket\fP() , \fIwrite\fP() , the Base Definitions volume of
189
IEEE\ Std\ 1003.1-2001, \fI<sys/socket.h>\fP
190
.SH COPYRIGHT
191
Portions of this text are reprinted and reproduced in electronic form
192
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
193
-- Portable Operating System Interface (POSIX), The Open Group Base
194
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
195
Electrical and Electronics Engineers, Inc and The Open Group. In the
196
event of any discrepancy between this version and the original IEEE and
197
The Open Group Standard, the original IEEE and The Open Group Standard
198
is the referee document. The original Standard can be obtained online at
199
http://www.opengroup.org/unix/online.html .