4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
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.
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.
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.
23 #ifndef HH_IpV4Packet_
24 #define HH_IpV4Packet_ 1
27 #include "Packets/Packets.hh"
29 //#include "IpV4Packet.mpp"
30 ///////////////////////////////hh.p////////////////////////////////////////
34 /** \brief Parse an IpV4 packet
36 Parser implementing the IpV4 header. The fields implemented are:
39 <tr><th>Field name</th><th>Parser type</th></tr>
40 <tr><td>version</td><td>\ref Parse_Version</td></tr>
41 <tr><td>ihl</td><td>\ref Parse_IHL</td></tr>
42 <tr><td>tos</td><td>\ref Parse_8bit</td></tr>
43 <tr><td>length</td><td>\ref Parse_16bit</td></tr>
44 <tr><td>identifier</td><td>\ref Parse_16bit</td></tr>
45 <tr><td>reserved</td><td>\ref Parse_R</td></tr>
46 <tr><td>df</td><td>\ref Parse_DF</td></tr>
47 <tr><td>mf</td><td>\ref Parse_MF</td></tr>
48 <tr><td>frag</td><td>\ref Parse_Frag</td></tr>
49 <tr><td>ttl</td><td>\ref Parse_8bit</td></tr>
50 <tr><td>protocol</td><td>\ref Parse_8bit</td></tr>
51 <tr><td>crc</td><td>\ref Parse_16bit</td></tr>
52 <tr><td>source</td><td>\ref Parse_32bit</td></tr>
53 <tr><td>destination</td><td>\ref Parse_32bit</td></tr>
56 \see IpV4PacketType \n
57 <a href="http://tools.ietf.org/html/rfc791">RFC 791</a>
59 \todo Implement options
61 struct Parse_IpV4 : public PacketParserBase
63 SENF_PACKET_PARSER_NO_INIT(Parse_IpV4);
65 ///////////////////////////////////////////////////////////////////////////
67 typedef Parse_UIntField < 0, 4 > Parse_Version;
68 typedef Parse_UIntField < 4, 8 > Parse_IHL;
69 typedef Parse_UInt8 Parse_8bit;
70 typedef Parse_UInt16 Parse_16bit;
71 typedef Parse_Flag < 0 > Parse_R;
72 typedef Parse_Flag < 1 > Parse_DF;
73 typedef Parse_Flag < 2 > Parse_MF;
74 typedef Parse_UIntField < 3, 16 > Parse_Frag;
75 typedef Parse_UInt32 Parse_32bit;
77 SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
78 ((OverlayField)( version, Parse_Version ))
79 ((Field )( ihl, Parse_IHL ))
80 ((Field )( tos, Parse_8bit ))
81 ((Field )( length, Parse_16bit ))
82 ((Field )( identifier, Parse_16bit ))
83 ((OverlayField)( reserved, Parse_R ))
84 ((OverlayField)( df, Parse_DF ))
85 ((OverlayField)( mf, Parse_MF ))
86 ((Field )( frag, Parse_Frag ))
87 ((Field )( ttl, Parse_8bit ))
88 ((Field )( protocol, Parse_8bit ))
89 ((Field )( crc, Parse_16bit ))
90 ((Field )( source, Parse_32bit ))
91 ((Field )( destination, Parse_32bit )) );
98 /** \brief IP protocol number registry
100 This registeres packets with their IP protocol number.
102 \see <a href="http://www.iana.org/assignments/protocol-numbers">Protocol numbers</a>
106 typedef boost::uint16_t key_t;
109 /** \brief IpV4 packet
111 \par Packet type (typedef):
117 \par Associated registries:
120 \ingroup protocolbundle_default
122 struct IpV4PacketType
123 : public PacketTypeBase,
124 public PacketTypeMixin<IpV4PacketType, IpTypes>
126 typedef PacketTypeMixin<IpV4PacketType, IpTypes> mixin;
127 typedef ConcretePacket<IpV4PacketType> packet;
128 typedef Parse_IpV4 parser;
130 using mixin::nextPacketRange;
131 using mixin::nextPacketType;
132 using mixin::initSize;
135 static registry_key_t nextPacketKey(packet p)
136 { return p->protocol(); }
138 static void dump(packet p, std::ostream & os);
141 /** \brief IpV4 packet typedef */
142 typedef IpV4PacketType::packet IpV4Packet;
146 ///////////////////////////////hh.e////////////////////////////////////////
148 #ifndef SENF_PACKETS_DECL_ONLY
149 //#include IpV4Packet.cci"
150 //#include "IpV4Packet.ct"
151 //#include "IpV4Packet.cti"
158 // c-file-style: "senf"
159 // indent-tabs-mode: nil
160 // ispell-local-dictionary: "american"
161 // compile-command: "scons -u test"
162 // comment-column: 40