Embedded TCP/IP stack: fnet_socket_recvfrom

FNET

Embedded TCP/IP stack  4.1.0
fnet_ssize_t fnet_socket_recvfrom ( fnet_socket_t  s,
void *  buf,
fnet_size_t  len,
fnet_flag_t  flags,
struct fnet_sockaddr from,
fnet_size_t fromlen 
)

Receives the data and captures the address, from which the data was sent.

Parameters
sDescriptor, identifying a bound socket.
bufBuffer for the incoming data.
lenLength of the buf.
flagsOptional flag specifying the way in which the call is made. It can be constructed by using the bitwise OR operator with any of the values defined by the fnet_msg_flags_t.
fromOptional pointer to a buffer that will hold the source address upon return.
fromlenOptional pointer to the size of the from buffer.
Returns
This function returns:
  • The number of bytes received, if no error occurs. The return value is set to zero, if the socket is nonblocking and there is no input data.
  • FNET_ERR if an error occurs.
    The specific error code can be retrieved using the fnet_error_get().
See also
fnet_socket_bind(), fnet_socket_recv()

For connection-oriented sockets (SOCK_STREAM), calling the fnet_socket_recvfrom() will return as much information as is currently available up to the size of the buffer supplied. The fnet_socket_recvfrom() call is rarely used for stream sockets, because the routine provides the peer-socket information, and stream sockets are tied to a specific peer.

For connectionless sockets (SOCK_DGRAM), the data is extracted from the first enqueued datagram. If the datagram is larger than the buffer supplied, the buffer is filled with the first part of the datagram, and the fnet_socket_recvfrom() generates the error FNET_ERR_MSGSIZE and the excess data is lost.

If the from parameter is non-zero, the network address of the peer that sent the data is copied to the corresponding fnet_sockaddr structure. The value pointed to by fromlen is initialized to the size of this structure and is modified on return, to indicate the actual size of the address stored in the fnet_sockaddr structure.

The flags parameter can be used to influence the behavior of the function invocation beyond the options specified for the associated socket.


© 2005-2018 by Andrey Butok. http://fnet.sourceforge.net