sitara_depot/components/free_rtos/ethernet_ip/eth_ip_checksum.c

23 lines
391 B
C
Raw Normal View History

/*
* eth_ip_checksum.c
*
* Created on: 14 <EFBFBD><EFBFBD><EFBFBD>. 2023 <EFBFBD>.
* Author: sychev
*/
#include "eth_ip_checksum.h"
#include "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);
}