1 .\" $NetBSD: in4_cksum.9,v 1.5 2001/06/05 12:58:34 wiz Exp $
3 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Bill Sommerfeld.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
37 .Nd compute Internet checksum
40 .Fn in_cksum "struct mbuf *m" "int len"
42 .Fn in4_cksum "struct mbuf *m" "uint8_t nxt" "int off" "int len"
44 .Fn in6_cksum "struct mbuf *m" "uint8_t nxt" "int off" "int len"
46 These functions are used to compute the ones-complement checksum
47 required by IP and IPv6.
50 function is used to compute the transport-layer checksum required by
54 over a range of bytes starting at
63 parameter is non-zero, it is assumed to be an IP protocol number.
64 It is also assumed that the data within
66 starts with an IP header, and the transport-layer header starts at
68 a pseudo-header is constructed as specified
69 in RFC768 and RFC793, and the pseudo-header is prepended to the data
70 covered by the checksum.
74 function is similar; if
76 is non-zero, it is assumed that
78 starts with an IPv6 header, and that the transport-layer header starts
85 function is equivalent to
86 .Fn in4_cksum "m" "0" "0" "len" .
88 These functions are always performance critical and should be
89 reimplemented in assembler or optimized C for each platform; when
90 available, use of repeated full-width add-with-carry followed by
91 reduction of the sum to a 16 bit width usually leads to best results.
92 See RFC's 1071, 1141, 1624, and 1936 for more information about
93 efficient computation of the internet checksum.
95 All three functions return the computed checksum value.
104 These functions implement the Internet transport-layer checksum as specified
105 in RFC768, RFC793, and RFC2460.
109 function currently requires special handling of link-local addresses
110 in the pseudo-header due to the use of embedded scope-id's within
111 link-local addresses.