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

📄 packetcrc.cpp

📁 VC++ 6.0NDIS, NDIS Miniport NIC Drivers
💻 CPP
字号:

#include "../../../include/kdndis.h"
#include "ne2000.h"


/*++
Routine Description:
    Runs the AUTODIN II CRC algorithm on buffer Buffer of
    length Length.
Arguments:
    Buffer - the input buffer
    Length - the length of Buffer
Return Value:
    The 32-bit CRC value.
Note:
    This is adapted from the comments in the assembly language
    version in _GENREQ.ASM of the DWB NE1000/2000 driver.

--*/
ULONG CardComputeCrc(IN PUCHAR Buffer, IN UINT Length)

{
    ULONG Crc, Carry;
    UINT i, j;
    UCHAR CurByte;

    Crc = 0xffffffff;

    for (i = 0; i < Length; i++) 
    {

       CurByte = Buffer[i];
        for (j = 0; j < 8; j++) 
        {
            Carry = ((Crc & 0x80000000) ? 1 : 0) ^ (CurByte & 0x01);
            Crc <<= 1;
            CurByte >>= 1;
            if (Carry) 
            {
                Crc = (Crc ^ 0x04c11db6) | Carry;
            }
        }
    }
    return Crc;
}


/*++
Routine Description:
    For a given multicast address, returns the byte and bit in
    the card multicast registers that it hashes to. Calls
    CardComputeCrc() to determine the CRC value.
Arguments:
    Address - the address
    Byte - the byte that it hashes to
    Value - will have a 1 in the relevant bit

--*/
VOID CardGetMulticastBit(IN UCHAR Address[NE2000_LENGTH_OF_ADDRESS], OUT UCHAR * Byte, OUT UCHAR * Value)
{
    ULONG Crc;
    UINT BitNumber;

    // First compute the CRC.
    Crc = CardComputeCrc(Address, NE2000_LENGTH_OF_ADDRESS);
    // The bit number is now in the 6 most significant bits of CRC.
    BitNumber = (UINT)((Crc >> 26) & 0x3f);

    *Byte = (UCHAR)(BitNumber / 8);
    *Value = (UCHAR)((UCHAR)1 << (BitNumber % 8));
}

⌨️ 快捷键说明

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