changelog shortlog tags branches changeset file revisions annotate raw help

Mercurial > hg > plan9front / sys/src/9/ip/ptclbsum.c

revision 7035: 65dab5125d9d
parent 7034: fe9f017a9d36
child 7036: 7bb53313aac9
     1.1deleted file mode 100644
     1.2--- a/sys/src/9/ip/ptclbsum.c
     1.3+++ /dev/null
     1.4@@ -1,72 +0,0 @@
     1.5-#include	"u.h"
     1.6-#include	"../port/lib.h"
     1.7-#include	"mem.h"
     1.8-#include	"dat.h"
     1.9-#include	"fns.h"
    1.10-#include	"../port/error.h"
    1.11-#include	"ip.h"
    1.12-
    1.13-static	short	endian	= 1;
    1.14-static	uchar*	aendian	= (uchar*)&endian;
    1.15-#define	LITTLE	*aendian
    1.16-
    1.17-ushort
    1.18-ptclbsum(uchar *addr, int len)
    1.19-{
    1.20-	ulong losum, hisum, mdsum, x;
    1.21-	ulong t1, t2;
    1.22-
    1.23-	losum = 0;
    1.24-	hisum = 0;
    1.25-	mdsum = 0;
    1.26-
    1.27-	x = 0;
    1.28-	if((ulong)addr & 1) {
    1.29-		if(len) {
    1.30-			hisum += addr[0];
    1.31-			len--;
    1.32-			addr++;
    1.33-		}
    1.34-		x = 1;
    1.35-	}
    1.36-	while(len >= 16) {
    1.37-		t1 = *(ushort*)(addr+0);
    1.38-		t2 = *(ushort*)(addr+2);	mdsum += t1;
    1.39-		t1 = *(ushort*)(addr+4);	mdsum += t2;
    1.40-		t2 = *(ushort*)(addr+6);	mdsum += t1;
    1.41-		t1 = *(ushort*)(addr+8);	mdsum += t2;
    1.42-		t2 = *(ushort*)(addr+10);	mdsum += t1;
    1.43-		t1 = *(ushort*)(addr+12);	mdsum += t2;
    1.44-		t2 = *(ushort*)(addr+14);	mdsum += t1;
    1.45-		mdsum += t2;
    1.46-		len -= 16;
    1.47-		addr += 16;
    1.48-	}
    1.49-	while(len >= 2) {
    1.50-		mdsum += *(ushort*)addr;
    1.51-		len -= 2;
    1.52-		addr += 2;
    1.53-	}
    1.54-	if(x) {
    1.55-		if(len)
    1.56-			losum += addr[0];
    1.57-		if(LITTLE)
    1.58-			losum += mdsum;
    1.59-		else
    1.60-			hisum += mdsum;
    1.61-	} else {
    1.62-		if(len)
    1.63-			hisum += addr[0];
    1.64-		if(LITTLE)
    1.65-			hisum += mdsum;
    1.66-		else
    1.67-			losum += mdsum;
    1.68-	}
    1.69-
    1.70-	losum += hisum >> 8;
    1.71-	losum += (hisum & 0xff) << 8;
    1.72-	while(hisum = losum>>16)
    1.73-		losum = hisum + (losum & 0xffff);
    1.74-
    1.75-	return losum & 0xffff;
    1.76-}