Newer
Older
* 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)
{