Implemented IpV6Packet and added raw-data constructor to INet6Address
[senf.git] / Packets / IpV6Packet.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief IpV6Packet public header */
23
24 #ifndef HH_IpV6Packet_
25 #define HH_IpV6Packet_ 1
26
27 // Custom includes
28 #include "Packet.hh"
29 #include "ParseInt.hh"
30 #include "ParseArray.hh"
31 #include "PacketRegistry.hh"
32 #include "IpV4Packet.hh"
33
34 //#include "IpV6Packet.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38
39     template <class Iterator=nil, class IpV6Packet=nil>
40     struct Parse_IpV6 : public ParserBase<Iterator,IpV6Packet>
41     {
42         template <class I, class P=nil>
43         struct rebind { typedef Parse_IpV6<I,P> parser; };
44         typedef Iterator byte_iterator;
45
46         Parse_IpV6() {}
47         Parse_IpV6(Iterator const & i) : ParserBase<Iterator,IpV6Packet>(i) {}
48
49         static unsigned bytes() { return 40; }
50         
51         ///////////////////////////////////////////////////////////////////////////
52
53         typedef Parse_UIntField <  0,  4, Iterator > Parse_Version;
54         typedef Parse_UIntField <  4, 12, Iterator > Parse_Class;
55         typedef Parse_UIntField < 12, 32, Iterator > Parse_FlowLabel;
56         typedef Parse_UInt8     <         Iterator > Parse_8bit;
57         typedef Parse_UInt16    <         Iterator > Parse_16bit;
58
59         typedef Parse_Array < 16, Parse_8bit, Iterator > Parse_Addr;
60
61         Parse_Version    version()       const { return Parse_Version   (this->i()      ); }
62         Parse_Class      trafficClass()  const { return Parse_Class     (this->i()      ); }
63         Parse_FlowLabel  flowLabel()     const { return Parse_FlowLabel (this->i()      ); }
64         Parse_16bit      length()        const { return Parse_16bit     (this->i() +  4 ); }
65         Parse_8bit       nextHeader()    const { return Parse_8bit      (this->i() +  6 ); }
66         Parse_8bit       hopLimit()      const { return Parse_8bit      (this->i() +  7 ); }
67         Parse_Addr       source()        const { return Parse_Addr      (this->i() +  8 ); }
68         Parse_Addr       destination()   const { return Parse_Addr      (this->i() + 24 ); }
69     };
70
71     class IpV6Packet
72         : public Packet,
73           public Parse_IpV6<Packet::iterator, IpV6Packet>,
74           public PacketRegistryMixin<IpTypes, IpV6Packet>
75     {
76         using PacketRegistryMixin<IpTypes,IpV6Packet>::registerInterpreter;
77     public:
78         ///////////////////////////////////////////////////////////////////////////
79         // Types
80
81         typedef ptr_t<IpV6Packet>::ptr ptr;
82
83         ///////////////////////////////////////////////////////////////////////////
84
85     private:
86         template <class Arg>
87         IpV6Packet(Arg const & arg);
88
89         virtual void v_nextInterpreter() const;
90         virtual void v_finalize();
91         virtual void v_dump(std::ostream & os) const;
92
93         friend class Packet;
94     };
95
96 }    
97
98 ///////////////////////////////hh.e////////////////////////////////////////
99 //#include "IpV6Packet.cci"
100 //#include "IpV6Packet.ct"
101 #include "IpV6Packet.cti"
102 #endif
103
104 \f
105 // Local Variables:
106 // mode: c++
107 // fill-column: 100
108 // c-file-style: "senf"
109 // ispell-local-dictionary: "american"
110 // End: