Parameters

socket

buffer

buflen

flags

from

Port number and IP address of the node that sent the data; port number and IP address are in network byte order. This parameter has type struct sockaddr * for historical reasons. Use type struct sockaddr_in * instead.

This routine will receive up to buflen bytes from the connection and copy the data to *buffer. It will never return more than buflen bytes but will return as soon as bytes are available in the buffer.

If parameter from is non-zero, the IP address and port number of the endpoint where the data came from is returned to the caller in *from. The size of the from structure is passed to recvfrom in fromlen and recvfrom returns the number of valid bytes stored in from in fromlen.

For UDP, connect may be called before recvfrom but it is not necessary. For TCP, the socket must be connected before calling recvfrom.

If no data is available and the socket is in blocking mode, recvfrom blocks on the read signal until any data is available. If no data is available and the socket is in non-blocking mode, recvfrom returns immediately with an error condition. select may be called prior to calling recvfrom to determine when data is available.

For TCP, if the socket option SO_TCP_NO_COPY is set, the incoming packets are stored in the input window without copying the data. Therefore, copying data to the user buffer is the only copying which is done.

For TCP, this function returns 0 if a FIN packet has been received (i.e. the remote host did a closesocket) and the input window is empty.

Raw packets are queued on every socket whose protocol matches the protocol field in the packet. The socket's protocol is a parameter to socket. The data written to buffer includes the IP header.

In blocking mode, this function blocks infinitely. Use select for a timeout capability.

Warning: For UDP, each call to recv dequeues one packet from the socket's input queue. If there is more data in the packet than the caller requested, the residual data will be lost.