in_cksum.h revision 143063
199040Sbenno/*- 299040Sbenno * Copyright (c) 1990 The Regents of the University of California. 399040Sbenno * All rights reserved. 499040Sbenno * 599040Sbenno * Redistribution and use in source and binary forms, with or without 699040Sbenno * modification, are permitted provided that the following conditions 799040Sbenno * are met: 899040Sbenno * 1. Redistributions of source code must retain the above copyright 999040Sbenno * notice, this list of conditions and the following disclaimer. 1099040Sbenno * 2. Redistributions in binary form must reproduce the above copyright 1199040Sbenno * notice, this list of conditions and the following disclaimer in the 1299040Sbenno * documentation and/or other materials provided with the distribution. 1399040Sbenno * 4. Neither the name of the University nor the names of its contributors 1499040Sbenno * may be used to endorse or promote products derived from this software 1599040Sbenno * without specific prior written permission. 1699040Sbenno * 1799040Sbenno * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1899040Sbenno * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1999040Sbenno * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2099040Sbenno * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2199040Sbenno * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2299040Sbenno * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2399040Sbenno * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2499040Sbenno * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2599040Sbenno * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2699040Sbenno * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2799040Sbenno * SUCH DAMAGE. 2899040Sbenno * 2999040Sbenno * from tahoe: in_cksum.c 1.2 86/01/05 3099040Sbenno * from: @(#)in_cksum.c 1.3 (Berkeley) 1/19/91 3199040Sbenno * from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp 3299040Sbenno * $FreeBSD: head/sys/powerpc/include/in_cksum.h 143063 2005-03-02 21:33:29Z joerg $ 3399040Sbenno */ 3499040Sbenno 3599040Sbenno#ifndef _MACHINE_IN_CKSUM_H_ 3699040Sbenno#define _MACHINE_IN_CKSUM_H_ 1 3799040Sbenno 3899040Sbenno#include <sys/cdefs.h> 3999040Sbenno 4099040Sbenno#define in_cksum(m, len) in_cksum_skip(m, len, 0) 4199040Sbenno 4299040Sbenno/* 4399040Sbenno * It it useful to have an Internet checksum routine which is inlineable 4499040Sbenno * and optimized specifically for the task of computing IP header checksums 4599040Sbenno * in the normal case (where there are no options and the header length is 4699040Sbenno * therefore always exactly five 32-bit words. 4799040Sbenno */ 48143063Sjoerg#ifdef __CC_SUPPORTS___INLINE 4999040Sbenno 5099040Sbennostatic __inline void 5199040Sbennoin_cksum_update(struct ip *ip) 5299040Sbenno{ 5399040Sbenno int __tmpsum; 5499040Sbenno __tmpsum = (int)ntohs(ip->ip_sum) + 256; 5599040Sbenno ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); 5699040Sbenno} 5799040Sbenno 5899040Sbenno#else 5999040Sbenno 6099040Sbenno#define in_cksum_update(ip) \ 6199040Sbenno do { \ 6299040Sbenno int __tmpsum; \ 6399040Sbenno __tmpsum = (int)ntohs(ip->ip_sum) + 256; \ 6499040Sbenno ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); \ 6599040Sbenno } while(0) 6699040Sbenno 6799040Sbenno#endif 6899040Sbenno 6999040Sbenno#ifdef _KERNEL 7099040Sbennou_int in_cksum_hdr(const struct ip *ip); 7199040Sbennou_short in_addword(u_short sum, u_short b); 7299040Sbennou_short in_pseudo(u_int sum, u_int b, u_int c); 7399040Sbennou_short in_cksum_skip(struct mbuf *m, int len, int skip); 7499040Sbenno#endif 7599040Sbenno 7699040Sbenno#endif /* _MACHINE_IN_CKSUM_H_ */ 77