22 lines
404 B
C
22 lines
404 B
C
/*
|
||
* eth_ip_checksum.c
|
||
*
|
||
* Created on: 14 мар. 2023 г.
|
||
* Author: sychev
|
||
*/
|
||
#include "eth_ip_checksum.h"
|
||
#include "free_rtos/base/swap.h"
|
||
|
||
uint16_t eth_ip_calcChecksum(uint16_t * const data, uint32_t length)
|
||
{
|
||
uint32_t i, crc = 0;
|
||
|
||
for (i = 0 ; i < length; ++i ) {
|
||
crc += BASE_SWAP16(data[i]);
|
||
}
|
||
|
||
crc = (crc & 0xffff) + (crc >> 16);
|
||
|
||
return (uint16_t) (~crc);
|
||
}
|