11ebcad57SDoug Rabson /*- 21ebcad57SDoug Rabson * Copyright (c) 1990 The Regents of the University of California. 31ebcad57SDoug Rabson * All rights reserved. 41ebcad57SDoug Rabson * 51ebcad57SDoug Rabson * Redistribution and use in source and binary forms, with or without 61ebcad57SDoug Rabson * modification, are permitted provided that the following conditions 71ebcad57SDoug Rabson * are met: 81ebcad57SDoug Rabson * 1. Redistributions of source code must retain the above copyright 91ebcad57SDoug Rabson * notice, this list of conditions and the following disclaimer. 101ebcad57SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 111ebcad57SDoug Rabson * notice, this list of conditions and the following disclaimer in the 121ebcad57SDoug Rabson * documentation and/or other materials provided with the distribution. 131ebcad57SDoug Rabson * 3. All advertising materials mentioning features or use of this software 141ebcad57SDoug Rabson * must display the following acknowledgement: 151ebcad57SDoug Rabson * This product includes software developed by the University of 161ebcad57SDoug Rabson * California, Berkeley and its contributors. 171ebcad57SDoug Rabson * 4. Neither the name of the University nor the names of its contributors 181ebcad57SDoug Rabson * may be used to endorse or promote products derived from this software 191ebcad57SDoug Rabson * without specific prior written permission. 201ebcad57SDoug Rabson * 211ebcad57SDoug Rabson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221ebcad57SDoug Rabson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231ebcad57SDoug Rabson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241ebcad57SDoug Rabson * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251ebcad57SDoug Rabson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261ebcad57SDoug Rabson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271ebcad57SDoug Rabson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281ebcad57SDoug Rabson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291ebcad57SDoug Rabson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301ebcad57SDoug Rabson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311ebcad57SDoug Rabson * SUCH DAMAGE. 321ebcad57SDoug Rabson * 331ebcad57SDoug Rabson * from tahoe: in_cksum.c 1.2 86/01/05 341ebcad57SDoug Rabson * from: @(#)in_cksum.c 1.3 (Berkeley) 1/19/91 351ebcad57SDoug Rabson * from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp 361ebcad57SDoug Rabson * $FreeBSD$ 371ebcad57SDoug Rabson */ 381ebcad57SDoug Rabson 391ebcad57SDoug Rabson #ifndef _MACHINE_IN_CKSUM_H_ 401ebcad57SDoug Rabson #define _MACHINE_IN_CKSUM_H_ 1 411ebcad57SDoug Rabson 421ebcad57SDoug Rabson #include <sys/cdefs.h> 431ebcad57SDoug Rabson 441ebcad57SDoug Rabson #define in_cksum(m, len) in_cksum_skip(m, len, 0) 451ebcad57SDoug Rabson 461ebcad57SDoug Rabson /* 471ebcad57SDoug Rabson * It it useful to have an Internet checksum routine which is inlineable 481ebcad57SDoug Rabson * and optimized specifically for the task of computing IP header checksums 491ebcad57SDoug Rabson * in the normal case (where there are no options and the header length is 501ebcad57SDoug Rabson * therefore always exactly five 32-bit words. 511ebcad57SDoug Rabson */ 521ebcad57SDoug Rabson #ifdef __GNUC__ 531ebcad57SDoug Rabson 541ebcad57SDoug Rabson static __inline void 551ebcad57SDoug Rabson in_cksum_update(struct ip *ip) 561ebcad57SDoug Rabson { 571ebcad57SDoug Rabson int __tmpsum; 581ebcad57SDoug Rabson __tmpsum = (int)ntohs(ip->ip_sum) + 256; 591ebcad57SDoug Rabson ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); 601ebcad57SDoug Rabson } 611ebcad57SDoug Rabson 621ebcad57SDoug Rabson #else 631ebcad57SDoug Rabson 641ebcad57SDoug Rabson #define in_cksum_update(ip) \ 651ebcad57SDoug Rabson do { \ 661ebcad57SDoug Rabson int __tmpsum; \ 671ebcad57SDoug Rabson __tmpsum = (int)ntohs(ip->ip_sum) + 256; \ 681ebcad57SDoug Rabson ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); \ 691ebcad57SDoug Rabson } while(0) 701ebcad57SDoug Rabson 711ebcad57SDoug Rabson #endif 721ebcad57SDoug Rabson 731ebcad57SDoug Rabson #ifdef _KERNEL 741ebcad57SDoug Rabson u_int in_cksum_hdr(const struct ip *ip); 751ebcad57SDoug Rabson u_short in_addword(u_short sum, u_short b); 761ebcad57SDoug Rabson u_short in_pseudo(u_int sum, u_int b, u_int c); 771ebcad57SDoug Rabson u_short in_cksum_skip(struct mbuf *m, int len, int skip); 781ebcad57SDoug Rabson #endif 791ebcad57SDoug Rabson 801ebcad57SDoug Rabson #endif /* _MACHINE_IN_CKSUM_H_ */ 81