LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to set the crc for the frame of raw socket programming (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-set-the-crc-for-the-frame-of-raw-socket-programming-4175511907/)

zerop 07-22-2014 03:35 AM

how to set the crc for the frame of raw socket programming
 
how to set the crc for the frame of raw socket programming

after googled the following function

which input are valid for it?

if frame size = 14 (header) + 46(data) + 4 (crc)

is the length parameter = 46?
is *data = the data in char[46] data, memcpy(&data, &msg[14], 46) ?

what is foxes?

ether_crc_le(int length, u8_t *data, int foxes)



// Generating polynomial:
const uint32_t ethernet_polynomial_le = 0xedb88320U;

//bit-oriented implementation: processes a byte array.
unsigned ether_crc_le(int length, u8_t *data, int foxes)
{
unsigned int crc = (foxes) ? 0xffffffff: 0; /* Initial value. */
while(--length >= 0)
{
unsigned char current_octet = *data++;
int bit;
// printf("%02X, %08X, inv %08X\n", current_octet, crc, ~crc);

for (bit = 8; --bit >= 0; current_octet >>= 1) {
if ((crc ^ current_octet) & 1) {
crc >>= 1;
crc ^= ethernet_polynomial_le;
} else
crc >>= 1;
}
}
// printf("crc final %x\n", crc);
return crc;
}


All times are GMT -5. The time now is 02:28 AM.