]>
git.saurik.com Git - apple/xnu.git/blob - tests/in_cksum.c
2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1988, 1992, 1993
26 * The Regents of the University of California. All rights reserved.
28 * @(#)in_cksum.c 8.1 (Berkeley) 6/10/93
31 #include <sys/param.h>
44 static __inline__
void
50 *sum
= l_util
.s
[0] + l_util
.s
[1];
61 in_cksum(void * pkt
, int len
)
67 while ((len
-= 32) >= 0) {
68 sum
+= w
[0]; sum
+= w
[1];
69 sum
+= w
[2]; sum
+= w
[3];
70 sum
+= w
[4]; sum
+= w
[5];
71 sum
+= w
[6]; sum
+= w
[7];
72 sum
+= w
[8]; sum
+= w
[9];
73 sum
+= w
[10]; sum
+= w
[11];
74 sum
+= w
[12]; sum
+= w
[13];
75 sum
+= w
[14]; sum
+= w
[15];
79 while ((len
-= 8) >= 0) {
80 sum
+= w
[0]; sum
+= w
[1];
81 sum
+= w
[2]; sum
+= w
[3];
87 while ((len
-= 2) >= 0) {
91 if (len
== -1) { /* odd-length packet */
95 s_util
.c
[0] = *((char *)w
);
100 return ~sum
& 0xffff;