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
19

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

171       None.
172

APPLICATION USAGE

174       The select() and poll() functions can be used to determine when data is
175       available to be received.
176

RATIONALE

178       None.
179

FUTURE DIRECTIONS

181       None.
182

SEE ALSO

184       poll(), recv(),  recvfrom(),  select(),  send(),  sendmsg(),  sendto(),
185       shutdown(),     socket(),    the    Base    Definitions    volume    of
186       IEEE Std 1003.1-2001, <sys/socket.h>
187
189       Portions of this text are reprinted and reproduced in  electronic  form
190       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
191       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
192       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
193       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
194       event of any discrepancy between this version and the original IEEE and
195       The Open Group Standard, the original IEEE and The Open Group  Standard
196       is  the  referee document. The original Standard can be obtained online
197       at http://www.opengroup.org/unix/online.html .
198
199
200
201IEEE/The Open Group                  2003                          RECVMSG(3P)
Impressum