2 * Computes the standard internet checksum of a set of data (from RFC1071)
3 * ChangeLog since sendip 2.0:
4 * 02/12/2001: Moved ipv6_csum into icmp.c as that is where it is used
5 * 22/01/2002: Include types.h to make sure u_int*_t defined on Solaris
8 #define __USE_BSD /* GLIBC */
9 #define _BSD_SOURCE /* LIBC5 */
10 #include <sys/types.h>
11 #include <netinet/in_systm.h>
12 #include <netinet/in.h>
17 u_int16_t csum (u_int16_t *packet, int packlen);
19 /* Checksum a block of data */
20 u_int16_t csum (u_int16_t *packet, int packlen) {
21 register unsigned long sum = 0;
29 sum += *(unsigned char *)packet;
31 /* TODO: this depends on byte order */
34 sum = (sum & 0xffff) + (sum >> 16);
36 return (u_int16_t) ~sum;