FreeBSD/usr.sbin/timed/timed/cksum.c
/*
 *			I N _ C K S U M
 *
 * Checksum routine for Internet Protocol family headers (C Version)
 *
 * There is no profit in a specialized version of the checksum
 * function for any machine where int's are 32 bits and shorts are 16.
 *
 * All timed packets are smaller than 32K shorts, so there is no need to
 * worry about carries except at the end.
 */
I N _ C K S U M
Checksum routine for Internet Protocol family headers (C Version)

There is no profit in a specialized version of the checksum
function for any machine where int's are 32 bits and shorts are 16.

All timed packets are smaller than 32K shorts, so there is no need to
worry about carries except at the end.
I N _ C K S U M Checksum routine for Internet Protocol family headers ( C Version ) There is no profit in a specialized version of the checksum function for any machine where int ' s are 32 bits and shorts are 16 . All timed packets are smaller than 32K shorts so there is no need to worry about carries except at the end .
int
in_cksum(u_short *addr, int len)
{
	register int nleft = len;
	register u_short *w = addr;
	register u_short answer;
	register int sum = 0;
	while( nleft > 1 )  {
		sum += *w++;
		nleft -= 2;
	}
	if( nleft == 1 )
		sum += (*(u_char *)w) << 8;
	sum = (sum >> 16) + (sum & 0xffff);	
	sum += (sum >> 16);			
	answer = ~sum;				
	return (answer);
}
int in_cksum ( u_short * addr , int len ) { register int nleft = len ; register u_short * w = addr ; register u_short answer ; register int sum = 0 ; while ( nleft > 1 ) { sum += * w ++ ; nleft -= 2 ; } if ( nleft == 1 ) sum += ( * ( u_char * ) w ) << 8 ; sum = ( sum >> 16 ) + ( sum & 0xffff ) ; sum += ( sum >> 16 ) ; answer = ~ sum ; return ( answer ) ; }
I N _ C K S U M
 Checksum routine for Internet Protocol family headers (C Version)
I N _ C K S U M Checksum routine for Internet Protocol family headers ( C Version )
/*
	 *  Our algorithm is simple, using a 32 bit accumulator (sum),
	 *  we add sequential 16 bit words to it, and at the end, fold
	 *  back all the carry bits from the top 16 bits into the lower
	 *  16 bits.
	 */ /* mop up an odd byte, if necessary */ /*
	 * add back carry outs from top 16 bits to low 16 bits
	 */ /* add hi 16 to low 16 */ /* add carry */ /* truncate to 16 bits */