File:  [Research Unix] / researchv9 / sys / inet / vecadd.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:59 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv9-SUN3_old, researchv9-SUN3, HEAD
researchv9-SUN3(old)

#include "../h/param.h"

/*
 * Compute a 16 bit checksum for the internet.
 * This routine will only work on a 68020 as it assumes
 * a short pointer can be used to access odd addresses.
 * If odd is set, reverse the bytes in the sum.
 */
vecadd(w, len, sum, odd)
register u_short *w;
register int len;
register u_long sum;
int odd;
{
	register u_char *c;
	int extra;

	if (odd) {
		c = (u_char *)w;
		sum += *c++;
		w = (u_short *)c;
		len--;
	}
	extra = (int)len & 1;
	len >>= 1;
	while (len--)
		sum += *w++;
	if (extra) {
		c = (u_char *)w;
		sum += *c << 8;
	}
	sum = (sum >> 16) + (sum & 0xffff);
	/* Check for a carry */
	if (sum & 0x10000)
		sum = (sum & ~0x10000) + 1;
	return (sum);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.