Exemple #1
0
/************************************************************************
* DESCRIPTION: RAW send function.
*************************************************************************/
static fnet_int32_t fnet_raw_snd( fnet_socket_if_t *sk, fnet_uint8_t *buf, fnet_size_t len, fnet_flag_t flags, const struct sockaddr *addr)
{
    fnet_netbuf_t           *nb;
    fnet_error_t            error = FNET_ERR_OK;
    const struct sockaddr   *foreign_addr;
    fnet_bool_t             flags_save = FNET_FALSE;

    fnet_isr_lock();

    if(len > sk->send_buffer.count_max)
    {
        error = FNET_ERR_MSGSIZE;   /* Message too long. */
        goto ERROR;
    }

    if(addr)
    {
        foreign_addr = addr;
    }
    else
    {
        foreign_addr = &sk->foreign_addr;
    }

    if((nb = fnet_netbuf_from_buf(buf, len, FNET_FALSE)) == 0)
    {
        error = FNET_ERR_NOMEM;     /* Cannot allocate memory.*/
        goto ERROR;
    }

    if((flags & MSG_DONTROUTE) != 0u) /* Save */
    {
        flags_save = sk->options.so_dontroute;
        sk->options.so_dontroute = FNET_TRUE;
    }

    error = fnet_raw_output(&sk->local_addr, foreign_addr, (fnet_uint8_t)sk->protocol_number, &(sk->options), nb);

    if((flags & MSG_DONTROUTE) != 0u) /* Restore.*/
    {
        sk->options.so_dontroute = flags_save;
    }

    if((error == FNET_ERR_OK) && (sk->options.local_error == FNET_ERR_OK)) /* We get RAW or ICMP error.*/
    {
        fnet_isr_unlock();
        return (fnet_int32_t)(len);
    }

ERROR:
    fnet_socket_set_error(sk, error);
    fnet_isr_unlock();
    return (FNET_ERR);
}
Exemple #2
0
/************************************************************************
* NAME: fnet_raw_snd
*
* DESCRIPTION: RAW send function.
*************************************************************************/
static int fnet_raw_snd( fnet_socket_t *sk, char *buf, int len, int flags, const struct sockaddr *addr)
{
    fnet_netbuf_t           *nb;
    int                     error = FNET_OK;
    const struct sockaddr   *foreign_addr;
    int                     flags_save = 0;

    if(len > sk->send_buffer.count_max)
    {
        error = FNET_ERR_MSGSIZE;   /* Message too long. */
        goto ERROR;
    }

    if(addr)
    {
        foreign_addr = addr;
    }
    else
    {
        foreign_addr = &sk->foreign_addr;
    }

    if((nb = fnet_netbuf_from_buf(buf, len, FNET_FALSE)) == 0)
    {
        error = FNET_ERR_NOMEM;     /* Cannot allocate memory.*/
        goto ERROR;
    }

    if((flags & MSG_DONTROUTE) != 0) /* Save */
    {
        flags_save = sk->options.flags;
        sk->options.flags |= SO_DONTROUTE;
    }

    error = fnet_raw_output(&sk->local_addr, foreign_addr, (unsigned char)sk->protocol_number, &(sk->options), nb);

    if((flags & MSG_DONTROUTE) != 0) /* Restore.*/
    {
        sk->options.flags = flags_save;
    }

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

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