Move include files in debian packge into 'senf' subdirectory
[senf.git] / Packets / DefaultBundle / 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 "../../Socket/Protocols/INet/INet6Address.hh"
29 #include "../../Packets/Packets.hh"
30 #include "IpV4Packet.hh"
31
32 //#include "IpV6Packet.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
34
35 namespace senf {
36
37     /** \brief Parse an IpV6 address
38         
39         \see INet6Address
40      */
41     struct Parse_INet6Address : public PacketParserBase
42     {
43         Parse_INet6Address(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
44
45         ///////////////////////////////////////////////////////////////////////////
46
47         typedef INet6Address value_type;
48         static const size_type fixed_bytes = 16u;
49
50         value_type value() const { return value_type::from_data(i()); }
51         void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
52         operator value_type() { return value(); }
53         byte & operator[](size_type index) { return *boost::next(i(),index); }
54         Parse_INet6Address const & operator= (value_type const & other) 
55             { value(other); return *this; }
56     };
57
58     /** \brief Parse an IpV6 packet
59
60         \see IpV6PacketType \n
61             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
62      */
63     struct Parse_IpV6 : public PacketParserBase
64     {
65         typedef Parse_UIntField <  0,  4 > Parse_Version;
66         typedef Parse_UIntField <  4, 12 > Parse_Class;
67         typedef Parse_UIntField < 12, 32 > Parse_FlowLabel;
68         typedef Parse_UInt8                Parse_8bit;
69         typedef Parse_UInt16               Parse_16bit;
70         typedef Parse_INet6Address         Parse_Addr;
71
72 #       ifndef DOXYGEN
73
74         SENF_PACKET_PARSER_NO_INIT(Parse_IpV6);
75
76         SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
77             ((OverlayField)( version,      Parse_Version   ))
78             ((OverlayField)( trafficClass, Parse_Class     ))
79             ((Field       )( flowLabel,    Parse_FlowLabel ))
80             ((Field       )( length,       Parse_16bit     ))
81             ((Field       )( nextHeader,   Parse_8bit      ))
82             ((Field       )( hopLimit,     Parse_8bit      ))
83             ((Field       )( source,       Parse_Addr      ))
84             ((Field       )( destination,  Parse_Addr      )) );
85
86 #       else
87
88         Parse_Version   version() const;
89         Parse_Class     trafficClass() const;
90         Parse_FlowLabel flowLabel() const;
91         Parse_16bit     length() const;
92         Parse_8bit      nextHeader() const;
93         Parse_8bit      hopLimit() const;
94         Parse_Addr      source() const;
95         Parse_Addr      destination() const;
96
97 #       endif
98
99         void init() {
100             version() = 6;
101         }
102     };
103
104     /** \brief IpV6 packet
105
106         \par Packet type (typedef):
107             \ref IpV6Packet
108         
109         \par Fields:
110             \ref Parse_IpV6
111
112         \par Associated registries:
113             \ref IpTypes
114
115         \ingroup protocolbundle_default
116      */
117     struct IpV6PacketType
118         : public PacketTypeBase,
119           public PacketTypeMixin<IpV6PacketType, IpTypes>
120     {
121         typedef PacketTypeMixin<IpV6PacketType, IpTypes> mixin;
122         typedef ConcretePacket<IpV6PacketType> packet;
123         typedef Parse_IpV6 parser;
124
125         using mixin::nextPacketRange;
126         using mixin::nextPacketType;
127         using mixin::initSize;
128         using mixin::init;
129
130         static registry_key_t nextPacketKey(packet p) 
131             { return p->nextHeader(); }
132         
133         static void dump(packet p, std::ostream & os);
134     };
135
136     /** \brief IpV6 packet typedef */
137     typedef IpV6PacketType::packet IpV6Packet;
138
139     ///@}
140 }
141
142 ///////////////////////////////hh.e////////////////////////////////////////
143 #endif
144 #ifndef SENF_PACKETS_DECL_ONLY
145 //#include "IpV6Packet.cci"
146 //#include "IpV6Packet.ct"
147 //#include "IpV6Packet.cti"
148 #endif
149
150 \f
151 // Local Variables:
152 // mode: c++
153 // fill-column: 100
154 // c-file-style: "senf"
155 // indent-tabs-mode: nil
156 // ispell-local-dictionary: "american"
157 // compile-command: "scons -u test"
158 // comment-column: 40
159 // End: