4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Philipp Batroff <pug@berlios.de>
29 \brief ICMPv6Packet non-inline non-template implementation */
31 #include "ICMPv6Packet.hh"
32 //#include "ICMPv6Packet.ih"
35 #include <boost/io/ios_state.hpp>
36 #include <senf/Packets/DefaultBundle/IPv6Packet.hh>
37 #include <senf/Utils/IpChecksum.hh>
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43 SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 58, senf::ICMPv6Packet);
45 prefix_ boost::uint16_t senf::ICMPv6PacketParser::calcChecksum()
48 IPv6Packet ipv6 (packet().rfind<IPv6Packet>(senf::nothrow));
49 if (! ipv6) return 0u;
53 //-/////////////////////////////////////////////////////////////////////////////////////////////
55 summer.feed( ipv6->source().i(),
56 ipv6->source().i() + IPv6Packet::Parser::source_t::fixed_bytes );
57 // need support for HopByHop routing header -> the destination used here must be the *final*
59 summer.feed( ipv6->destination().i(),
60 ipv6->destination().i() + IPv6PacketParser::destination_t::fixed_bytes );
62 boost::uint32_t size (data().size());
63 summer.feed((size>>24)&0xff);
64 summer.feed((size>>16)&0xff);
65 summer.feed((size>> 8)&0xff);
66 summer.feed((size )&0xff);
73 //-/////////////////////////////////////////////////////////////////////////////////////////////
75 summer.feed( i(), i()+checksum_offset );
77 // summer.feed(0); summer.feed(0);
78 summer.feed( i()+checksum_offset+2, data().end() );
80 boost::uint16_t rv (summer.sum());
81 return rv ? rv : 0xffffu;
84 prefix_ void senf::ICMPv6PacketType::dump(packet p, std::ostream & os)
86 boost::io::ios_all_saver ias(os);
87 os << "ICMPv6 protocol:\n"
88 << senf::fieldName("type") << unsigned(p->type()) << "\n"
89 << senf::fieldName("code") << unsigned(p->code()) << "\n"
90 << senf::fieldName("checksum")
91 << "0x" << std::hex << std::setw(4) << unsigned(p->checksum()) << "\n";
94 //-/////////////////////////////////////////////////////////////////////////////////////////////////
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u test"
105 // comment-column: 40