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