File: csum.c

package info (click to toggle)
dnprogs 2.43.2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,936 kB
  • ctags: 3,872
  • sloc: ansic: 24,686; cpp: 10,608; makefile: 769; sh: 551; awk: 13
file content (27 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (2)
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:     Patrick Caulfield <patrick@debian.org>
 *
 */
#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;
}