⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pap.c

📁 PPP协议C语言源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
    len = 0;

    /* Get a pointer to the data part of the packet */
    pap_pkt_ptr = (UINT8 *)&pap_pkt->data;

    /* Set up the packet */
    pap_pkt->code        = PAP_AUTHENTICATE_REQUEST;
    pap_pkt->identifier  = LCP_Random_Number();

    /* Add length of the name of the user */
    pap_pkt_ptr[len++] = pw_id_len = (UINT8) strlen (auth->login_name);

    /* Copy the login name into the pkt. */
    for (x = 0; x < pw_id_len; x++, len++)
        pap_pkt_ptr[len] = auth->login_name[x];

    /* Add length the PW of the user */
    pap_pkt_ptr[len++] = pw_id_len = (UINT8) strlen (auth->login_pw);

    /* Copy the PW over. */
    for (x = 0; x < pw_id_len; x++)
        pap_pkt_ptr[len++] = auth->login_pw [x];

    /* Add on the LCP header to the length and
       put it in the pkt. */
    len                += LCP_HEADER_LENGTH;
    pap_pkt->length     = INTSWAP (len);

    /* Set the packet type for this buffer. */
    buf_ptr->mem_flags  = NET_PAP;

    /* Set the length of the data contained in the buffer. */
    buf_ptr->data_len   = buf_ptr->mem_total_data_len = len;

    /* Set the dlist for this buffer. */
    buf_ptr->mem_dlist  = &MEM_Buffer_Freelist;

    /* Send the pkt. */
    dev_ptr->dev_output (buf_ptr, dev_ptr, NU_NULL, NU_NULL);

}


/***************************************************************************
* FUNCTION
*
*       PAP_Timer_Expire
*
* DESCRIPTION
*
*       This function handles the authentication timer expiration. If the
*       authentication request has not been sent more than
*       LCP_MAX_AUTHENTICATE times then it will get sent again. Otherwise
*       we will consider that the authentication failed.
*
* AUTHOR
*
*       Uriah T. Pollock
*
*
* INPUTS
*
*       UNSIGNED            dev_ptr     Address of the device structure
*                                       that caused this timer event.
*
* OUTPUTS
*
*       none
*
****************************************************************************/
VOID PAP_Timer_Expire (UNSIGNED dev_ptr)
{
    DV_DEVICE_ENTRY *device;

#ifdef NU_DEBUG_PPP
    _PRINT ("\npap timer\r\n");
#endif

    /* Point to the device that cause this timer. */
    device = (DV_DEVICE_ENTRY *)dev_ptr;

    /* See if we will try again. */
    if (((LINK_LAYER *)device->link_layer)->authentication.num_timeouts-- > 0)
    {
        /* if we are a CLIENT then we need to retransmit the authentication
           packet. */
        if (((LINK_LAYER *)device->link_layer)->ipcp.mode == NCP_CLIENT)
        {
            /* Set the event that will send an authenticaion packet */
            UTL_Timerset (PAP_SEND_AUTH, dev_ptr, 0, 0);
        }
        else
        {
            /* We do not need to do anything. We are still waiting for
               a response from our CLIENT. */
        }
    }
    else
    {
        /* Stop the echo timer since we are leaving the open state */
        NU_Control_Timer (&(((LINK_LAYER *)device->link_layer)->lcp.echo_timer), NU_DISABLE_TIMER);

        /* We have tried or waited too many times. Give up. */
        NU_Set_Events (&(((LINK_LAYER *)device->link_layer)->negotiation_progression),
                            LCP_CONFIG_FAIL, NU_OR);
    }

}

