Esempio n. 1
0
/************************************************************************
* NAME: fnet_udp_rcv
*
* DESCRIPTION :UDP receive function.
*************************************************************************/
static fnet_int32_t fnet_udp_rcv(fnet_socket_if_t *sk, fnet_uint8_t *buf, fnet_size_t len, fnet_flag_t flags, struct sockaddr *addr)
{
    fnet_error_t    error = FNET_ERR_OK;
    fnet_int32_t    length;
    struct sockaddr foreign_addr;
    
    fnet_memset_zero ((void *)&foreign_addr, sizeof(foreign_addr));
    
#if FNET_CFG_TCP_URGENT
    if(flags & MSG_OOB)
    {
        error = FNET_ERR_OPNOTSUPP; /* Operation not supported.*/
        goto ERROR;
    }
#endif /* FNET_CFG_TCP_URGENT */
    
    if((length = fnet_socket_buffer_read_address(&(sk->receive_buffer), buf,
            len, &foreign_addr, ((flags & MSG_PEEK)== 0u)?FNET_TRUE:FNET_FALSE)) == FNET_ERR)
    {
        /* The message was too large to fit into the specified buffer and was truncated.*/
        error = FNET_ERR_MSGSIZE;
        goto ERROR;
    }

    if(sk->options.local_error == FNET_ERR_OK) 
    {
        if(addr)
        {
            fnet_socket_addr_copy(&foreign_addr, addr);
        }
        
        return (length);
    }
    else /* We get UDP or ICMP error.*/
    {
        error = sk->options.local_error;
    }

ERROR:
    fnet_socket_set_error(sk, error);
    return (FNET_ERR);
}
Esempio n. 2
0
/************************************************************************
* NAME: fnet_raw_rcv
*
* DESCRIPTION :RAW receive function.
*************************************************************************/
static int fnet_raw_rcv(fnet_socket_t *sk, char *buf, int len, int flags, struct sockaddr *addr)
{
    int error = FNET_OK;
    int length;
    struct sockaddr foreign_addr;

#if FNET_CFG_TCP_URGENT
    if(flags & MSG_OOB)
    {
        error = FNET_ERR_OPNOTSUPP; /* Operation not supported.*/
        goto ERROR;
    }
#endif /* FNET_CFG_TCP_URGENT */
    
    if((length = fnet_socket_buffer_read_address(&(sk->receive_buffer), buf,
            len, &foreign_addr, ((flags &MSG_PEEK)== 0))) == FNET_ERR)
    {
        /* The message was too large to fit into the specified buffer and was truncated.*/
        error = FNET_ERR_MSGSIZE;
        goto ERROR;
    }


    if((error == FNET_OK) && (sk->options.local_error == FNET_OK)) /* We get RAW or ICMP error.*/
    {
        if(addr)
        {
            fnet_socket_addr_copy(&foreign_addr, addr);
        }
        
        return (length);
    }

ERROR:
    fnet_socket_set_error(sk, error);
    return (SOCKET_ERROR);
}