Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/ip/ptclbsum.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname ip/ptclbsum.c 1997/0926
## diff -e /dev/null /n/emeliedump/1997/0926/sys/src/brazil/ip/ptclbsum.c
0a
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"
#include	"kernel.h"
#include	"ip.h"

static	short	endian	= 1;
static	byte*	aendian	= (byte*)&endian;
#define	LITTLE	*aendian

ushort
ptclbsum(byte *addr, int len)
{
	ulong losum, hisum, mdsum, x;
	ulong t1, t2;

	losum = 0;
	hisum = 0;
	mdsum = 0;

	x = 0;
	if((ulong)addr & 1) {
		if(len) {
			hisum += addr[0];
			len--;
			addr++;
		}
		x = 1;
	}
	while(len >= 16) {
		t1 = *(ushort*)(addr+0);
		t2 = *(ushort*)(addr+2);	mdsum += t1;
		t1 = *(ushort*)(addr+4);	mdsum += t2;
		t2 = *(ushort*)(addr+6);	mdsum += t1;
		t1 = *(ushort*)(addr+8);	mdsum += t2;
		t2 = *(ushort*)(addr+10);	mdsum += t1;
		t1 = *(ushort*)(addr+12);	mdsum += t2;
		t2 = *(ushort*)(addr+14);	mdsum += t1;
		mdsum += t2;
		len -= 16;
		addr += 16;
	}
	while(len >= 2) {
		mdsum += *(ushort*)addr;
		len -= 2;
		addr += 2;
	}
	if(x) {
		if(len)
			losum += addr[0];
		if(LITTLE)
			losum += mdsum;
		else
			hisum += mdsum;
	} else {
		if(len)
			hisum += addr[0];
		if(LITTLE)
			hisum += mdsum;
		else
			losum += mdsum;
	}

	losum += hisum >> 8;
	losum += (hisum & 0xff) << 8;
	while(hisum = losum>>16)
		losum = hisum + (losum & 0xffff);

	return losum & 0xffff;
}
.
## diffname ip/ptclbsum.c 1998/0306
## diff -e /n/emeliedump/1997/0926/sys/src/brazil/ip/ptclbsum.c /n/emeliedump/1998/0306/sys/src/brazil/ip/ptclbsum.c
15c
ptclbsum(uchar *addr, int len)
.
11c
static	uchar*	aendian	= (uchar*)&endian;
.
## diffname ip/ptclbsum.c 2000/1111
## diff -e /n/emeliedump/1998/0306/sys/src/brazil/ip/ptclbsum.c /n/emeliedump/2000/1111/sys/src/9/ip/ptclbsum.c
7d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.