Jump to main content

##

# 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

Parameters | Description
--- | ---
s | Socket descriptor returned from previous call to socket().
buf | Application data receive buffer.
len | Buffer length in bytes.
flags | Message flags (currently this is not supported).
from | Pointer to the sockaddr structure that will be filled in with the destination address.
fromlen | Size 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.