Packets: BUGFIX: ensure complete interpreter chain in finalize()
[senf.git] / Packets / DefaultBundle / IpV4Packet.hh
1 // $Id: IpV4Packet.hh 307 2007-07-14 21:31:12Z g0dil $
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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_IpV4Packet_
24 #define HH_IpV4Packet_ 1
25
26 // Custom includes
27 #include "Packets/PacketType.hh"
28 #include "Packets/ParseInt.hh"
29 #include "Packets/PacketRegistry.hh"
30 #include "Packets/PacketParser.hh"
31
32 //#include "IpV4Packet.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36
37     ///\addtogroup protocolbundle_default
38     ///@{
39
40     struct Parse_IpV4 : public PacketParserBase
41     {
42         SENF_PACKET_PARSER_NO_INIT(Parse_IpV4);
43
44         ///////////////////////////////////////////////////////////////////////////
45
46         typedef Parse_UIntField <  0,  4 > Parse_Version;
47         typedef Parse_UIntField <  4,  8 > Parse_IHL;
48         typedef Parse_UInt8                Parse_8bit;
49         typedef Parse_UInt16               Parse_16bit;
50         typedef Parse_Flag      <  0     > Parse_R;
51         typedef Parse_Flag      <  1     > Parse_DF;
52         typedef Parse_Flag      <  2     > Parse_MF;
53         typedef Parse_UIntField <  3, 16 > Parse_Frag;
54         typedef Parse_UInt32               Parse_32bit;
55
56         SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
57             ((OverlayField)( version,     Parse_Version ))
58             ((Field       )( ihl,         Parse_IHL     ))
59             ((Field       )( tos,         Parse_8bit    ))
60             ((Field       )( length,      Parse_16bit   ))
61             ((Field       )( identifier,  Parse_16bit   ))
62             ((OverlayField)( reserved,    Parse_R       ))
63             ((OverlayField)( df,          Parse_DF      ))
64             ((OverlayField)( mf,          Parse_MF      ))
65             ((Field       )( frag,        Parse_Frag    ))
66             ((Field       )( ttl,         Parse_8bit    ))
67             ((Field       )( protocol,    Parse_8bit    ))
68             ((Field       )( crc,         Parse_16bit   ))
69             ((Field       )( source,      Parse_32bit   ))
70             ((Field       )( destination, Parse_32bit   )) );
71
72         void init() {
73             version() = 4;
74         }
75     };
76
77     struct IpTypes {
78         // See http://www.iana.org/assignments/protocol-numbers
79         // Also used by IPv6
80         typedef boost::uint16_t key_t;
81     };
82
83     struct IpV4PacketType
84         : public PacketTypeBase,
85           public PacketTypeMixin<IpV4PacketType, IpTypes>
86     {
87         typedef PacketTypeMixin<IpV4PacketType, IpTypes> mixin;
88         typedef ConcretePacket<IpV4PacketType> packet;
89         typedef Parse_IpV4 parser;
90
91         using mixin::nextPacketRange;
92         using mixin::nextPacketType;
93         using mixin::initSize;
94         using mixin::init;
95
96         static registry_key_t nextPacketKey(packet p) 
97             { return p->protocol(); }
98
99         static void dump(packet p, std::ostream & os);
100     };
101         
102     typedef IpV4PacketType::packet IpV4Packet;
103
104     ///@}
105 }
106
107
108 ///////////////////////////////hh.e////////////////////////////////////////
109 //#include IpV4Packet.cci"
110 //#include "IpV4Packet.ct"
111 //#include "IpV4Packet.cti"
112 #endif
113
114 \f
115 // Local Variables:
116 // mode: c++
117 // fill-column: 100
118 // c-file-style: "senf"
119 // indent-tabs-mode: nil
120 // ispell-local-dictionary: "american"
121 // compile-command: "scons -u test"
122 // comment-column: 40
123 // End: