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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       recvfrom — receive a message from a socket
14

SYNOPSIS

16       #include <sys/socket.h>
17
18       ssize_t recvfrom(int socket, void *restrict buffer, size_t length,
19           int flags, struct sockaddr *restrict address,
20           socklen_t *restrict address_len);
21

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

154       None.
155

APPLICATION USAGE

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

RATIONALE

161       None.
162

FUTURE DIRECTIONS

164       None.
165

SEE ALSO

167       poll(),  pselect(),  read(),  recv(),  recvmsg(),  send(),   sendmsg(),
168       sendto(), shutdown(), socket(), write()
169
170       The Base Definitions volume of POSIX.1‐2008, <sys_socket.h>
171
173       Portions  of  this text are reprinted and reproduced in electronic form
174       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
175       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
176       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
177       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
178       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
179       event of any discrepancy between this version and the original IEEE and
180       The Open Group Standard, the original IEEE and The Open Group  Standard
181       is  the  referee document. The original Standard can be obtained online
182       at http://www.unix.org/online.html .
183
184       Any typographical or formatting errors that appear  in  this  page  are
185       most likely to have been introduced during the conversion of the source
186       files to man page format. To report such errors,  see  https://www.ker
187       nel.org/doc/man-pages/reporting_bugs.html .
188
189
190
191IEEE/The Open Group                  2013                         RECVFROM(3P)
Impressum