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 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;
83 SENF_PACKET_PARSER_NO_INIT(Parse_IpV4);
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 )( checksum, Parse_16bit ))
98 ((Field )( source, Parse_Addr ))
99 ((Field )( destination, Parse_Addr )) );
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;
111 Parse_Frag frag() const;
112 Parse_8bit ttl() const;
113 Parse_8bit protocol() const;
114 Parse_16bit checksum() const;
115 Parse_Addr source() const;
116 Parse_Addr destination() const;
122 // We don't support option headers at the moment ...
126 boost::uint16_t calcChecksum() const;
127 bool validateChecksum() const {
128 return checksum() == calcChecksum();
132 /** \brief IP protocol number registry
134 This registeres packets with their IP protocol number.
136 \see <a href="http://www.iana.org/assignments/protocol-numbers">Protocol numbers</a> \n
140 typedef boost::uint16_t key_t;
143 /** \brief IpV4 packet
145 \par Packet type (typedef):
151 \par Associated registries:
154 \ingroup protocolbundle_default
156 struct IpV4PacketType
157 : public PacketTypeBase,
158 public PacketTypeMixin<IpV4PacketType, IpTypes>
160 typedef PacketTypeMixin<IpV4PacketType, IpTypes> mixin;
161 typedef ConcretePacket<IpV4PacketType> packet;
162 typedef Parse_IpV4 parser;
164 using mixin::nextPacketRange;
165 using mixin::nextPacketType;
166 using mixin::initSize;
169 static registry_key_t nextPacketKey(packet p)
170 { return p->protocol(); }
172 static void dump(packet p, std::ostream & os);
173 static void finalize(packet p);
176 /** \brief IpV4 packet typedef */
177 typedef IpV4PacketType::packet IpV4Packet;
181 ///////////////////////////////hh.e////////////////////////////////////////
183 #ifndef SENF_PACKETS_DECL_ONLY
184 //#include IpV4Packet.cci"
185 //#include "IpV4Packet.ct"
186 //#include "IpV4Packet.cti"
193 // c-file-style: "senf"
194 // indent-tabs-mode: nil
195 // ispell-local-dictionary: "american"
196 // compile-command: "scons -u test"
197 // comment-column: 40