Go to the previous, next section.

recv, recvfrom and recvmsg

SYNOPSIS

int recv(int s, void *buf, int len, unsigned int flags);

int recvfrom(int s, void *buf, int len, unsigned int flags struct sockaddr *from, int *fromlen);

int recvmsg(int s, struct msghdr *msg, unsigned int flags);

PARAMETERS

s: [in] the socket to read from.

buf: [out] points to a buffer where to put the information read.

len: [in] the capacity of the buffer.

flags: [in] several options (see description).

from: [out] points to an area where to store the peer address. If NULL, the peer address is not stored.

fromlen: [in out] on entry, points to a number indicating the capacity of from. On return, points to an area where to store the actual length of from.

msg: [out] points to an area where to store the incomming message header.

DESCRIPTION

recv is usually used to receive messages form a connection-oriented socket. It is equivalent to recvfrom with from set to NULL.

recvfrom and recvmsg are used for connection-less or connection-oriented sockets.

These calls block if there is no message to receive unless the socket is non-blocking.

The flags parameter may have the following values:

MSG_OOB
the call will receive out-of-band data instead of in band data.

MSG_PEEK
return the data from the input queue without dequeuing it.

MSG_WAITALL
wait until all data requested is received (buf is full).

recvmsg is not yet implemented in Linux.

RETURN VALUE

On success, the number of bytes received. On error, the call returns -1 and sets errno to one of the following values:

Go to the previous, next section.