44a43163dc14caa34eab426d707838fda40b778b
[senf.git] / Packets / DefaultBundle / ICMPv6Packet.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Philipp Batroff <pug@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 #ifndef HH_SENF_Packets_DefaultBundle_ICMPv6Packet_
24 #define HH_SENF_Packets_DefaultBundle_ICMPv6Packet_ 1
25
26 // Custom includes
27 #include "../../Packets/Packets.hh"
28 #include "../../Packets/DefaultBundle/IPv6Packet.hh"
29
30 namespace senf 
31 {
32
33     struct ICMPv6PacketParser : public PacketParserBase
34     {
35 #       include SENF_FIXED_PARSER()
36         SENF_PARSER_FIELD ( type,     UInt8Parser  );
37         SENF_PARSER_FIELD ( code,     UInt8Parser  );
38         SENF_PARSER_FIELD ( checksum, UInt16Parser );
39     
40         SENF_PARSER_FINALIZE ( ICMPv6PacketParser );
41         
42         boost::uint16_t calcChecksum() const;
43     };
44     
45     struct ICMPTypes {
46         // ICMP type registry
47         typedef boost::uint16_t key_t;
48     };
49     
50     struct ICMPv6PacketType 
51         : public PacketTypeBase,
52           public PacketTypeMixin<ICMPv6PacketType, ICMPTypes>
53     {
54         typedef PacketTypeMixin<ICMPv6PacketType, ICMPTypes> mixin;
55         typedef ConcretePacket<ICMPv6PacketType> packet;
56         typedef ICMPv6PacketParser parser;
57         
58         using mixin::nextPacketRange;
59         using mixin::nextPacketType;
60         using mixin::init;
61         using mixin::initSize;
62         
63         static void dump(packet p, std::ostream & os);
64         
65         static IpTypes::key_t nextPacketKey(packet p) { 
66             return p->type();
67         }
68         
69         static void finalize(packet p) {
70             p->checksum() << p->calcChecksum();
71             p->type() << key(p.next(senf::nothrow));
72         }
73     };
74     
75     typedef ConcretePacket<ICMPv6PacketType> ICMPv6Packet;
76 }
77
78 #endif