Newer
Older
*
* Parameters:
* sockfd Socket descriptor of socket
* buf Buffer to receive data
* len Length of buffer
* flags Receive flags
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
* fromlen The length of the address structure
*
* Returned Value:
* On success, returns the number of characters sent. On error,
* -1 is returned, and errno is set appropriately:
*
* EAGAIN
* The socket is marked non-blocking and the receive operation would block,
* or a receive timeout had been set and the timeout expired before data
* was received.
* EBADF
* The argument sockfd is an invalid descriptor.
* ECONNREFUSED
* A remote host refused to allow the network connection (typically because
* it is not running the requested service).
* EFAULT
* The receive buffer pointer(s) point outside the process's address space.
* EINTR
* The receive was interrupted by delivery of a signal before any data were
* available.
* EINVAL
* Invalid argument passed.
* ENOMEM
* ENOTCONN
* The socket is associated with a connection-oriented protocol and has
* not been connected.
* ENOTSOCK
* The argument sockfd does not refer to a socket.
*
* Assumptions:
*
****************************************************************************/
ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags,
FAR struct sockaddr *from, FAR socklen_t *fromlen)
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP)
FAR struct sockaddr_in6 *infrom = (struct sockaddr_in6 *)from;
FAR struct sockaddr_in *infrom = (struct sockaddr_in *)from;
/* Verify that non-NULL pointers were passed */
{
err = EINVAL;
goto errout;
}
/* Get the underlying socket structure */
/* Verify that the sockfd corresponds to valid, allocated socket */
psock = sockfd_socket(sockfd);
if (!psock || psock->s_crefs <= 0)
{
err = EBADF;
goto errout;
}
/* If a 'from' address has been provided, verify that it is large
* enough to hold this address family.
*/
/* Set the socket state to receiving */
psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_RECV);
/* Perform the TCP/IP or UDP recv() operation */
#if defined(CONFIG_NET_UDP) && defined(CONFIG_NET_TCP)
if (psock->s_type == SOCK_STREAM)
ret = tcp_recvfrom(psock, buf, len, infrom);
ret = udp_recvfrom(psock, buf, len, infrom);
#elif defined(CONFIG_NET_TCP)
ret = tcp_recvfrom(psock, buf, len, infrom);
#elif defined(CONFIG_NET_UDP)
ret = udp_recvfrom(psock, buf, len, infrom);
#else
ret = -ENOSYS;
/* Set the socket state to idle */
psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE);
/* Handle returned errors */
if (ret < 0)
{