1RECVMSG(3P)                POSIX Programmer's Manual               RECVMSG(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

NAME

12       recvmsg — receive a message from a socket
13

SYNOPSIS

15       #include <sys/socket.h>
16
17       ssize_t recvmsg(int socket, struct msghdr *message, int flags);
18

DESCRIPTION

20       The recvmsg() function shall receive a message from  a  connection-mode
21       or connectionless-mode socket. It is normally used with connectionless-
22       mode sockets because it permits the application to retrieve the  source
23       address of received data.
24
25       The recvmsg() function takes the following arguments:
26
27       socket      Specifies the socket file descriptor.
28
29       message     Points to a msghdr structure, containing both the buffer to
30                   store the source address and the buffers for  the  incoming
31                   message. The length and format of the address depend on the
32                   address family of  the  socket.  The  msg_flags  member  is
33                   ignored on input, but may contain meaningful values on out‐
34                   put.
35
36       flags       Specifies the type of message  reception.  Values  of  this
37                   argument are formed by logically OR'ing zero or more of the
38                   following values:
39
40                   MSG_OOB     Requests out-of-band data. The significance and
41                               semantics of out-of-band data are protocol-spe‐
42                               cific.
43
44                   MSG_PEEK    Peeks at the incoming message.
45
46                   MSG_WAITALL On SOCK_STREAM sockets this requests  that  the
47                               function  block  until  the full amount of data
48                               can be returned. The function  may  return  the
49                               smaller  amount of data if the socket is a mes‐
50                               sage-based socket, if a signal  is  caught,  if
51                               the  connection  is terminated, if MSG_PEEK was
52                               specified, or if an error is  pending  for  the
53                               socket.
54
55       The  recvmsg() function shall receive messages from unconnected or con‐
56       nected sockets and shall return the length of the message.
57
58       The recvmsg() function shall return the total length  of  the  message.
59       For  message-based  sockets, such as SOCK_DGRAM and SOCK_SEQPACKET, the
60       entire message shall be read in a single operation. If a message is too
61       long  to  fit  in  the supplied buffers, and MSG_PEEK is not set in the
62       flags argument, the excess bytes  shall  be  discarded,  and  MSG_TRUNC
63       shall  be  set  in  the  msg_flags  member of the msghdr structure. For
64       stream-based sockets, such as SOCK_STREAM, message boundaries shall  be
65       ignored. In this case, data shall be returned to the user as soon as it
66       becomes available, and no data shall be discarded.
67
68       If the MSG_WAITALL flag is not set, data shall be returned only  up  to
69       the end of the first message.
70
71       If no messages are available at the socket and O_NONBLOCK is not set on
72       the socket's file descriptor, recvmsg() shall  block  until  a  message
73       arrives.  If  no messages are available at the socket and O_NONBLOCK is
74       set on the socket's file descriptor, the recvmsg() function shall  fail
75       and set errno to [EAGAIN] or [EWOULDBLOCK].
76
77       In  the  msghdr structure, the msg_name member may be a null pointer if
78       the source address is not required.  Otherwise, if the socket is uncon‐
79       nected, the msg_name member points to a sockaddr structure in which the
80       source address is to be stored, and the  msg_namelen  member  on  input
81       specifies  the  length of the supplied sockaddr structure and on output
82       specifies the length of the stored address.  If the  actual  length  of
83       the  address is greater than the length of the supplied sockaddr struc‐
84       ture, the stored address shall be truncated.  If  the  socket  is  con‐
85       nected,  the  msg_name  and  msg_namelen  members shall be ignored. The
86       msg_iov and msg_iovlen fields are used to specify  where  the  received
87       data  shall  be stored.  The msg_iov member points to an array of iovec
88       structures; the msg_iovlen member shall be set to the dimension of this
89       array.  In each iovec structure, the iov_base field specifies a storage
90       area and the iov_len field gives its size in bytes. Each  storage  area
91       indicated  by msg_iov is filled with received data in turn until all of
92       the received data is stored or all of the areas have been filled.
93
94       Upon successful completion, the msg_flags member of the message  header
95       shall  be  the  bitwise-inclusive OR of all of the following flags that
96       indicate conditions detected for the received message:
97
98       MSG_EOR     End-of-record was received (if supported by the protocol).
99
100       MSG_OOB     Out-of-band data was received.
101
102       MSG_TRUNC   Normal data was truncated.
103
104       MSG_CTRUNC  Control data was truncated.
105

RETURN VALUE

107       Upon successful completion, recvmsg() shall return the  length  of  the
108       message  in  bytes. If no messages are available to be received and the
109       peer has performed an orderly shutdown, recvmsg() shall return 0.  Oth‐
110       erwise, -1 shall be returned and errno set to indicate the error.
111

ERRORS

113       The recvmsg() function shall fail if:
114
115       EAGAIN or EWOULDBLOCK
116              The socket's file descriptor is marked O_NONBLOCK and no data is
117              waiting to be received; or MSG_OOB is  set  and  no  out-of-band
118              data  is  available  and  either the socket's file descriptor is
119              marked O_NONBLOCK or the socket does  not  support  blocking  to
120              await out-of-band data.
121
122       EBADF  The socket argument is not a valid open file descriptor.
123
124       ECONNRESET
125              A connection was forcibly closed by a peer.
126
127       EINTR  This  function  was  interrupted by a signal before any data was
128              available.
129
130       EINVAL The sum of the  iov_len  values  overflows  a  ssize_t,  or  the
131              MSG_OOB flag is set and no out-of-band data is available.
132
133       EMSGSIZE
134              The msg_iovlen member of the msghdr structure pointed to by mes‐
135              sage is less than or equal to 0, or is greater than {IOV_MAX}.
136
137       ENOTCONN
138              A receive is attempted on a connection-mode socket that  is  not
139              connected.
140
141       ENOTSOCK
142              The socket argument does not refer to a socket.
143
144       EOPNOTSUPP
145              The specified flags are not supported for this socket type.
146
147       ETIMEDOUT
148              The connection timed out during connection establishment, or due
149              to a transmission timeout on active connection.
150
151       The recvmsg() function may fail if:
152
153       EIO    An I/O error occurred while reading from or writing to the  file
154              system.
155
156       ENOBUFS
157              Insufficient  resources  were available in the system to perform
158              the operation.
159
160       ENOMEM Insufficient memory was available to fulfill the request.
161
162       The following sections are informative.
163

EXAMPLES

165       None.
166

APPLICATION USAGE

168       The select() and poll() functions can be used to determine when data is
169       available to be received.
170

RATIONALE

172       None.
173

FUTURE DIRECTIONS

175       None.
176

SEE ALSO

178       poll(),  pselect(),  recv(),  recvfrom(),  send(), sendmsg(), sendto(),
179       shutdown(), socket()
180
181       The Base Definitions volume of POSIX.1‐2017, <sys_socket.h>
182
184       Portions of this text are reprinted and reproduced in  electronic  form
185       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
186       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
187       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
188       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
189       event of any discrepancy between this version and the original IEEE and
190       The Open Group Standard, the original IEEE and The Open Group  Standard
191       is  the  referee document. The original Standard can be obtained online
192       at http://www.opengroup.org/unix/online.html .
193
194       Any typographical or formatting errors that appear  in  this  page  are
195       most likely to have been introduced during the conversion of the source
196       files to man page format. To report such errors,  see  https://www.ker
197       nel.org/doc/man-pages/reporting_bugs.html .
198
199
200
201IEEE/The Open Group                  2017                          RECVMSG(3P)
Impressum