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

NAME

6       recvmsg - receive a message from a socket
7

SYNOPSIS

9       #include <sys/socket.h>
10
11       ssize_t recvmsg(int socket, struct msghdr *message, int flags);
12
13

DESCRIPTION

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

RETURN VALUE

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

ERRORS

110       The recvmsg() function shall fail if:
111
112       EAGAIN or EWOULDBLOCK
113
114              The socket's file descriptor is marked O_NONBLOCK and no data is
115              waiting to be received; or MSG_OOB is  set  and  no  out-of-band
116              data  is  available  and  either the socket's file descriptor is
117              marked O_NONBLOCK or the socket does  not  support  blocking  to
118              await out-of-band data.
119
120       EBADF  The socket argument is not a valid open file descriptor.
121
122       ECONNRESET
123              A connection was forcibly closed by a peer.
124
125       EINTR  This  function  was  interrupted by a signal before any data was
126              available.
127
128       EINVAL The sum of the  iov_len  values  overflows  a  ssize_t,  or  the
129              MSG_OOB flag is set and no out-of-band data is available.
130
131       EMSGSIZE
132              The msg_iovlen member of the msghdr structure pointed to by mes‐
133              sage is less than or equal to 0, or is greater than {IOV_MAX}.
134
135       ENOTCONN
136              A receive is attempted on a connection-mode socket that  is  not
137              connected.
138
139       ENOTSOCK
140              The socket argument does not refer to a socket.
141
142       EOPNOTSUPP
143              The specified flags are not supported for this socket type.
144
145       ETIMEDOUT
146              The connection timed out during connection establishment, or due
147              to a transmission timeout on active connection.
148
149
150       The recvmsg() function may fail if:
151
152       EIO    An I/O error occurred while reading from or writing to the  file
153              system.
154
155       ENOBUFS
156              Insufficient  resources  were available in the system to perform
157              the operation.
158
159       ENOMEM Insufficient memory was available to fulfill the request.
160
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() , recv() , recvfrom() , select() , send() , sendmsg() , sendto()
179       ,  shutdown()  ,  socket()   ,   the   Base   Definitions   volume   of
180       IEEE Std 1003.1-2001, <sys/socket.h>
181
183       Portions  of  this text are reprinted and reproduced in electronic form
184       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
185       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
186       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
187       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
188       event of any discrepancy between this version and the original IEEE and
189       The  Open Group Standard, the original IEEE and The Open Group Standard
190       is the referee document. The original Standard can be  obtained  online
191       at http://www.opengroup.org/unix/online.html .
192
193
194
195IEEE/The Open Group                  2003                           RECVMSG(P)
Impressum