Annotation of 43BSD/etc/timed/m68000/cksum.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.  The Berkeley software License Agreement
        !             4:  * specifies the terms and conditions for redistribution.
        !             5:  */
        !             6: 
        !             7: #ifndef lint
        !             8: static char sccsid[] = "@(#)cksum.c    2.1 (Berkeley) 6/6/86";
        !             9: #endif not lint
        !            10: 
        !            11: #include "../globals.h"
        !            12: #include <protocols/timed.h>
        !            13: 
        !            14: /* computes the checksum for ip packets for a Motorola 68000 base computer */
        !            15: 
        !            16: in_cksum(w, mlen)
        !            17:        register u_short *w;
        !            18:        register int mlen;
        !            19: {
        !            20:        register int sum = 0;
        !            21: 
        !            22:        if (mlen > 0) {
        !            23:                if (((int)w & 1) == 0) {
        !            24:                        sum = ocsum(w, mlen>>1);
        !            25:                        w += mlen>>1;
        !            26:                        if (mlen & 1) {
        !            27:                                sum += *(u_char *)w << 8;
        !            28:                                mlen = -1;
        !            29:                        }
        !            30:                } else {
        !            31:                        u_short swsum;
        !            32: 
        !            33:                        sum = *(u_char *)w << 8;
        !            34:                        mlen--;
        !            35:                        w = (u_short *)(1 + (int)w);
        !            36:                        swsum = ocsum(w, mlen>>1);
        !            37:                        swab((char *)&swsum, (char *)&swsum, sizeof swsum);
        !            38:                        sum += swsum;
        !            39:                        w += mlen>>1;
        !            40:                        if (mlen & 1)
        !            41:                                sum += *(u_char *)w;
        !            42:                }
        !            43:        }
        !            44:        sum = (sum & 0xFFFF) + (sum >> 16);
        !            45:        sum = (sum & 0xFFFF) + (sum >> 16);
        !            46:        sum = (~sum) & 0xFFFF;
        !            47:        return (sum);
        !            48: }

unix.superglobalmegacorp.com

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