00001 // 00002 // Copyright (C) 2005 Christian Dankbar, Irene Ruengeler, Michael Tuexen 00003 // 2009 Zoltan Bojthe 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #ifndef __TCPIPCHECKSUM_H 00020 #define __TCPIPCHECKSUM_H 00021 00022 00023 #include "TCPSegment.h" 00024 #include "TCPSegment_m.h" 00025 #include "IPvXAddress.h" 00026 00027 #include "headers/defs.h" 00028 00029 #include "headers/tcp.h" 00030 00034 class TCPIPchecksum 00035 { 00036 public: 00037 TCPIPchecksum() {} 00038 00039 /* 00040 * calculate the 16 bit one's complement of the one's 00041 * complement sum of all 16 bit words in the header and text. If a 00042 * segment contains an odd number of header and text octets to be 00043 * checksummed, the last octet is padded on the right with zeros to 00044 * form a 16 bit word for checksum purposes 00045 */ 00046 static uint16_t checksum(const void *addr, unsigned int count) 00047 { 00048 return ~ _checksum(addr, count); 00049 } 00050 00051 static uint16_t _checksum(const void *addr, unsigned int count); 00052 }; 00053 00054 #endif