119 lines
4.1 KiB
Groff
119 lines
4.1 KiB
Groff
.\" $NetBSD: in4_cksum.9,v 1.5 2001/06/05 12:58:34 wiz 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 IN_CKSUM 9
|
|
.Os
|
|
.Sh NAME
|
|
.Nm in_cksum ,
|
|
.Nm in4_cksum ,
|
|
.Nm in6_cksum
|
|
.Nd compute Internet checksum
|
|
.Sh SYNOPSIS
|
|
.Ft uint16_t
|
|
.Fn in_cksum "struct mbuf *m" "int len"
|
|
.Ft uint16_t
|
|
.Fn in4_cksum "struct mbuf *m" "uint8_t nxt" "int off" "int len"
|
|
.Ft uint16_t
|
|
.Fn in6_cksum "struct mbuf *m" "uint8_t nxt" "int off" "int len"
|
|
.Sh DESCRIPTION
|
|
These functions are used to compute the ones-complement checksum
|
|
required by IP and IPv6.
|
|
The
|
|
.Fn in4_cksum
|
|
function is used to compute the transport-layer checksum required by
|
|
.Xr tcp 4
|
|
and
|
|
.Xr udp 4
|
|
over a range of bytes starting at
|
|
.Fa off
|
|
and continuing on for
|
|
.Fa len
|
|
bytes within the mbuf
|
|
.Fa m .
|
|
.Pp
|
|
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, and the transport-layer header starts at
|
|
.Fa off ;
|
|
a pseudo-header is constructed as specified
|
|
in RFC768 and RFC793, and the pseudo-header is prepended to the data
|
|
covered by the checksum.
|
|
.Pp
|
|
The
|
|
.Fn in6_cksum
|
|
function is similar; if
|
|
.Fa nxt
|
|
is non-zero, it is assumed that
|
|
.Fa m
|
|
starts with an IPv6 header, and that the transport-layer header starts
|
|
after
|
|
.Fa off
|
|
bytes.
|
|
.Pp
|
|
The
|
|
.Fn in_cksum
|
|
function is equivalent to
|
|
.Fn in4_cksum "m" "0" "0" "len" .
|
|
.Pp
|
|
These functions are always performance critical and should be
|
|
reimplemented in assembler or optimized C for each platform; when
|
|
available, use of repeated full-width add-with-carry followed by
|
|
reduction of the sum to a 16 bit width usually leads to best results.
|
|
See RFC's 1071, 1141, 1624, and 1936 for more information about
|
|
efficient computation of the internet checksum.
|
|
.Sh RETURN VALUES
|
|
All three functions return the computed checksum value.
|
|
.Sh SEE ALSO
|
|
.Xr inet 4 ,
|
|
.Xr inet6 4 ,
|
|
.Xr tcp 4 ,
|
|
.Xr udp 4 ,
|
|
.Xr protocols 5 ,
|
|
.Xr mbuf 9
|
|
.Sh STANDARDS
|
|
These functions implement the Internet transport-layer checksum as specified
|
|
in RFC768, RFC793, and RFC2460.
|
|
.Sh BUGS
|
|
The
|
|
.Fn in6_cksum
|
|
function currently requires special handling of link-local addresses
|
|
in the pseudo-header due to the use of embedded scope-id's within
|
|
link-local addresses.
|