added TCPPacket implemented by Dennis.
tho [Mon, 27 Jul 2009 15:23:25 +0000 (15:23 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1281 270642c3-0616-0410-b53a-bc976706d245

Packets/DefaultBundle/TCPPacket.cc [new file with mode: 0644]
Packets/DefaultBundle/TCPPacket.hh [new file with mode: 0644]
Packets/DefaultBundle/TCPPacket.test.cc [new file with mode: 0644]
Packets/DefaultBundle/UDPPacket.cc
Packets/DefaultBundle/UDPPacket.test.cc

diff --git a/Packets/DefaultBundle/TCPPacket.cc b/Packets/DefaultBundle/TCPPacket.cc
new file mode 100644 (file)
index 0000000..fb10044
--- /dev/null
@@ -0,0 +1,152 @@
+// $Id$
+//
+// Copyright (C) 2009
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//        Dennis Goslar <dennis.goslar@inf.hochschule-bonn-rhein-sieg.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+/** \file
+    \brief TCPPacket non-inline non-template implementation */
+
+#include "TCPPacket.hh"
+//#include "TCPPacket.ih"
+
+// Custom includes
+#include <iomanip>
+#include <boost/io/ios_state.hpp>
+#include "../../Packets/Packets.hh"
+#include "../../Utils/IpChecksum.hh"
+#include "IPv4Packet.hh"
+#include "IPv6Packet.hh"
+
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+namespace {
+    senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::TCPPacket>
+        registerTCPPacket (6);
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::TCPPacketParser
+
+prefix_ boost::uint16_t senf::TCPPacketParser::calcChecksum()
+    const
+{
+    IpChecksum summer;
+    // first on to the awkward part: the IP pseudo header
+    IPv4Packet ipv4 (packet().rfind<IPv4Packet>(nothrow));
+    if (ipv4) {
+        // Pseudo header defined in RFC793
+        // begin
+        summer.feed( ipv4->source().i(),
+                     ipv4->source().i() + IPv4Packet::Parser::source_t::fixed_bytes );
+        ///\fixme What about a hop-by-hop routing option? Which destination is used in IPv4 ?
+        summer.feed( ipv4->destination().i(),
+                     ipv4->destination().i() + IPv4PacketParser::destination_t::fixed_bytes );
+        // include zero byte
+        summer.feed( 0u );
+        ///\fixme May there be another header between the IPv4 header and TCP? if so, we
+        /// need to hack the correct protocol number here ...
+        summer.feed( 6u );
+
+        // feed 1st byte and 2nd byte from field tcp length
+        summer.feed(boost::uint16_t(data().size()) & 0xff00);
+        summer.feed(boost::uint16_t(data().size()) & 0x00ff);
+        // end pseudo header
+    }
+    else {
+    // Pseudo header defined in RFC2460
+        IPv6Packet ipv6 (packet().rfind<IPv6Packet>(nothrow));
+        if (ipv6) {
+            summer.feed( ipv6->source().i(),
+                         ipv6->source().i() + IPv6Packet::Parser::source_t::fixed_bytes );
+            ///\todo Implement routing header support
+            // The destination used here must be the *final* destination ...
+            summer.feed( ipv6->destination().i(),
+                         ipv6->destination().i() + IPv6PacketParser::destination_t::fixed_bytes );
+            // This is a simplification. The value is really 32bit to support UDP Jumbograms
+            // (RFC2147). However, skipping an even number of 0 bytes does not change the checksum
+            // RFC2460 specifies, that this must always be 6, not the value used in the ipv6
+            // header
+            // feed 1st byte and 2nd byte from field tcp length
+            summer.feed(boost::uint16_t(data().size()) & 0xff00);
+            summer.feed(boost::uint16_t(data().size()) & 0x00ff);
+            // include zero byte
+            summer.feed( 0u );
+            // add TCP protocol number
+            summer.feed( 6u );
+        }
+    }
+
+    // since header are 16 / even 32bit aligned we don't have to care for padding. since IpChecksum
+    // cares for padding at the final summing we don't have to care is the payload is 16nbit-aligned, too.
+
+    // iterate till checksum field and skip 2 bytes,
+    // iterate over rest of tcp header and tcp payload
+    summer.feed( i(), i()+16 );
+    summer.feed( i()+18, data().end() );
+
+    boost::uint16_t rv (summer.sum());
+    return rv ? rv : 0xffffu;
+
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::TCPPacketType
+
+prefix_ void senf::TCPPacketType::dump(packet p, std::ostream & os)
+{
+    boost::io::ios_all_saver ias(os);
+    os << "TCP:\n"
+       <<     "  source port             : " << p->source() << "\n"
+       <<     "  destination port        : " << p->destination() << "\n"
+       <<     "  sequence number         : " << p->sequencenumber() << "\n"
+       <<     "  acknowledgment number   : " << p->acknowledgmentnumber() << "\n"
+       <<     "  data offset             : " << p->dataoffset() << "\n"
+       <<     "  urgent flag             : " << p->urgf() << "\n"
+       <<     "  ack flag                : " << p->ackf() << "\n"
+       <<     "  push flag               : " << p->pshf() << "\n"
+       <<     "  reset flag              : " << p->rstf() << "\n"
+       <<     "  syn flag                : " << p->synf() << "\n"
+       <<     "  fin flag                : " << p->finf() << "\n"
+       <<     "  window size             : " << p->window() << "\n"
+       <<     "  checksum                : "
+       << std::hex << std::setw(4) << std::setfill('0') << p->checksum() << "\n"
+       <<     "  urgent pointer          : " << p->urgentpointer() << "\n";
+}
+
+prefix_ void senf::TCPPacketType::finalize(packet p)
+{
+    p->dataoffset() << p.size();
+    p->checksum() << p->calcChecksum();
+}
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
diff --git a/Packets/DefaultBundle/TCPPacket.hh b/Packets/DefaultBundle/TCPPacket.hh
new file mode 100644 (file)
index 0000000..2f960b1
--- /dev/null
@@ -0,0 +1,186 @@
+// $Id$
+//
+// Copyright (C) 2009
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//        Dennis Goslar <dennis.goslar@inf.hochschule-bonn-rhein-sieg.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+/** \file
+    \brief TCPPacket public header */
+
+#ifndef HH_SENF_Packets_DefaultBundle_TCPPacket_
+#define HH_SENF_Packets_DefaultBundle_TCPPacket_ 1
+
+// Custom includes
+#include "../../Packets/Packets.hh"
+
+//#include "TCPPacket.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+    /** \brief Parse a TCP packet
+
+        Parser implementing the TCP header. The fields implemented are:
+        \image html TCPPacket.png
+
+        \see TCPPacketType \n
+            <a href="http://tools.ietf.org/html/rfc793">RFC 793</a>
+     */
+    struct TCPPacketParser : public PacketParserBase
+    {
+#       include SENF_PARSER()
+
+       SENF_PARSER_FIELD( source,                              UInt16Parser );
+       SENF_PARSER_FIELD( destination,                 UInt16Parser );
+       SENF_PARSER_FIELD( sequencenumber,              UInt32Parser );
+       SENF_PARSER_FIELD( acknowledgmentnumber,        UInt32Parser );
+
+       SENF_PARSER_BITFIELD        ( dataoffset, 4, unsigned );
+       SENF_PARSER_PRIVATE_BITFIELD( reserved,   6, unsigned );
+       SENF_PARSER_BITFIELD        ( urgf,       1, bool     );
+        SENF_PARSER_BITFIELD        ( ackf,       1, bool     );
+        SENF_PARSER_BITFIELD        ( pshf,       1, bool     );
+        SENF_PARSER_BITFIELD        ( rstf,       1, bool     );
+        SENF_PARSER_BITFIELD        ( synf,       1, bool     );
+        SENF_PARSER_BITFIELD        ( finf,       1, bool     );
+
+        SENF_PARSER_FIELD( window,        UInt16Parser );
+        SENF_PARSER_FIELD( checksum,      UInt16Parser );
+        SENF_PARSER_FIELD( urgentpointer, UInt16Parser );
+
+        // skip option part in TCP-Header, dataoffset()*4 = TCP header length in byte
+        // for options see http://www.iana.org/assignments/tcp-parameters/
+        // if dataoffset() < 5 packet is invalid
+        SENF_PARSER_SKIP( (dataoffset() < 5 ? 0 : dataoffset()*4-20), 0);
+
+        SENF_PARSER_FINALIZE(TCPPacketParser);
+
+        SENF_PARSER_INIT() {
+            // Reserved: 6 bits, reserved for future use. Must be zero.
+            // see http://tools.ietf.org/html/rfc793
+            reserved_() = 0;
+            // dataoffset per default 5, 5*4 = 20 Byte Header Length
+            dataoffset() = 5;
+        }
+
+        boost::uint16_t calcChecksum() const; ///< calculate (pseudo-)header checksum
+                                              /**< calculate and return the checksum of the
+                                                   (pseudo-)header \see \ref senf::IpChecksum */
+
+        bool validateChecksum() const {
+            return checksum() == 0u || checksum() == calcChecksum();
+        }                               ///< validate header checksum
+                                        /**< return \c true if the \ref checksum() "checksum"
+                                             field is equal to the \ref calcChecksum() "calculated checksum" */
+    };
+
+    /** \brief TCP packet
+
+        \par Packet type (typedef):
+            \ref TCPPacket
+
+        \par Fields:
+            \ref TCPPacketParser
+
+        <table class="packet" cellpadding="5" cellspacing="1" border="1">
+        <tr>
+            <th width="12%">0</th>
+            <th width="20%">4</th>
+            <th width="3%">10</th>
+            <th width="3%">11</th>
+            <th width="3%">12</th>
+            <th width="3%">13</th>
+            <th width="3%">14</th>
+            <th width="3%">15</th>
+            <th width="25%">16</th>
+            <th style="text-align:right" width="25%">31</th>
+        </tr>
+        <tr>
+            <td colspan="8">\ref TCPPacketParser::source() "Source Port"</td>
+            <td colspan="2">\ref TCPPacketParser::destination() "Destination Port"</td>
+        </tr><tr>
+            <td colspan="10">\ref TCPPacketParser::sequencenumber() "Sequence Number"</td>
+        </tr><tr>
+            <td colspan="10">\ref TCPPacketParser::acknowledgmentnumber() "Acknowledgment Number"</td>
+        </tr><tr>
+            <td colspan="1">\ref TCPPacketParser::dataoffset() "DataOffset"</td>
+            <td colspan="1">Reserved</td>
+            <td colspan="1">\ref TCPPacketParser::urgf() "UR"</td>
+            <td colspan="1">\ref TCPPacketParser::ackf() "AC"</td>
+            <td colspan="1">\ref TCPPacketParser::pshf() "PS"</td>
+            <td colspan="1">\ref TCPPacketParser::rstf() "RS"</td>
+            <td colspan="1">\ref TCPPacketParser::synf() "SY"</td>
+            <td colspan="1">\ref TCPPacketParser::finf() "FI"</td>
+            <td colspan="2">\ref TCPPacketParser::window() "Window Size"</td>
+        </tr><tr>
+            <td colspan="8">\ref TCPPacketParser::checksum() "Checksum"</td>
+            <td colspan="2">\ref TCPPacketParser::urgentpointer() "Urgent Pointer"</td>
+        </tr>
+        </table>
+
+        \par Finalize action:
+            \copydetails finalize()
+
+        \ingroup protocolbundle_default
+     */
+    struct TCPPacketType
+        : public PacketTypeBase,
+          public PacketTypeMixin<TCPPacketType>
+    {
+#ifndef DOXYGEN
+        typedef PacketTypeMixin<TCPPacketType> mixin;
+#endif
+        typedef ConcretePacket<TCPPacketType> packet; ///< TCP packet typedef
+        typedef TCPPacketParser parser;               ///< typedef to the parser of TCP packet
+
+        using mixin::nextPacketRange;
+        using mixin::initSize;
+        using mixin::init;
+
+        /** \brief Dump given TCPPacket in readable form to given output stream */
+        static void dump(packet p, std::ostream & os);
+
+        static void finalize(packet p); ///< Finalize packet.
+                                        /**< \li set \ref TCPPacketParser::dataoffset() "Data Offset" from
+                                               header size
+                                             \li calculate and set \ref TCPPacketParser::checksum()
+                                               "checksum" */
+    };
+
+    /** \brief TCP packet typedef */
+    typedef ConcretePacket<TCPPacketType> TCPPacket;
+}
+
+
+///////////////////////////////hh.e////////////////////////////////////////
+//#include "TCPPacket.cci"
+//#include "TCPPacket.ct"
+//#include "TCPPacket.cti"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
diff --git a/Packets/DefaultBundle/TCPPacket.test.cc b/Packets/DefaultBundle/TCPPacket.test.cc
new file mode 100644 (file)
index 0000000..70ada0c
--- /dev/null
@@ -0,0 +1,189 @@
+// $Id$
+//
+// Copyright (C) 2009
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//        Dennis Goslar <dennis.goslar@inf.hochschule-bonn-rhein-sieg.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+/** \file
+    \brief TCPPacket unit tests */
+
+//#include "TCPPacket.test.hh"
+//#include "TCPPacket.test.ih"
+
+// Custom includes
+#include "TCPPacket.hh"
+#include "IPv4Packet.hh"
+#include "IPv6Packet.hh"
+
+#include "../../Utils/auto_unit_test.hh"
+#include <boost/test/test_tools.hpp>
+
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+BOOST_AUTO_UNIT_TEST(tcpPacket_parse)
+{
+
+    unsigned char data[] = {
+            0x80, 0xA6, 0x00, 0x50, 0x2E, 0x93, 0x31, 0xB8, 0x66, 0xF9, 0xB7,
+            0xA1, 0x80, 0x18, 0x00, 0x2E, 0xCF, 0x65, 0x00, 0x00
+    };
+
+    senf::TCPPacket p (senf::TCPPacket::create(data));
+
+    BOOST_CHECK_EQUAL( p->source(),               0x80A6u       );
+    BOOST_CHECK_EQUAL( p->destination(),          0x0050u       );
+    BOOST_CHECK_EQUAL( p->sequencenumber(),       0x2E9331B8u   );
+    BOOST_CHECK_EQUAL( p->acknowledgmentnumber(), 0x66F9B7A1u   );
+    BOOST_CHECK_EQUAL( p->dataoffset(),           0x8u          );
+    BOOST_CHECK_EQUAL( p->urgf(),                 0u            );
+    BOOST_CHECK_EQUAL( p->ackf(),                 1u            );
+    BOOST_CHECK_EQUAL( p->pshf(),                 1u            );
+    BOOST_CHECK_EQUAL( p->rstf(),                 0u            );
+    BOOST_CHECK_EQUAL( p->synf(),                 0u            );
+    BOOST_CHECK_EQUAL( p->finf(),                 0u            );
+    BOOST_CHECK_EQUAL( p->window(),               0x002Eu       );
+    BOOST_CHECK_EQUAL( p->checksum(),             0xCF65u       );
+    BOOST_CHECK_EQUAL( p->urgentpointer(),        0x0000u       );
+
+    std::ostringstream oss (std::ostringstream::out);
+    SENF_CHECK_NO_THROW( p.dump( oss));
+}
+
+BOOST_AUTO_UNIT_TEST(tcpPacket_in_ipv4_parse)
+{
+    unsigned char data[] = {
+            //20 Byte IPv4-Header
+            0x45, 0x00, 0x00, 0xb2, 0x0f, 0x4d, 0x40, 0x00, 0x0f9, 0x06, 0xa0,
+            0xa1, 0xc1, 0x63, 0x90, 0x55, 0x0a, 0x14, 0x75, 0x8a,
+
+            //20 Byte TCP-Header + 12 Byte Options
+            0x00, 0x50, 0xc3, 0xbf, 0xe2, 0xf7, 0x49, 0xf3, 0x3e, 0x4f, 0x8a,
+            0xbe, 0x80, 0x18, 0x13, 0x24, 0x2e, 0x33, 0x00, 0x00, 0x01, 0x01,
+            0x08, 0x0a, 0x0f, 0xf1, 0xa7, 0x6b, 0x00, 0x59, 0xf4, 0x75,
+
+            //TCP-Payload
+            0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, 0x33, 0x30,
+            0x34, 0x20, 0x4e, 0x6f, 0x74, 0x20, 0x4d, 0x6f, 0x64, 0x69, 0x66,
+            0x69, 0x65, 0x64, 0x0d, 0x0a, 0x44, 0x61, 0x74, 0x65, 0x3a, 0x20,
+            0x54, 0x68, 0x75, 0x2c, 0x20, 0x32, 0x33, 0x20, 0x4a, 0x75, 0x6c,
+            0x20, 0x32, 0x30, 0x30, 0x39, 0x20, 0x31, 0x35, 0x3a, 0x31, 0x35,
+            0x3a, 0x31, 0x39, 0x20, 0x47, 0x4d, 0x54, 0x0d, 0x0a, 0x53, 0x65,
+            0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x41, 0x70, 0x61, 0x63, 0x68,
+            0x65, 0x2f, 0x32, 0x2e, 0x32, 0x2e, 0x31, 0x31, 0x0d, 0x0a, 0x43,
+            0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20,
+            0x63, 0x6c, 0x6f, 0x73, 0x65, 0x0d, 0x0a, 0x56, 0x61, 0x72, 0x79,
+            0x3a, 0x20, 0x55, 0x73, 0x65, 0x72, 0x2d, 0x41, 0x67, 0x65, 0x6e,
+            0x74, 0x0d, 0x0a, 0x0d, 0x0a
+    };
+
+    senf::IPv4Packet ip (senf::IPv4Packet::create(data));
+    senf::TCPPacket tcp (ip.next<senf::TCPPacket>());
+
+    BOOST_CHECK( tcp->validateChecksum() );
+}
+
+
+BOOST_AUTO_UNIT_TEST(tcpPacket_in_ipv6_parse)
+{
+    unsigned char data[] = {
+            // IPv6-Header
+            0x60, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x06, 0x39, 0x20, 0x01, 0x48,
+            0x60, 0xa0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x68, 0x20, 0x01, 0x06, 0x38, 0x04, 0x08, 0x02, 0x01, 0xef,
+            0xdc, 0x71, 0x52, 0x17, 0x2c, 0x44, 0x3e,
+        
+            // 20 Byte TCP-Header without Options
+            0x00, 0x50, 0xac, 0x3e, 0x82, 0x99, 0x60, 0xa6, 0xa4, 0xfa, 0x32,
+            0x83, 0x50, 0x18, 0x19, 0x20, 0xd7, 0xcd, 0x00, 0x00,
+        
+            // TCP-Payload
+            0x1a, 0x01, 0x52, 0x0e, 0x26, 0x6f, 0xac, 0xd9, 0x78, 0x0c, 0x3c,
+            0x69, 0x3c, 0xa6, 0x49, 0xc6, 0x85, 0xc2, 0xa9, 0x72, 0x75, 0x9a,
+            0xef, 0x63, 0x46, 0xa3, 0xd4, 0x11, 0xda, 0x04, 0x95, 0x55,0x7b,
+            0xb5, 0x6c, 0xcb, 0x52, 0xfb, 0xa0, 0x7a, 0x03, 0xd5, 0x98, 0x75,
+            0x8b, 0x53, 0xfc, 0x23, 0x21, 0x01, 0xc5, 0x06, 0x66, 0x6c, 0x0d,
+            0x06, 0x1d, 0x69, 0x2f, 0xec, 0xb7, 0x7d, 0xe3, 0xd6, 0x71, 0x23,
+            0xaa, 0x58, 0x3b, 0x80, 0x58, 0x5b, 0x10, 0xa1, 0xa8, 0x8f, 0x59,
+            0x3d, 0x3d, 0x80, 0xd6, 0x2e, 0x0d, 0x21, 0x33, 0x2b, 0x47, 0x5b,
+            0xb2, 0xd0, 0xde, 0x19, 0xaf, 0x03, 0x2a, 0x33,0x86, 0x57, 0x8e,
+            0x07, 0xf9, 0x6e, 0xde, 0x68, 0xe1, 0xd8, 0x63, 0x92, 0x18, 0x1a,
+            0xa9, 0xc0, 0xe5, 0x94, 0xba, 0x1d, 0x97, 0xed, 0x7e, 0x2b, 0xa8,
+            0xda, 0x4a, 0x96, 0x0c, 0xe5, 0x78, 0xb9, 0xec, 0x80, 0xf8, 0x5c,
+            0x94, 0xf9, 0xd3, 0x49, 0x79, 0x4a, 0x4a, 0x98, 0xb1, 0x13, 0x73,
+            0x50, 0x6c
+    };
+
+    senf::IPv6Packet ip (senf::IPv6Packet::create(data));
+    senf::TCPPacket tcp (ip.next<senf::TCPPacket>());
+
+    BOOST_CHECK( tcp->validateChecksum() );
+}
+
+BOOST_AUTO_UNIT_TEST(tcpPacket_in_ipv6_create)
+{
+    unsigned char data[] = {
+            // IPv6-Header
+            0x60, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x06, 0x40,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+        
+            // TCP-Header + TCP-Payload
+            0x5b, 0xa0, 0x30, 0x39, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00,
+            0x18, 0x80, 0x00, 0x00, 0x54, 0x45, 0x53, 0x54,
+            0x2d, 0x57, 0x52, 0x49, 0x54, 0x45
+    };
+
+    senf::IPv6Packet ip (senf::IPv6Packet::create());
+    ip->source() = senf::INet6Address::Loopback;
+    ip->destination() = senf::INet6Address::Loopback;
+    ip->hopLimit() = 64;
+
+    senf::TCPPacket tcp (senf::TCPPacket::createAfter(ip));
+    tcp->source() = 23456;
+    tcp->destination() = 12345;
+
+    senf::DataPacket::createAfter(tcp, std::string("TEST-WRITE"));
+
+    // validates, since the checksum is 0 and thus ignored !
+    BOOST_CHECK( tcp->validateChecksum() );
+
+    ip.finalizeAll();
+
+    BOOST_CHECK_EQUAL_COLLECTIONS(
+            data, data+sizeof(data), ip.data().begin(), ip.data().end() );
+    BOOST_CHECK( tcp->validateChecksum() );
+}
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
index 57db0cc..a985f24 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "UDPPacket.hh"
 //#include "UDPPacket.ih"
-#include "IPv4Packet.hh"
 
 // Custom includes
 #include <iomanip>
@@ -105,7 +104,7 @@ prefix_ void senf::UDPPacketType::dump(packet p, std::ostream & os)
        <<     "  dest port               : " << p->destination() << "\n"
        <<     "  length                  : " << p->length() << "\n"
        <<     "  checksum                : " 
-         << std::hex << std::setw(4) << std::setfill('0') << p->checksum() << "\n";
+       << std::hex << std::setw(4) << std::setfill('0') << p->checksum() << "\n";
 }
 
 prefix_ void senf::UDPPacketType::finalize(packet p)
index cec4ec1..ad47d32 100644 (file)
@@ -55,7 +55,7 @@ BOOST_AUTO_UNIT_TEST(udpPacket_parse)
     SENF_CHECK_NO_THROW( p.dump( oss));
 }
 
-BOOST_AUTO_UNIT_TEST(udpPacket_in_ipv6_create)
+BOOST_AUTO_UNIT_TEST(udpPacket_in_ipv4_create)
 {
     unsigned char data[] = { 
             0x45, 0x00, 0x00, 0x26, 0x00, 0x00, 0x40, 0x00,