4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1996-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
31 #include <netinet/in.h>
32 #include "v4_sum_impl.h"
35 * RFC 768 pseudo header. Used in calculating UDP checksums.
40 uint8_t notused
; /* always zero */
41 uint8_t proto
; /* protocol used */
42 uint16_t len
; /* UDP len */
46 * One's complement checksum of pseudo header, udp header, and data.
50 udp_chksum(struct udphdr
*udph
, const struct in_addr
*src
,
51 const struct in_addr
*dst
, uint8_t proto
)
54 uint16_t *end_pseudo_hdr
= (uint16_t *)(&ck
+ 1);
55 uint16_t *sp
= (uint16_t *)&ck
;
60 * Start on the pseudo header. Note that pseudo_udp already takes
61 * acount for the udphdr...
64 bzero(&ck
, sizeof (ck
));
69 ck
.len
= udph
->uh_ulen
;
73 * If the packet is an odd length, zero the pad byte for checksum
74 * purposes [doesn't hurt data]
77 cnt
= ntohs(ck
.len
) + sizeof (ck
);
79 ((caddr_t
)udph
)[ntohs(udph
->uh_ulen
)] = '\0';
80 cnt
++; /* make even */
83 for (cnt
>>= 1; cnt
!= 0; cnt
--) {
86 if (sum
>= BIT_WRAP
) {
87 /* Wrap carries into low bit */
93 * If we've finished checking the pseudo-header, move
94 * onto the udp header and data.
97 if (sp
== end_pseudo_hdr
)
98 sp
= (uint16_t *)udph
;
101 return (~sum
== 0 ? ~0 : ~sum
);