in4_cksum.9 revision 1.1 $NetBSD: in4_cksum.9,v 1.1 2001/05/23 15:58:41 sommerfeld Exp $ Copyright (c) 2001 The NetBSD Foundation, Inc. All rights reserved. This code is derived from software contributed to The NetBSD Foundation by Bill Sommerfeld. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by the NetBSD Foundation, Inc. and its contributors. 4. Neither the name of The NetBSD Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE..Dd May 22, 2001
.Dt in4_cksum 9
.Os
.Sh NAME
.Nm in4_cksum
.Nd Compute checksum for IPv4 packets.
.Sh SYNOPSIS
.Ft uint16_t
.Fn in4_cksum "struct mbuf *m" "uint8_t nxt" "int off" "int len"
.Sh DESCRIPTION
The
.Fn in4_cksum
function is used to compute the ones-complement checksum required by the
.Xr inet 4
protocol family over a range of bytes starting at
.Fa off
and continuing on for
.Fa len
bytes within the mbuf
.Fa m .
p
If the
.Fa nxt
parameter is non-zero, it is assumed to be an IP protocol number.
It is also assumed that the data within
.Fa m
starts with an ip header; a pseudo-header is constructed as specified
in RFC768 and RFC793, and the pseudo-header is prepended to the data
covered by the checksum.
p
This function is almost always performance critical and should be
reimplemented in assembler or optimized C for each platform; use of
repeated full-width add-with-carry followed by reduction of the sum to
a 16 bit width usually leads to best results.
.Sh RETURN VALUES
The
.Nm
function returns the computed checksum value.
.Sh SEE ALSO
.Xr inet 4 ,
.Xr mbuf 9 ,
.Xr protocols 5 ,
.Xr tcp 4 ,
.Xr udp 4 .
.Sh STANDARDS
The
.Nm
function implements the checksum specified in RFC768 and RFC793