2 // Fraunhofer Institute for Open Communication Systems (FOKUS)
3 // Competence Center NETwork research (NET), St. Augustin, GERMANY
4 // Philipp Batroff <Philipp.Batroff@fokus.fraunhofer.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "../../Packets/Packets.hh"
23 #include "ICMPv6Packet.hh"
24 #include <boost/io/ios_state.hpp>
25 #include "../../Packets/DefaultBundle/IPv6Packet.hh"
26 #include "../../Utils/IpChecksum.hh"
31 senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::ICMPv6Packet>
32 registerICMPv6Packet (58);
35 prefix_ void senf::ICMPV6PacketParser::calcChecksum() const {
37 senf::IpChecksum summer;
38 senf::IPv6Packet ipv6 (packet().rfind<senf::IPv6Packet>(senf::nothrow));
40 summer.feed( ipv6->source().i(),
41 ipv6->source().i() + senf::IPv6Packet::Parser::source_t::fixed_bytes );
42 // The destination used here must be the *final* destination ...
43 summer.feed( ipv6->destination().i(), ipv6->destination().i() + senf::IPv6PacketParser::destination_t::fixed_bytes );
45 // This is a simplification. The value is really 32bit to support UDP Jumbograms
46 // (RFC2147). However, skipping an even number of 0 bytes does not change the checksum
47 summer.feed( i() + ipv6->length(), i() + ipv6->length() + 2 );
48 // --> http://www.iana.org/assignments/protocol-numbers
49 // need to insert the correct protocol number here, NOT static 17!!
52 // since header are 16 / even 32bit aligned we don't have to care for padding. since IpChecksum
53 // cares for padding at the final summing we don't have to care is the payload is 16nbit-aligned, too.
54 summer.feed( i(), i()+checksum_offset );
55 summer.feed( i()+checksum_offset+2, data().end() );
57 boost::uint16_t rv (summer.sum());
58 this->checksum() << (rv ? rv : 0xffffu);
61 prefix_ void senf::ICMPV6PacketType::dump(packet p, std::ostream &os)
63 boost::io::ios_all_saver ias(os);
64 os << "ICMPv6 protocol:\n"
65 << "Type : " << p->type() <<"\n"
66 << "Code : " << p->code() <<"\n"
67 << "Checksum : " << p->checksumOutput() << "\n";