.\" Copyright (c) 1983 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\" @(#)recv.2 6.5 (Berkeley) %G%
recv, recvfrom, recvmsg \- receive a message from a socket
cc = recv(s, buf, len, flags)
cc = recvfrom(s, buf, len, flags, from, fromlen)
cc = recvmsg(s, msg, flags)
are used to receive messages from a socket.
call is normally used only on a
may be used to receive data on a socket whether
it is in a connected state or not.
is non-zero, the source address of the message is filled in.
is a value-result parameter, initialized to the size of
the buffer associated with
and modified on return to indicate the actual size of the
The length of the message is returned in
If a message is too long to fit in the supplied buffer,
excess bytes may be discarded depending on the type of socket
the message is received from (see
If no messages are available at the socket, the
receive call waits for a message to arrive, unless
the socket is nonblocking (see
of \-1 is returned with the external variable errno
call may be used to determine when more data arrives.
argument to a recv call is formed by
one or more of the values,
.ta \w'#define\ \ 'u +\w'MSG_DONTROUTE\ \ \ 'u +\w'0x\0\0\0\ \ 'u
#define MSG_OOB 0x1 /* process out-of-band data */
#define MSG_PEEK 0x2 /* peek at incoming message */
structure to minimize the number of directly supplied parameters.
This structure has the following form, as defined in
caddr_t msg_name; /* optional address */
int msg_namelen; /* size of address */
struct iovec *msg_iov; /* scatter/gather array */
int msg_iovlen; /* # elements in msg_iov */
caddr_t msg_accrights; /* access rights sent/received */
specify the destination address if the socket is unconnected;
may be given as a null pointer if no names are desired or required.
describe the scatter gather locations, as described in
A buffer to receive any access rights sent along with the message is specified
Access rights are currently limited to file descriptors,
which each occupy the size of an
If access rights are not being transferred, the
field should be set to NULL.
These calls return the number of bytes received, or \-1
The argument \fIs\fP is an invalid descriptor.
The argument \fIs\fP is not a socket.
The socket is marked non-blocking and the receive operation
The receive was interrupted by delivery of a signal before
any data was available for the receive.
The data was specified to be received into a non-existent
or protected part of the process address space.
fcntl(2), read(2), send(2), select(2), getsockopt(2), socket(2)