7fca40ee43e72a8eca2122248c2407c86ee12a66
[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 /** \file
24     \brief IpV4Packet public header */
25
26 #ifndef HH_IpV4Packet_
27 #define HH_IpV4Packet_ 1
28
29 // Custom includes
30 #include "Packets/Packets.hh"
31
32 //#include "IpV4Packet.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36
37     /** \brief Parse an IpV4 packet
38
39         Parser implementing the IpV4 header. The fields implemented are:
40
41         \see IpV4PacketType \n
42             <a href="http://tools.ietf.org/html/rfc791">RFC 791</a>
43
44         \todo Implement options
45      */
46     struct Parse_IpV4 : public PacketParserBase
47     {
48         typedef Parse_UIntField <  0,  4 > Parse_Version;
49         typedef Parse_UIntField <  4,  8 > Parse_IHL;
50         typedef Parse_UInt8                Parse_8bit;
51         typedef Parse_UInt16               Parse_16bit;
52         typedef Parse_Flag      <  0     > Parse_R;
53         typedef Parse_Flag      <  1     > Parse_DF;
54         typedef Parse_Flag      <  2     > Parse_MF;
55         typedef Parse_UIntField <  3, 16 > Parse_Frag;
56         typedef Parse_UInt32               Parse_32bit;
57
58 #       ifndef DOXYGEN
59
60         SENF_PACKET_PARSER_NO_INIT(Parse_IpV4);
61
62         SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
63             ((OverlayField)( version,     Parse_Version ))
64             ((Field       )( ihl,         Parse_IHL     ))
65             ((Field       )( tos,         Parse_8bit    ))
66             ((Field       )( length,      Parse_16bit   ))
67             ((Field       )( identifier,  Parse_16bit   ))
68             ((OverlayField)( reserved,    Parse_R       ))
69             ((OverlayField)( df,          Parse_DF      ))
70             ((OverlayField)( mf,          Parse_MF      ))
71             ((Field       )( frag,        Parse_Frag    ))
72             ((Field       )( ttl,         Parse_8bit    ))
73             ((Field       )( protocol,    Parse_8bit    ))
74             ((Field       )( crc,         Parse_16bit   ))
75             ((Field       )( source,      Parse_32bit   ))
76             ((Field       )( destination, Parse_32bit   )) );
77
78 #       else
79
80         Parse_Version version() const;
81         Parse_IHL     ihl() const;
82         Parse_8bit    tos() const;
83         Parse_16bit   length() const;
84         Parse_16bit   identifier() const;
85         Parse_R       reserved() const;
86         Parse_DF      df() const;
87         Parse_MF      mf() const;
88         Parse_Frag    frag() const;
89         Parse_8bit    ttl() const;
90         Parse_8bit    protocol() const;
91         Parse_16bit   crc() const;
92         Parse_32bit   source() const;
93         Parse_32bit   destination() const;
94
95 #       endif
96
97         void init() {
98             version() = 4;
99         }
100     };
101
102     /** \brief IP protocol number registry
103
104         This registeres packets with their IP protocol number.
105
106         \see <a href="http://www.iana.org/assignments/protocol-numbers">Protocol numbers</a> \n
107             PacketRegistry
108      */
109     struct IpTypes {
110         typedef boost::uint16_t key_t;
111     };
112
113     /** \brief IpV4 packet
114         
115         \par Packet type (typedef):
116             \ref IpV4Packet
117
118         \par Fields:
119             \ref Parse_IpV4
120
121         \par Associated registries:
122             \ref IpTypes
123
124         \ingroup protocolbundle_default
125      */
126     struct IpV4PacketType
127         : public PacketTypeBase,
128           public PacketTypeMixin<IpV4PacketType, IpTypes>
129     {
130         typedef PacketTypeMixin<IpV4PacketType, IpTypes> mixin;
131         typedef ConcretePacket<IpV4PacketType> packet;
132         typedef Parse_IpV4 parser;
133
134         using mixin::nextPacketRange;
135         using mixin::nextPacketType;
136         using mixin::initSize;
137         using mixin::init;
138
139         static registry_key_t nextPacketKey(packet p) 
140             { return p->protocol(); }
141
142         static void dump(packet p, std::ostream & os);
143     };
144         
145     /** \brief IpV4 packet typedef */
146     typedef IpV4PacketType::packet IpV4Packet;
147 }
148
149
150 ///////////////////////////////hh.e////////////////////////////////////////
151 #endif
152 #ifndef SENF_PACKETS_DECL_ONLY
153 //#include IpV4Packet.cci"
154 //#include "IpV4Packet.ct"
155 //#include "IpV4Packet.cti"
156 #endif
157
158 \f
159 // Local Variables:
160 // mode: c++
161 // fill-column: 100
162 // c-file-style: "senf"
163 // indent-tabs-mode: nil
164 // ispell-local-dictionary: "american"
165 // compile-command: "scons -u test"
166 // comment-column: 40
167 // End: