1 // $Id: EthernetPacket.hh 299 2007-07-10 21:23:49Z g0dil $
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.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 IPv6Packet public header */
26 #ifndef HH_SENF_Packets_DefaultBundle_IPv6Packet_
27 #define HH_SENF_Packets_DefaultBundle_IPv6Packet_ 1
30 #include <senf/Socket/Protocols/INet/INet6Address.hh>
31 #include <senf/Packets/Packets.hh>
32 #include "IPv4Packet.hh"
34 //#include "IPv6Packet.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
39 /** \brief Parse an IPv6 address
43 struct INet6AddressParser : public PacketParserBase
45 INet6AddressParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
47 ///////////////////////////////////////////////////////////////////////////
49 typedef INet6Address value_type;
50 static const size_type fixed_bytes = 16u;
52 value_type value() const { return value_type::from_data(i()); }
53 void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
54 operator value_type() const { return value(); }
55 byte & operator[](size_type index) const { return *boost::next(i(),index); }
56 INet6AddressParser const & operator= (value_type const & other)
57 { value(other); return *this; }
60 /** \brief Parse an IPv6 packet
62 \image html IPv6Packet.png
63 \see IPv6PacketType \n
64 <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
66 struct IPv6PacketParser : public PacketParserBase
68 # include SENF_FIXED_PARSER()
70 SENF_PARSER_BITFIELD( version, 4, unsigned );
71 SENF_PARSER_BITFIELD( trafficClass, 8, unsigned );
72 SENF_PARSER_BITFIELD( flowLabel, 20, unsigned );
74 SENF_PARSER_FIELD( length, UInt16Parser );
75 SENF_PARSER_FIELD( nextHeader, UInt8Parser );
76 SENF_PARSER_FIELD( hopLimit, UInt8Parser );
77 SENF_PARSER_FIELD( source, INet6AddressParser );
78 SENF_PARSER_FIELD( destination, INet6AddressParser );
84 SENF_PARSER_FINALIZE(IPv6PacketParser);
87 /** \brief IPv6 packet
89 \par Packet type (typedef):
95 <table class="packet" cellpadding="5" cellspacing="1" border="1">
97 <th width="12.5%">0</th> <th width="12.5%">4</th> <th width="12.5%">8</th>
98 <th width="12.5%">12</th> <th width="12.5%">16</th> <th width="12.5%">20</th>
99 <th width="12.5%">24</th> <th width="6.5%">28</th>
100 <th style="text-align:right" width="6%">31</th>
102 <td>\ref IPv6PacketParser::version() "Version"</td>
103 <td colspan="2">\ref IPv6PacketParser::trafficClass() "Traffic Class"</td>
104 <td colspan="6">\ref IPv6PacketParser::flowLabel() "Flow Label"</td>
106 <td colspan="4">\ref IPv6PacketParser::length() "Payload Length"</td>
107 <td colspan="2">\ref IPv6PacketParser::nextHeader() "Next Header"</td>
108 <td colspan="3">\ref IPv6PacketParser::hopLimit() "Hop Limit"</td>
110 <td colspan="9" style="height:8em">
111 \ref IPv6PacketParser::source() "Source Address"</td>
113 <td colspan="9" style="height:8em">
114 \ref IPv6PacketParser::destination() "Destination Address"</td>
118 \par Associated registries:
121 \par Finalize action:
122 \copydetails finalize()
124 \ingroup protocolbundle_default
126 struct IPv6PacketType
127 : public PacketTypeBase,
128 public PacketTypeMixin<IPv6PacketType, IpTypes>
131 typedef PacketTypeMixin<IPv6PacketType, IpTypes> mixin;
133 typedef ConcretePacket<IPv6PacketType> packet; ///< IPv6 packet typedef
134 typedef IPv6PacketParser parser; ///< typedef to the parser of IPv6 packet
136 using mixin::nextPacketRange;
137 using mixin::nextPacketType;
138 using mixin::initSize;
141 static key_t nextPacketKey(packet p)
142 { return p->nextHeader(); }
144 /** \brief Dump given IPv6Packet in readable form to given output stream */
145 static void dump(packet p, std::ostream & os);
147 static void finalize(packet p); ///< Finalize packet.
148 /**< \li set \ref IPv6PacketParser::length() "length"
150 \li set \ref IPv6PacketParser::nextHeader()
151 "nextHeader" from type of next packet if found
155 /** \brief IPv6 packet typedef */
156 typedef ConcretePacket<IPv6PacketType> IPv6Packet;
161 ///////////////////////////////hh.e////////////////////////////////////////
162 //#include "IPv6Packet.cci"
163 //#include "IPv6Packet.ct"
164 //#include "IPv6Packet.cti"
171 // c-file-style: "senf"
172 // indent-tabs-mode: nil
173 // ispell-local-dictionary: "american"
174 // compile-command: "scons -u test"
175 // comment-column: 40