switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / DefaultBundle / ICMPv6Packet.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
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
10 //
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.
14 //
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.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
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.
24 //
25 // Contributor(s):
26 //   Philipp Batroff <pug@berlios.de>
27
28 /** \file
29     \brief ICMPv6Packet public header */
30
31 #ifndef HH_SENF_Packets_DefaultBundle_ICMPv6Packet_
32 #define HH_SENF_Packets_DefaultBundle_ICMPv6Packet_ 1
33
34 // Custom includes
35 #include <senf/Packets/Packets.hh>
36
37 //#include "ICMPv6Packet.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 namespace senf
40 {
41     struct ICMPv6PacketParser : public PacketParserBase
42     {
43 #       include SENF_FIXED_PARSER()
44         SENF_PARSER_FIELD ( type,     UInt8Parser  );
45         SENF_PARSER_FIELD ( code,     UInt8Parser  );
46         SENF_PARSER_FIELD ( checksum, UInt16Parser );
47
48         SENF_PARSER_FINALIZE ( ICMPv6PacketParser );
49
50         boost::uint16_t calcChecksum() const;
51     };
52
53     struct ICMPTypes {
54         // ICMP type registry
55         typedef boost::uint8_t key_t;
56     };
57
58     /** \brief ICMP Packet for IPv6
59
60         \par Packet type (typedef):
61             \ref ICMPv6Packet
62
63         \par Fields:
64             \ref ICMPv6PacketParser
65             \image html ICMPv6Packet.png
66
67         \par Associated registries:
68             \ref ICMPTypes
69
70         \ingroup protocolbundle_default
71      */
72     struct ICMPv6PacketType
73         : public PacketTypeBase,
74           public PacketTypeMixin<ICMPv6PacketType, ICMPTypes>
75     {
76         typedef PacketTypeMixin<ICMPv6PacketType, ICMPTypes> mixin;
77         typedef ConcretePacket<ICMPv6PacketType> packet;
78         typedef ICMPv6PacketParser parser;
79
80         using mixin::nextPacketRange;
81         using mixin::nextPacketType;
82         using mixin::init;
83         using mixin::initSize;
84
85         static void dump(packet p, std::ostream & os);
86
87         static key_t nextPacketKey(packet p) {
88             return p->type();
89         }
90
91         static void finalize(packet p) {
92             p->type() << key(p.next(senf::nothrow));
93             p->checksum() << p->calcChecksum();
94         }
95     };
96
97     /** \brief ICMPv6 packet typedef
98         \ingroup protocolbundle_default
99      */
100     typedef ConcretePacket<ICMPv6PacketType> ICMPv6Packet;
101 }
102
103 //-/////////////////////////////////////////////////////////////////////////////////////////////////
104 //#include "IPv4Packet.cci"
105 //#include "IPv4Packet.ct"
106 //#include "IPv4Packet.cti"
107 #endif
108
109 \f
110 // Local Variables:
111 // mode: c++
112 // fill-column: 100
113 // c-file-style: "senf"
114 // indent-tabs-mode: nil
115 // ispell-local-dictionary: "american"
116 // compile-command: "scons -u test"
117 // comment-column: 40
118 // End:
119