in_cksum.h revision 99040
1139969Simp/*-
281588Sru * Copyright (c) 1990 The Regents of the University of California.
362813Speter * All rights reserved.
462813Speter *
562813Speter * Redistribution and use in source and binary forms, with or without
662813Speter * modification, are permitted provided that the following conditions
762813Speter * are met:
862813Speter * 1. Redistributions of source code must retain the above copyright
962813Speter *    notice, this list of conditions and the following disclaimer.
1062813Speter * 2. Redistributions in binary form must reproduce the above copyright
1162813Speter *    notice, this list of conditions and the following disclaimer in the
1262813Speter *    documentation and/or other materials provided with the distribution.
1362813Speter * 3. All advertising materials mentioning features or use of this software
1462813Speter *    must display the following acknowledgement:
1562813Speter *	This product includes software developed by the University of
1662813Speter *	California, Berkeley and its contributors.
1762813Speter * 4. Neither the name of the University nor the names of its contributors
1862813Speter *    may be used to endorse or promote products derived from this software
1962813Speter *    without specific prior written permission.
2062813Speter *
2162813Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2262813Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2362813Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2462813Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2562813Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2662813Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27236118Smdf * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2862813Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2979535Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3062813Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3162813Speter * SUCH DAMAGE.
3294937Smux *
3362813Speter *	from tahoe:	in_cksum.c	1.2	86/01/05
3468963Sru *	from:		@(#)in_cksum.c	1.3 (Berkeley) 1/19/91
35236118Smdf *	from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp
3694937Smux * $FreeBSD: head/sys/powerpc/include/in_cksum.h 99040 2002-06-29 09:49:26Z benno $
37236118Smdf */
3894937Smux
3994937Smux#ifndef _MACHINE_IN_CKSUM_H_
40150101Srwatson#define	_MACHINE_IN_CKSUM_H_	1
4194937Smux
4294937Smux#include <sys/cdefs.h>
4362813Speter
4483760Sru#define in_cksum(m, len)	in_cksum_skip(m, len, 0)
4568963Sru
4694937Smux/*
4794937Smux * It it useful to have an Internet checksum routine which is inlineable
4862813Speter * and optimized specifically for the task of computing IP header checksums
4962813Speter * in the normal case (where there are no options and the header length is
5083760Sru * therefore always exactly five 32-bit words.
5183760Sru */
5283760Sru#ifdef __GNUC__
5383760Sru
5462813Speterstatic __inline void
5562813Speterin_cksum_update(struct ip *ip)
5694937Smux{
57236118Smdf	int __tmpsum;
58236118Smdf	__tmpsum = (int)ntohs(ip->ip_sum) + 256;
59236118Smdf	ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16));
60236118Smdf}
61236118Smdf
6294937Smux#else
6394937Smux
6494937Smux#define	in_cksum_update(ip) \
6594937Smux	do { \
6694937Smux		int __tmpsum; \
6797502Sru		__tmpsum = (int)ntohs(ip->ip_sum) + 256; \
6894937Smux		ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); \
6994937Smux	} while(0)
70150101Srwatson
71150101Srwatson#endif
72150101Srwatson
73150101Srwatson#ifdef _KERNEL
74150101Srwatsonu_int in_cksum_hdr(const struct ip *ip);
75187142Sluigiu_short	in_addword(u_short sum, u_short b);
76236118Smdfu_short	in_pseudo(u_int sum, u_int b, u_int c);
77236118Smdfu_short	in_cksum_skip(struct mbuf *m, int len, int skip);
78236118Smdf#endif
79236118Smdf
80236118Smdf#endif /* _MACHINE_IN_CKSUM_H_ */
81236118Smdf