xref: /netbsd-src/share/man/man9/in4_cksum.9 (revision 11a6dbe72840351315e0652b2fc6663628c84cad)
1.\"	$NetBSD: in4_cksum.9,v 1.6 2008/04/30 13:10:58 martin Exp $
2.\"
3.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Bill Sommerfeld.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
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.
17.\"
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.
29.\"
30.Dd May 22, 2001
31.Dt IN_CKSUM 9
32.Os
33.Sh NAME
34.Nm in_cksum ,
35.Nm in4_cksum ,
36.Nm in6_cksum
37.Nd compute Internet checksum
38.Sh SYNOPSIS
39.Ft uint16_t
40.Fn in_cksum "struct mbuf *m" "int len"
41.Ft uint16_t
42.Fn in4_cksum "struct mbuf *m" "uint8_t nxt" "int off" "int len"
43.Ft uint16_t
44.Fn in6_cksum "struct mbuf *m" "uint8_t nxt" "int off" "int len"
45.Sh DESCRIPTION
46These functions are used to compute the ones-complement checksum
47required by IP and IPv6.
48The
49.Fn in4_cksum
50function is used to compute the transport-layer checksum required by
51.Xr tcp 4
52and
53.Xr udp 4
54over a range of bytes starting at
55.Fa off
56and continuing on for
57.Fa len
58bytes within the mbuf
59.Fa m .
60.Pp
61If the
62.Fa nxt
63parameter is non-zero, it is assumed to be an IP protocol number.
64It is also assumed that the data within
65.Fa m
66starts with an IP header, and the transport-layer header starts at
67.Fa off ;
68a pseudo-header is constructed as specified
69in RFC768 and RFC793, and the pseudo-header is prepended to the data
70covered by the checksum.
71.Pp
72The
73.Fn in6_cksum
74function is similar; if
75.Fa nxt
76is non-zero, it is assumed that
77.Fa m
78starts with an IPv6 header, and that the transport-layer header starts
79after
80.Fa off
81bytes.
82.Pp
83The
84.Fn in_cksum
85function is equivalent to
86.Fn in4_cksum "m" "0" "0" "len" .
87.Pp
88These functions are always performance critical and should be
89reimplemented in assembler or optimized C for each platform; when
90available, use of repeated full-width add-with-carry followed by
91reduction of the sum to a 16 bit width usually leads to best results.
92See RFC's 1071, 1141, 1624, and 1936 for more information about
93efficient computation of the internet checksum.
94.Sh RETURN VALUES
95All three functions return the computed checksum value.
96.Sh SEE ALSO
97.Xr inet 4 ,
98.Xr inet6 4 ,
99.Xr tcp 4 ,
100.Xr udp 4 ,
101.Xr protocols 5 ,
102.Xr mbuf 9
103.Sh STANDARDS
104These functions implement the Internet transport-layer checksum as specified
105in RFC768, RFC793, and RFC2460.
106.Sh BUGS
107The
108.Fn in6_cksum
109function currently requires special handling of link-local addresses
110in the pseudo-header due to the use of embedded scope-id's within
111link-local addresses.
112