aboutsummaryrefslogtreecommitdiff
path: root/Semestr 4/sieci/pracownia1/icmp_checksum.c
blob: c9dc96b80db02087f4724fa375aab163929cd9d0 (plain)
1
2
3
4
5
6
7
8
9
10
u_int16_t compute_icmp_checksum (const void *buff, int length)
{
	u_int32_t sum;
	const u_int16_t* ptr = buff;
	assert (length % 2 == 0);
	for (sum = 0; length > 0; length -= 2)
		sum += *ptr++;
	sum = (sum >> 16) + (sum & 0xffff);
	return (u_int16_t)(~(sum + (sum >> 16)));
}