File: csum.c

package info (click to toggle)
dnprogs 2.52
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,644 kB
  • ctags: 4,021
  • sloc: ansic: 26,737; cpp: 10,666; makefile: 832; sh: 537; awk: 13
file content (27 lines) | stat: -rw-r--r-- 748 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * csum.c       Checksum calculation for DECnet routing
 *
 *		This program is free software; you can redistribute it and/or
 *		modify it under the terms of the GNU General Public License
 *		as published by the Free Software Foundation; either version
 *		2 of the License, or (at your option) any later version.
 *
 * Authors:     Christine Caulfield <christine.caulfield@googlemail.com>
 *
 */
#include <stdio.h>

unsigned short route_csum(unsigned char *buf, int start, int end)
{
    unsigned int  sum = 1; /* Starting value for Phase IV */
    int i;

    for (i=start; i<end; i++, i++)
    {
	sum += buf[i] + (buf[i+1]<<8);
    }
    sum = (sum>>16) + (sum&0xFFFF);
    sum = (sum>>16) + (sum&0xFFFF);

    return (unsigned short)sum;
}