/***************************************************************************
* FUNCTION
*
*       PAP_Check_Login
*
* DESCRIPTION
*
*       Searchs the password list for a correct match.
*
* AUTHOR
*
*       Uriah T. Pollock
*
* INPUTS
*
*     CHAR                      id[]        ID to check
*     CHAR                      pw[]        pw to check
*
* OUTPUTS
*
*     STATUS                    Was a correct match found
*
****************************************************************************/
STATUS PAP_Check_Login (CHAR id[PPP_MAX_ID_LENGTH], CHAR pw[PPP_MAX_PW_LENGTH])
{
    STATUS  found_it, wrong_pw;
    UINT16  index;

    /* Assume an invalid login */
    found_it = NU_FALSE;
    wrong_pw = NU_FALSE;

    /* All we need to do is loop through the password list and compare
       the ID and PW. */
    for (index = 0; (_passwordlist[index].id[0] != 0) && (found_it == NU_FALSE)
                    && (wrong_pw == NU_FALSE); index++)
    {
        /* If the IDs match, check the PW */
        if ((strcmp (id, _passwordlist[index].id)) == 0)
        {
            if ((strcmp (pw, _passwordlist[index].pw)) == 0)

                /* If they both match then we found it. */
                found_it = NU_TRUE;
            else
            {
                /* The password must be wrong. */
                wrong_pw = NU_TRUE;
            }
        }

    }

    return (found_it);
}


/***************************************************************************
* FUNCTION
*
*       PAP_Send_Authentication_Ack_Nak
*
* DESCRIPTION
*
*       Sends a PAP ack or nak packet
*
* AUTHOR
*
*       Uriah T. Pollock
*
* INPUTS
*
*       NET_BUFFER                  *in_buf_ptr Pointer to the incoming PAP
*                                               packet
*       UINT8                       pkt_type    Which type to send - ACK or NAK
*       UINT8                       req_id      ID of the request that caused
*                                               this ACK/NAK
*
* OUTPUTS
*
*       none
*
****************************************************************************/
VOID PAP_Send_Authentication_Ack_Nak(NET_BUFFER *in_buf_ptr, UINT8 pkt_type,
                                     UINT8 req_id)
{
    NET_BUFFER  *buf_ptr;
    LCP_HEADER   *pap_pkt;
    UINT16      len;

#ifdef NU_DEBUG_PPP
    if (pkt_type == PAP_AUTHENTICATE_ACK)
        _PRINT ("send ack\r\n");
    else
        _PRINT ("send nak\r\n");
#endif

    len = 0;

    /* Allocate a buffer for the PAP packet. */
    buf_ptr = MEM_Buffer_Dequeue (&MEM_Buffer_Freelist);

    /* Make sure a buffer was available */
    if (buf_ptr == NU_NULL)
    {
        NERRS_Log_Error (NERR_RECOVERABLE, __FILE__, __LINE__);

        /* Get out */
        return;
    }

    /* Set the data ptr */
    buf_ptr->data_ptr = buf_ptr->mem_parent_packet + in_buf_ptr->mem_buf_device->dev_hdrlen;
    pap_pkt = (LCP_HEADER *) buf_ptr->data_ptr;

    /* We will not send a msg. So set the msg len to 0. The msg length
       is the first byte of data. */
    pap_pkt->data = 0;
    len++;                                  /* bump length for this one byte */

    /* Set up the packet */
    if (pkt_type == PAP_AUTHENTICATE_ACK)
    {
        pap_pkt->code = PAP_AUTHENTICATE_ACK;
    }
    else
    {
        pap_pkt->code = PAP_AUTHENTICATE_NAK;
    }

    pap_pkt->identifier  = req_id;

    /* Add on the LCP header to the length and
       put it in the pkt. */
    len += LCP_HEADER_LENGTH;
    pap_pkt->length = INTSWAP (len);

    /* Set the lengths for the packet buffer. */
    buf_ptr->data_len = buf_ptr->mem_total_data_len = len;

    /* Set the packet type. */
    buf_ptr->mem_flags = NET_PAP;

    /* Set the dlist for this buffer. */
    buf_ptr->mem_dlist = &MEM_Buffer_Freelist;

    /* Send the pkt. */
    in_buf_ptr->mem_buf_device->dev_output (buf_ptr,
                in_buf_ptr->mem_buf_device, NU_NULL, NU_NULL);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -