Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Packets / DefaultBundle / IPv4Packet.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.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_SENF_Packets_DefaultBundle_IPv4Packet_
27 #define HH_SENF_Packets_DefaultBundle_IPv4Packet_ 1
28
29 // Custom includes
30 #include <senf/Socket/Protocols/INet/INet4Address.hh>
31 #include <senf/Packets/Packets.hh>
32
33 //#include "IPv4Packet.mpp"
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35
36 namespace senf {
37
38     /** \brief Parse in IPv4 address
39
40         \see INet4Address
41      */
42     struct INet4AddressParser
43         : public ValueParserBase<INet4AddressParser, INet4Address, 4u>
44     {
45         INet4AddressParser(data_iterator i, state_type s) : Base(i,s) {}
46
47         value_type value() const { return value_type::from_data(i()); }
48         void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
49
50         using Base::operator=;
51     };
52
53     /** \brief Parse an IPv4 packet
54
55         Parser implementing the IPv4 header.
56
57         \image html IPv4Packet.png
58
59         \see IPv4PacketType \n
60             <a href="http://tools.ietf.org/html/rfc791">RFC 791</a>
61
62         \todo Implement options
63      */
64     struct IPv4PacketParser : public PacketParserBase
65     {
66 #       include SENF_FIXED_PARSER()
67
68         SENF_PARSER_BITFIELD( version,   4, unsigned );
69         SENF_PARSER_BITFIELD( ihl,       4, unsigned );
70
71         SENF_PARSER_FIELD( tos,         UInt8Parser        );
72         SENF_PARSER_FIELD( length,      UInt16Parser       );
73         SENF_PARSER_FIELD( identifier,  UInt16Parser       );
74
75         SENF_PARSER_PRIVATE_BITFIELD( reserved,  1, bool     );
76         SENF_PARSER_BITFIELD        ( df,        1, bool     );
77         SENF_PARSER_BITFIELD        ( mf,        1, bool     );
78         SENF_PARSER_BITFIELD        ( frag,     13, unsigned );
79
80         SENF_PARSER_FIELD( ttl,         UInt8Parser        );
81         SENF_PARSER_FIELD( protocol,    UInt8Parser        );
82         SENF_PARSER_FIELD( checksum,    UInt16Parser       );
83         SENF_PARSER_FIELD( source,      INet4AddressParser );
84         SENF_PARSER_FIELD( destination, INet4AddressParser );
85
86         SENF_PARSER_INIT() {
87             version() = 4;
88             // We don't support option headers at the moment ...
89             ihl() = 5;
90         }
91
92         SENF_PARSER_FINALIZE(IPv4PacketParser);
93
94         boost::uint16_t calcChecksum() const; ///< calculate header checksum
95                                               /**< calculate and return the checksum of the header
96                                                    \see \ref senf::IpChecksum */
97
98         bool validateChecksum() const {
99             return checksum() == calcChecksum();
100         }                               ///< validate header checksum
101                                         /**< return \c true if the \ref checksum() "checksum"
102                                              field is equal to the \ref calcChecksum()
103                                              "calculated checksum" */
104     };
105
106     /** \brief IP protocol number registry
107
108         This registeres packets with their IP protocol number.
109
110         \see <a href="http://www.iana.org/assignments/protocol-numbers">Protocol numbers</a> \n
111             PacketRegistry
112      */
113     struct IpTypes {
114         typedef boost::uint8_t key_t;
115     };
116
117     /** \brief IPv4 packet
118
119         \par Packet type (typedef):
120             \ref IPv4Packet
121
122         \par Fields:
123             see \ref IPv4PacketParser
124
125         <table class="packet" cellpadding="5" cellspacing="1" border="1">
126           <tr>
127             <th width="12%">0</th> <th width="12%">4</th> <th width="12%">8</th>
128             <th width="12%">12</th> <th width="3%">16</th>
129             <th width="3%"></th> <th width="3%"></th> <th width="3%"></th>
130             <th width="12%">20</th> <th width="12%">24</th> <th width="6%">28</th>
131             <th style="text-align:right" width="6%">31</th>
132           </tr><tr>
133             <td>\ref IPv4PacketParser::version() "Version"</td>
134             <td>\ref IPv4PacketParser::ihl() "IHL"</td>
135             <td colspan="2">\ref IPv4PacketParser::tos() "TOS"</td>
136             <td colspan="8">\ref IPv4PacketParser::length() "Length"</td>
137           </tr><tr>
138             <td colspan="4">\ref IPv4PacketParser::identifier() "Identifier"</td>
139             <td>R</td>
140             <td>\ref IPv4PacketParser::df() "DF"</td>
141             <td>\ref IPv4PacketParser::mf() "MF"</td>
142             <td colspan="5">\ref IPv4PacketParser::frag() "Fragment Offset"</td>
143           </tr><tr>
144             <td colspan="2">\ref IPv4PacketParser::ttl() "Time to Live (ttl)"</td>
145             <td colspan="2">\ref IPv4PacketParser::protocol() "Protocol"</td>
146             <td colspan="8">\ref IPv4PacketParser::checksum() "Header Checksum"</td>
147           </tr><tr>
148             <td colspan="12">\ref IPv4PacketParser::source() "Source Address"</td>
149           </tr><tr>
150             <td colspan="12">\ref IPv4PacketParser::destination() "Destination Address"</td>
151           </tr>
152         </table>
153
154         \par Associated registries:
155             \ref IpTypes
156
157         \par Finalize action:
158             \copydetails finalize()
159
160         \ingroup protocolbundle_default
161      */
162     struct IPv4PacketType
163         : public PacketTypeBase,
164           public PacketTypeMixin<IPv4PacketType, IpTypes>
165     {
166 #ifndef DOXYGEN
167         typedef PacketTypeMixin<IPv4PacketType, IpTypes> mixin;
168 #endif
169         typedef ConcretePacket<IPv4PacketType> packet;  ///< IPv4 packet typedef
170         typedef IPv4PacketParser parser;                ///< typedef to the parser of IPv4 packet
171
172         using mixin::nextPacketRange;
173         using mixin::nextPacketType;
174         using mixin::initSize;
175         using mixin::init;
176
177         static key_t nextPacketKey(packet p)
178             { return p->protocol(); }
179
180         /** \brief Dump given IPv4Packet in readable form to given output stream */
181         static void dump(packet p, std::ostream & os);
182
183         static void finalize(packet p); ///< Finalize packet.
184                                         /**< \li set \ref IPv4PacketParser::length() "length"
185                                                from payload size
186                                              \li set \ref IPv4PacketParser::protocol() "protocol"
187                                                from type of next packet if found in \ref IpTypes
188                                              \li calculate and set
189                                                \ref IPv4PacketParser::checksum() "checksum" */
190     };
191
192     /** \brief IPv4 packet typedef
193         \ingroup protocolbundle_default
194      */
195     typedef ConcretePacket<IPv4PacketType> IPv4Packet;
196 }
197
198
199 //-/////////////////////////////////////////////////////////////////////////////////////////////////
200 //#include "IPv4Packet.cci"
201 //#include "IPv4Packet.ct"
202 //#include "IPv4Packet.cti"
203 #endif
204
205 \f
206 // Local Variables:
207 // mode: c++
208 // fill-column: 100
209 // c-file-style: "senf"
210 // indent-tabs-mode: nil
211 // ispell-local-dictionary: "american"
212 // compile-command: "scons -u test"
213 // comment-column: 40
214 // End: