1RECVFROM(P)                POSIX Programmer's Manual               RECVFROM(P)
2
3
4

NAME

6       recvfrom - receive a message from a socket
7

SYNOPSIS

9       #include <sys/socket.h>
10
11       ssize_t recvfrom(int socket, void *restrict buffer, size_t length,
12              int flags, struct sockaddr *restrict address,
13              socklen_t *restrict address_len);
14
15

DESCRIPTION

17       The  recvfrom() function shall receive a message from a connection-mode
18       or connectionless-mode socket. It is normally used with connectionless-
19       mode  sockets because it permits the application to retrieve the source
20       address of received data.
21
22       The recvfrom() function takes the following arguments:
23
24       socket Specifies the socket file descriptor.
25
26       buffer Points to the buffer where the message should be stored.
27
28       length Specifies the length in bytes of the buffer pointed  to  by  the
29              buffer argument.
30
31       flags  Specifies the type of message reception. Values of this argument
32              are formed by logically OR'ing zero or  more  of  the  following
33              values:
34
35       MSG_PEEK
36              Peeks  at an incoming message. The data is treated as unread and
37              the next recvfrom() or similar function shall still return  this
38              data.
39
40       MSG_OOB
41              Requests  out-of-band  data.  The  significance and semantics of
42              out-of-band data are protocol-specific.
43
44       MSG_WAITALL
45              On SOCK_STREAM sockets this requests  that  the  function  block
46              until  the full amount of data can be returned. The function may
47              return the smaller amount of data if the socket  is  a  message-
48              based socket, if a signal is caught, if the connection is termi‐
49              nated, if MSG_PEEK was specified, or if an error is pending  for
50              the socket.
51
52
53       address
54              A  null  pointer, or points to a sockaddr structure in which the
55              sending address is to be stored. The length and  format  of  the
56              address depend on the address family of the socket.
57
58       address_len
59              Specifies the length of the sockaddr structure pointed to by the
60              address argument.
61
62
63       The recvfrom() function shall return the length of the message  written
64       to  the  buffer  pointed  to  by the buffer argument. For message-based
65       sockets, such as     SOCK_RAW,   SOCK_DGRAM,  and  SOCK_SEQPACKET,  the
66       entire  message  shall  be read in a single operation.  If a message is
67       too long to fit in the supplied buffer, and MSG_PEEK is not set in  the
68       flags  argument,  the excess bytes shall be discarded. For stream-based
69       sockets, such as SOCK_STREAM, message boundaries shall be ignored.   In
70       this  case,  data  shall  be returned to the user as soon as it becomes
71       available, and no data shall be discarded.
72
73       If the MSG_WAITALL flag is not set, data shall be returned only  up  to
74       the end of the first message.
75
76       Not  all  protocols  provide  the  source  address for messages. If the
77       address argument is not a null pointer and the  protocol  provides  the
78       source  address of messages, the source address of the received message
79       shall be stored in the sockaddr structure pointed  to  by  the  address
80       argument,  and the length of this address shall be stored in the object
81       pointed to by the address_len argument.
82
83       If the actual length of the address is greater than the length  of  the
84       supplied sockaddr structure, the stored address shall be truncated.
85
86       If the address argument is not a null pointer and the protocol does not
87       provide the source address of messages, the value stored in the  object
88       pointed to by address is unspecified.
89
90       If no messages are available at the socket and O_NONBLOCK is not set on
91       the socket's file descriptor, recvfrom() shall block  until  a  message
92       arrives.  If  no messages are available at the socket and O_NONBLOCK is
93       set on the socket's file descriptor,  recvfrom()  shall  fail  and  set
94       errno to [EAGAIN] or [EWOULDBLOCK].
95

RETURN VALUE

97       Upon  successful  completion, recvfrom() shall return the length of the
98       message in bytes. If no messages are available to be received  and  the
99       peer has performed an orderly shutdown, recvfrom() shall return 0. Oth‐
100       erwise, the function shall return -1 and  set  errno  to  indicate  the
101       error.
102

ERRORS

104       The recvfrom() function shall fail if:
105
106       EAGAIN or EWOULDBLOCK
107
108              The socket's file descriptor is marked O_NONBLOCK and no data is
109              waiting to be received; or MSG_OOB is  set  and  no  out-of-band
110              data  is  available  and  either the socket's file descriptor is
111              marked O_NONBLOCK or the socket does  not  support  blocking  to
112              await out-of-band data.
113
114       EBADF  The socket argument is not a valid file descriptor.
115
116       ECONNRESET
117              A connection was forcibly closed by a peer.
118
119       EINTR  A signal interrupted recvfrom() before any data was available.
120
121       EINVAL The MSG_OOB flag is set and no out-of-band data is available.
122
123       ENOTCONN
124              A  receive  is attempted on a connection-mode socket that is not
125              connected.
126
127       ENOTSOCK
128              The socket argument does not refer to a socket.
129
130       EOPNOTSUPP
131              The specified flags are not supported for this socket type.
132
133       ETIMEDOUT
134              The connection timed out during connection establishment, or due
135              to a transmission timeout on active connection.
136
137
138       The recvfrom() function may fail if:
139
140       EIO    An  I/O error occurred while reading from or writing to the file
141              system.
142
143       ENOBUFS
144              Insufficient resources were available in the system  to  perform
145              the operation.
146
147       ENOMEM Insufficient memory was available to fulfill the request.
148
149
150       The following sections are informative.
151

EXAMPLES

153       None.
154

APPLICATION USAGE

156       The select() and poll() functions can be used to determine when data is
157       available to be received.
158

RATIONALE

160       None.
161

FUTURE DIRECTIONS

163       None.
164

SEE ALSO

166       poll() , read() , recv() , recvmsg() , select() , send() , sendmsg()  ,
167       sendto()  , shutdown() , socket() , write() , the Base Definitions vol‐
168       ume of IEEE Std 1003.1-2001, <sys/socket.h>
169
171       Portions of this text are reprinted and reproduced in  electronic  form
172       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
173       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
174       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
175       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
176       event of any discrepancy between this version and the original IEEE and
177       The Open Group Standard, the original IEEE and The Open Group  Standard
178       is  the  referee document. The original Standard can be obtained online
179       at http://www.opengroup.org/unix/online.html .
180
181
182
183IEEE/The Open Group                  2003                          RECVFROM(P)
Impressum