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