4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief IpChecksum public header */
26 #ifndef HH_SENF_Utils_IpChecksum_
27 #define HH_SENF_Utils_IpChecksum_ 1
30 #include <boost/cstdint.hpp>
32 //#include "IpChecksum.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
37 /** \brief Calculate TCP/IP 16bit checksum value
39 This class allows calculation of the 16bit checksum value as defined in the TCP/IP v4
40 RFC's. This checksum is \e not a CRC.
42 To calculate the checksum, you create an instance of IpChecksum. You then repeatedly call
43 the feed() members to pass data in. After all data has been processed, the sum() member will
44 return the calculated checksum.
46 The mathematical properties of the checksum allow to skip any \e even number of zero bytes
47 without changing the checksum value.
52 ///////////////////////////////////////////////////////////////////////////
55 ///////////////////////////////////////////////////////////////////////////
56 ///\name Structors and default members
62 ///////////////////////////////////////////////////////////////////////////
64 void feed(boost::uint8_t byte); ///< Feed single byte
66 template <class InputIterator>
67 void feed(InputIterator b, InputIterator e);
68 ///< Feed range of bytes
70 boost::uint16_t sum() const; ///< Calculate checksum
82 ///////////////////////////////hh.e////////////////////////////////////////
83 #include "IpChecksum.cci"
84 //#include "IpChecksum.ct"
85 #include "IpChecksum.cti"
93 // c-file-style: "senf"
94 // indent-tabs-mode: nil
95 // ispell-local-dictionary: "american"
96 // compile-command: "scons -u test"