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.
24 \brief IpV4Packet public header */
26 #ifndef HH_IpV4Packet_
27 #define HH_IpV4Packet_ 1
30 #include "../../Socket/Protocols/INet/INet4Address.hh"
31 #include "../../Packets/Packets.hh"
33 //#include "IpV4Packet.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
38 /** \brief Parse in IpV4 address
42 struct Parse_INet4Address : public PacketParserBase
44 Parse_INet4Address(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
46 ///////////////////////////////////////////////////////////////////////////
48 typedef INet4Address value_type;
49 static const size_type fixed_bytes = 4u;
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; }
59 /** \brief Parse an IpV4 packet
61 Parser implementing the IpV4 header. The fields implemented are:
63 \see IpV4PacketType \n
64 <a href="http://tools.ietf.org/html/rfc791">RFC 791</a>
66 \todo Implement options
68 struct Parse_IpV4 : public PacketParserBase
70 # include SENF_FIXED_PARSER()
72 SENF_PARSER_BITFIELD( version, 4, unsigned );
73 SENF_PARSER_BITFIELD( ihl, 4, unsigned );
75 SENF_PARSER_FIELD( tos, Parse_UInt8 );
76 SENF_PARSER_FIELD( length, Parse_UInt16 );
77 SENF_PARSER_FIELD( identifier, Parse_UInt16 );
79 SENF_PARSER_BITFIELD( reserved, 1, bool );
80 SENF_PARSER_BITFIELD( df, 1, bool );
81 SENF_PARSER_BITFIELD( mf, 1, bool );
82 SENF_PARSER_BITFIELD( frag, 13, unsigned );
84 SENF_PARSER_FIELD( ttl, Parse_UInt8 );
85 SENF_PARSER_FIELD( protocol, Parse_UInt8 );
86 SENF_PARSER_FIELD( checksum, Parse_UInt16 );
87 SENF_PARSER_FIELD( source, Parse_INet4Address );
88 SENF_PARSER_FIELD( destination, Parse_INet4Address );
92 // We don't support option headers at the moment ...
96 SENF_PARSER_FINALIZE(Parse_IpV4);
98 boost::uint16_t calcChecksum() const;
100 bool validateChecksum() const {
101 return checksum() == calcChecksum();
105 /** \brief IP protocol number registry
107 This registeres packets with their IP protocol number.
109 \see <a href="http://www.iana.org/assignments/protocol-numbers">Protocol numbers</a> \n
113 typedef boost::uint16_t key_t;
116 /** \brief IpV4 packet
118 \par Packet type (typedef):
124 \par Associated registries:
127 \ingroup protocolbundle_default
129 struct IpV4PacketType
130 : public PacketTypeBase,
131 public PacketTypeMixin<IpV4PacketType, IpTypes>
133 typedef PacketTypeMixin<IpV4PacketType, IpTypes> mixin;
134 typedef ConcretePacket<IpV4PacketType> packet;
135 typedef Parse_IpV4 parser;
137 using mixin::nextPacketRange;
138 using mixin::nextPacketType;
139 using mixin::initSize;
142 static registry_key_t nextPacketKey(packet p)
143 { return p->protocol(); }
145 static void dump(packet p, std::ostream & os);
146 static void finalize(packet p);
149 /** \brief IpV4 packet typedef */
150 typedef IpV4PacketType::packet IpV4Packet;
154 ///////////////////////////////hh.e////////////////////////////////////////
156 #ifndef SENF_PACKETS_DECL_ONLY
157 //#include IpV4Packet.cci"
158 //#include "IpV4Packet.ct"
159 //#include "IpV4Packet.cti"
166 // c-file-style: "senf"
167 // indent-tabs-mode: nil
168 // ispell-local-dictionary: "american"
169 // compile-command: "scons -u test"
170 // comment-column: 40