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/Packet.hh"
28 #include "Packets/ParseInt.hh"
29 #include "Packets/ParseArray.hh"
30 #include "Packets/PacketRegistry.hh"
32 //#include "IpV4Packet.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
38 template <class Iterator=nil, class IpV4Packet=nil>
39 struct Parse_IpV4 : public ParserBase<Iterator,IpV4Packet>
41 template <class I, class P=nil>
42 struct rebind { typedef Parse_IpV4<I,P> parser; };
43 typedef Iterator byte_iterator;
46 Parse_IpV4(Iterator const & i) : ParserBase<Iterator,IpV4Packet>(i) {}
48 static unsigned bytes() { return 20; }
50 ///////////////////////////////////////////////////////////////////////////
52 typedef Parse_UIntField < 0, 4, Iterator > Parse_Version;
53 typedef Parse_UIntField < 4, 8, Iterator > Parse_IHL;
54 typedef Parse_UInt8 < Iterator > Parse_8bit;
55 typedef Parse_UInt16 < Iterator > Parse_16bit;
56 typedef Parse_Flag < 0, Iterator > Parse_R;
57 typedef Parse_Flag < 1, Iterator > Parse_DF;
58 typedef Parse_Flag < 2, Iterator > Parse_MF;
59 typedef Parse_UIntField < 3, 16, Iterator > Parse_Frag;
60 typedef Parse_UInt32 < Iterator > Parse_32bit;
62 Parse_Version version() const { return Parse_Version (this->i() ); }
63 Parse_IHL ihl() const { return Parse_IHL (this->i() ); }
64 Parse_8bit tos() const { return Parse_8bit (this->i() + 1 ); }
65 Parse_16bit length() const { return Parse_16bit (this->i() + 2 ); }
66 Parse_16bit identifier() const { return Parse_16bit (this->i() + 4 ); }
67 Parse_R reserved() const { return Parse_R (this->i() + 6 ); }
68 Parse_DF df() const { return Parse_DF (this->i() + 6 ); }
69 Parse_MF mf() const { return Parse_MF (this->i() + 6 ); }
70 Parse_Frag frag() const { return Parse_Frag (this->i() + 6 ); }
71 Parse_8bit ttl() const { return Parse_8bit (this->i() + 8 ); }
72 Parse_8bit protocol() const { return Parse_8bit (this->i() + 9 ); }
73 Parse_16bit crc() const { return Parse_16bit (this->i() + 10 ); }
74 Parse_32bit source() const { return Parse_32bit (this->i() + 12 ); }
75 Parse_32bit destination() const { return Parse_32bit (this->i() + 16 ); }
79 // See http://www.iana.org/assignments/protocol-numbers
81 typedef boost::uint16_t key_t;
86 public Parse_IpV4<Packet::iterator,IpV4Packet>,
87 public PacketRegistryMixin<IpTypes,IpV4Packet>
89 using PacketRegistryMixin<IpTypes,IpV4Packet>::registerInterpreter;
91 ///////////////////////////////////////////////////////////////////////////
94 typedef ptr_t<IpV4Packet>::ptr ptr;
96 ///////////////////////////////////////////////////////////////////////////
100 IpV4Packet(Arg const & arg);
102 virtual void v_nextInterpreter() const;
103 virtual void v_finalize();
104 virtual void v_dump(std::ostream & os) const;
111 ///////////////////////////////hh.e////////////////////////////////////////
112 //#include IpV4Packet.cci"
113 //#include "IpV4Packet.ct"
114 #include "IpV4Packet.cti"
121 // c-file-style: "senf"
122 // indent-tabs-mode: nil
123 // ispell-local-dictionary: "american"