1.\" $NetBSD: in4_cksum.9,v 1.5 2001/06/05 12:58:34 wiz 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.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd May 22, 2001 38.Dt IN_CKSUM 9 39.Os 40.Sh NAME 41.Nm in_cksum , 42.Nm in4_cksum , 43.Nm in6_cksum 44.Nd compute Internet checksum 45.Sh SYNOPSIS 46.Ft uint16_t 47.Fn in_cksum "struct mbuf *m" "int len" 48.Ft uint16_t 49.Fn in4_cksum "struct mbuf *m" "uint8_t nxt" "int off" "int len" 50.Ft uint16_t 51.Fn in6_cksum "struct mbuf *m" "uint8_t nxt" "int off" "int len" 52.Sh DESCRIPTION 53These functions are used to compute the ones-complement checksum 54required by IP and IPv6. 55The 56.Fn in4_cksum 57function is used to compute the transport-layer checksum required by 58.Xr tcp 4 59and 60.Xr udp 4 61over a range of bytes starting at 62.Fa off 63and continuing on for 64.Fa len 65bytes within the mbuf 66.Fa m . 67.Pp 68If the 69.Fa nxt 70parameter is non-zero, it is assumed to be an IP protocol number. 71It is also assumed that the data within 72.Fa m 73starts with an IP header, and the transport-layer header starts at 74.Fa off ; 75a pseudo-header is constructed as specified 76in RFC768 and RFC793, and the pseudo-header is prepended to the data 77covered by the checksum. 78.Pp 79The 80.Fn in6_cksum 81function is similar; if 82.Fa nxt 83is non-zero, it is assumed that 84.Fa m 85starts with an IPv6 header, and that the transport-layer header starts 86after 87.Fa off 88bytes. 89.Pp 90The 91.Fn in_cksum 92function is equivalent to 93.Fn in4_cksum "m" "0" "0" "len" . 94.Pp 95These functions are always performance critical and should be 96reimplemented in assembler or optimized C for each platform; when 97available, use of repeated full-width add-with-carry followed by 98reduction of the sum to a 16 bit width usually leads to best results. 99See RFC's 1071, 1141, 1624, and 1936 for more information about 100efficient computation of the internet checksum. 101.Sh RETURN VALUES 102All three functions return the computed checksum value. 103.Sh SEE ALSO 104.Xr inet 4 , 105.Xr inet6 4 , 106.Xr tcp 4 , 107.Xr udp 4 , 108.Xr protocols 5 , 109.Xr mbuf 9 110.Sh STANDARDS 111These functions implement the Internet transport-layer checksum as specified 112in RFC768, RFC793, and RFC2460. 113.Sh BUGS 114The 115.Fn in6_cksum 116function currently requires special handling of link-local addresses 117in the pseudo-header due to the use of embedded scope-id's within 118link-local addresses. 119