4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Philipp Batroff <pug@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 ICMPv6Packet non-inline non-template implementation */
26 #include "ICMPv6Packet.hh"
27 //#include "ICMPv6Packet.ih"
30 #include <boost/io/ios_state.hpp>
31 #include <senf/Packets/DefaultBundle/IPv6Packet.hh>
32 #include <senf/Utils/IpChecksum.hh>
35 ///////////////////////////////cc.p////////////////////////////////////////
38 SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 58, senf::ICMPv6Packet);
41 prefix_ boost::uint16_t senf::ICMPv6PacketParser::calcChecksum()
45 senf::IpChecksum summer;
46 senf::IPv6Packet ipv6 (packet().rfind<senf::IPv6Packet>(senf::nothrow));
51 summer.feed( ipv6->source().i(),
52 ipv6->source().i() + senf::IPv6Packet::Parser::source_t::fixed_bytes );
53 // The destination used here must be the *final* destination ...
54 summer.feed( ipv6->destination().i(), ipv6->destination().i() + senf::IPv6PacketParser::destination_t::fixed_bytes );
56 // This is a simplification. The value is really 32bit to support UDP Jumbograms
57 // (RFC2147). However, skipping an even number of 0 bytes does not change the checksum
58 summer.feed( i() + ipv6->length(), i() + ipv6->length() + 2 );
59 // --> http://www.iana.org/assignments/protocol-numbers
60 // need to insert the correct protocol number here, NOT static 17!!
63 // since header are 16 / even 32bit aligned we don't have to care for padding. since IpChecksum
64 // cares for padding at the final summing we don't have to care is the payload is 16nbit-aligned, too.
65 summer.feed( i(), i()+checksum_offset );
66 summer.feed( i()+checksum_offset+2, data().end() );
68 boost::uint16_t rv (summer.sum());
69 return rv ? rv : 0xffffu;
72 prefix_ void senf::ICMPv6PacketType::dump(packet p, std::ostream &os)
74 boost::io::ios_all_saver ias(os);
75 os << "ICMPv6 protocol:\n"
76 << " type : " << (unsigned) p->type() <<"\n"
77 << " code : " << (unsigned) p->code() <<"\n"
78 << " checksum : " << (unsigned) p->checksum() << "\n";
81 ///////////////////////////////cc.e////////////////////////////////////////
88 // c-file-style: "senf"
89 // indent-tabs-mode: nil
90 // ispell-local-dictionary: "american"
91 // compile-command: "scons -u test"