Commit | Line | Data |
---|---|---|
e4c3f0d8 KB |
1 | /*- |
2 | * Copyright (c) 1991 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
6 | * | |
d03611d5 | 7 | * @(#)lfs_cksum.c 7.5 (Berkeley) %G% |
e4c3f0d8 KB |
8 | */ |
9 | ||
d03611d5 | 10 | #include <sys/types.h> |
e4c3f0d8 KB |
11 | |
12 | /* | |
275ca4f0 KB |
13 | * Simple, general purpose, fast checksum. Data must be short-aligned. |
14 | * Returns a u_long in case we ever want to do something more rigorous. | |
f6437c6d KB |
15 | * |
16 | * XXX | |
17 | * Use the TCP/IP checksum instead. | |
e4c3f0d8 KB |
18 | */ |
19 | u_long | |
20 | cksum(str, len) | |
21 | register void *str; | |
22 | register size_t len; | |
23 | { | |
24 | register u_long sum; | |
25 | ||
26 | len &= ~(sizeof(u_short) - 1); | |
aac71cb6 KB |
27 | for (sum = 0; len; len -= sizeof(u_short)) { |
28 | sum ^= *(u_short *)str; | |
29 | ++(u_short *)str; | |
30 | } | |
e4c3f0d8 KB |
31 | return (sum); |
32 | } |