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:
38 \see IpV4PacketType \n
39 <a href="http://tools.ietf.org/html/rfc791">RFC 791</a>
41 \todo Implement options
43 struct Parse_IpV4 : public PacketParserBase
45 typedef Parse_UIntField < 0, 4 > Parse_Version;
46 typedef Parse_UIntField < 4, 8 > Parse_IHL;
47 typedef Parse_UInt8 Parse_8bit;
48 typedef Parse_UInt16 Parse_16bit;
49 typedef Parse_Flag < 0 > Parse_R;
50 typedef Parse_Flag < 1 > Parse_DF;
51 typedef Parse_Flag < 2 > Parse_MF;
52 typedef Parse_UIntField < 3, 16 > Parse_Frag;
53 typedef Parse_UInt32 Parse_32bit;
57 SENF_PACKET_PARSER_NO_INIT(Parse_IpV4);
59 SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
60 ((OverlayField)( version, Parse_Version ))
61 ((Field )( ihl, Parse_IHL ))
62 ((Field )( tos, Parse_8bit ))
63 ((Field )( length, Parse_16bit ))
64 ((Field )( identifier, Parse_16bit ))
65 ((OverlayField)( reserved, Parse_R ))
66 ((OverlayField)( df, Parse_DF ))
67 ((OverlayField)( mf, Parse_MF ))
68 ((Field )( frag, Parse_Frag ))
69 ((Field )( ttl, Parse_8bit ))
70 ((Field )( protocol, Parse_8bit ))
71 ((Field )( crc, Parse_16bit ))
72 ((Field )( source, Parse_32bit ))
73 ((Field )( destination, Parse_32bit )) );
77 Parse_Version version();
81 Parse_16bit identifier();
87 Parse_8bit protocol();
90 Parse_32bit destination();
99 /** \brief IP protocol number registry
101 This registeres packets with their IP protocol number.
103 \see <a href="http://www.iana.org/assignments/protocol-numbers">Protocol numbers</a> \n
107 typedef boost::uint16_t key_t;
110 /** \brief IpV4 packet
112 \par Packet type (typedef):
118 \par Associated registries:
121 \ingroup protocolbundle_default
123 struct IpV4PacketType
124 : public PacketTypeBase,
125 public PacketTypeMixin<IpV4PacketType, IpTypes>
127 typedef PacketTypeMixin<IpV4PacketType, IpTypes> mixin;
128 typedef ConcretePacket<IpV4PacketType> packet;
129 typedef Parse_IpV4 parser;
131 using mixin::nextPacketRange;
132 using mixin::nextPacketType;
133 using mixin::initSize;
136 static registry_key_t nextPacketKey(packet p)
137 { return p->protocol(); }
139 static void dump(packet p, std::ostream & os);
142 /** \brief IpV4 packet typedef */
143 typedef IpV4PacketType::packet IpV4Packet;
147 ///////////////////////////////hh.e////////////////////////////////////////
149 #ifndef SENF_PACKETS_DECL_ONLY
150 //#include IpV4Packet.cci"
151 //#include "IpV4Packet.ct"
152 //#include "IpV4Packet.cti"
159 // c-file-style: "senf"
160 // indent-tabs-mode: nil
161 // ispell-local-dictionary: "american"
162 // compile-command: "scons -u test"
163 // comment-column: 40