wireshark校验和checksum和artnet校验和checksum算法
wireshark校验和checksum
//计算校验和
uint16_t checksum(uint16_t* data, int size)
{
uint32_t chksum = 0;
while (size > 1)
{
chksum += *data++;
size -= sizeof(uint16_t);
}
if (size)
{
chksum += *(uint8_t*)data;
}
while (chksum >> 16)
{
chksum = (chksum >> 16) + (chksum & 0xffff);
}
return (uint16_t)(~chksum);
}
artnet校验和checksum算法
uint16_t ChkSum(uint8_t * data, int size)
{
uint16_t chkSum = 0;
for (int i = 0; i < size; i++)
{
chkSum += data[i];
}
return chkSum + 0xCC;
}