|
|
1.1 ! root 1: #include "../h/param.h" ! 2: ! 3: /* ! 4: * Compute a 16 bit checksum for the internet. ! 5: * This routine will only work on a 68020 as it assumes ! 6: * a short pointer can be used to access odd addresses. ! 7: * If odd is set, reverse the bytes in the sum. ! 8: */ ! 9: vecadd(w, len, sum, odd) ! 10: register u_short *w; ! 11: register int len; ! 12: register u_long sum; ! 13: int odd; ! 14: { ! 15: register u_char *c; ! 16: int extra; ! 17: ! 18: if (odd) { ! 19: c = (u_char *)w; ! 20: sum += *c++; ! 21: w = (u_short *)c; ! 22: len--; ! 23: } ! 24: extra = (int)len & 1; ! 25: len >>= 1; ! 26: while (len--) ! 27: sum += *w++; ! 28: if (extra) { ! 29: c = (u_char *)w; ! 30: sum += *c << 8; ! 31: } ! 32: sum = (sum >> 16) + (sum & 0xffff); ! 33: /* Check for a carry */ ! 34: if (sum & 0x10000) ! 35: sum = (sum & ~0x10000) + 1; ! 36: return (sum); ! 37: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.