recvfrom Function

C

int recvfrom(
    SOCKET s, 
    char* buf, 
    int len, 
    int flags, 
    struct sockaddr* from, 
    int* fromlen
);

Description

The revfrom() function is used to receive incoming data that has been queued for a socket. This function can be used with both datagram and stream type sockets. If the available data is too large to fit in the supplied application buffer buf, excess bytes are discarded in case of SOCK_DGRAM type sockets. For SOCK_STREAM types, the data is buffered internally so the application can retrieve all data by multiple calls of recvfrom().

Preconditions

The socket() function should be called.

Parameters

ParametersDescription
sSocket descriptor returned from previous call to socket().
bufApplication data receive buffer.
lenBuffer length in bytes.
flagsMessage flags (currently this is not supported).
fromPointer to the sockaddr structure that will be filled in with the destination address.
fromlenSize of buffer pointed by from.

Returns

  • If the function is successful, the number of bytes copied to the application buffer buf is returned.

  • A return value of SOCKET_ERROR (-1) indicates an error and errno is set accordingly.

  • A value of zero indicates socket has been shutdown by the peer.

Remarks

None.