recv(SSC) 6 January 1993 recv(SSC) Name recv, recvfrom - receive a message from a socket Syntax #include <sys/types.h> #include <sys/socket.h> int recv(s, buf, len, flags) int s; char *buf; int len, flags; int recvfrom(s, buf, len, flags, from, fromlen) int s; char *buf; int len, flags; struct sockaddr *from; int *fromlen;> Description recv and recvfrom are used to receive messages from a socket. The recv call may be used only on a connected socket (see connect(SSC) for more information), while recvfrom may be used to receive data on a socket whether it is in a connected state or not. If from is non-zero, the source address of the message is filled in. fromlen is a value-result parameter, initialized to the size of the buffer associated with from, and modified on return to indicate the actual size of the address stored there. The length of the message is returned in cc. 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 socket(SSC). If no messages are available at the socket, the receive call waits for a message to arrive. The flags argument to a send call is formed by or'ing one or more of the values: #define MSG_OOB 0x1 /* process out-of-band data */ #define MSG_PEEK 0x2 /* peek at incoming message */ Return value These calls return the number of bytes received, or -1 if an error occurred. Errors The calls fail if: [EBADF] The argument s is an invalid descriptor. [ENOTSOCK] The argument s is not a socket. [EINTR] The receive was interrupted by delivery of a signal before any data was available for the receive. [EFAULT] The data was specified to be received into a non- existent or protected part of the process address space. See also Intro(SSC), connect(SSC), read(S), send(SSC), socket(SSC) and intro(ADMP).