00001 // $Id: ICMPv6Packet.cc 1772 2011-03-10 12:45:21Z tho $ 00002 // 00003 // Copyright (C) 2008 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Philipp Batroff <pug@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00026 #include "ICMPv6Packet.hh" 00027 //#include "ICMPv6Packet.ih" 00028 00029 // Custom includes 00030 #include <boost/io/ios_state.hpp> 00031 #include <senf/Packets/DefaultBundle/IPv6Packet.hh> 00032 #include <senf/Utils/IpChecksum.hh> 00033 #include <iomanip> 00034 00035 #define prefix_ 00036 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00037 00038 SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 58, senf::ICMPv6Packet); 00039 00040 prefix_ boost::uint16_t senf::ICMPv6PacketParser::calcChecksum() 00041 const 00042 { 00043 IPv6Packet ipv6 (packet().rfind<IPv6Packet>(senf::nothrow)); 00044 if (! ipv6) return 0u; 00045 00046 IpChecksum summer; 00047 00048 //-///////////////////////////////////////////////////////////////////////////////////////////// 00049 // IPv6 pseudo header 00050 summer.feed( ipv6->source().i(), 00051 ipv6->source().i() + IPv6Packet::Parser::source_t::fixed_bytes ); 00052 // need support for HopByHop routing header -> the destination used here must be the *final* 00053 // destination ... 00054 summer.feed( ipv6->destination().i(), 00055 ipv6->destination().i() + IPv6PacketParser::destination_t::fixed_bytes ); 00056 // packet length 00057 boost::uint32_t size (data().size()); 00058 summer.feed((size>>24)&0xff); 00059 summer.feed((size>>16)&0xff); 00060 summer.feed((size>> 8)&0xff); 00061 summer.feed((size )&0xff); 00062 // protocol number 00063 // summer.feed( 0u ); 00064 // summer.feed( 0u ); 00065 summer.feed( 0u ); 00066 summer.feed( 58u ); 00067 00068 //-///////////////////////////////////////////////////////////////////////////////////////////// 00069 // ICMP Packet 00070 summer.feed( i(), i()+checksum_offset ); 00071 // checksum 00072 // summer.feed(0); summer.feed(0); 00073 summer.feed( i()+checksum_offset+2, data().end() ); 00074 00075 boost::uint16_t rv (summer.sum()); 00076 return rv ? rv : 0xffffu; 00077 } 00078 00079 prefix_ void senf::ICMPv6PacketType::dump(packet p, std::ostream & os) 00080 { 00081 boost::io::ios_all_saver ias(os); 00082 os << "ICMPv6 protocol:\n" 00083 << senf::fieldName("type") << unsigned(p->type()) << "\n" 00084 << senf::fieldName("code") << unsigned(p->code()) << "\n" 00085 << senf::fieldName("checksum") 00086 << "0x" << std::hex << std::setw(4) << unsigned(p->checksum()) << "\n"; 00087 } 00088 00089 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00090 #undef prefix_ 00091 00092 00093 // Local Variables: 00094 // mode: c++ 00095 // fill-column: 100 00096 // c-file-style: "senf" 00097 // indent-tabs-mode: nil 00098 // ispell-local-dictionary: "american" 00099 // compile-command: "scons -u test" 00100 // comment-column: 40 00101 // End: