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_IPv6Packet_
27 #define HH_IPv6Packet_ 1
30 #include "../../Socket/Protocols/INet/INet6Address.hh"
31 #include "../../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 \see IPv6PacketType \n
63 <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
65 struct IPv6PacketParser : public PacketParserBase
67 # include SENF_FIXED_PARSER()
69 SENF_PARSER_BITFIELD( version, 4, unsigned );
70 SENF_PARSER_BITFIELD( trafficClass, 8, unsigned );
71 SENF_PARSER_BITFIELD( flowLabel, 20, unsigned );
73 SENF_PARSER_FIELD( length, UInt16Parser );
74 SENF_PARSER_FIELD( nextHeader, UInt8Parser );
75 SENF_PARSER_FIELD( hopLimit, UInt8Parser );
76 SENF_PARSER_FIELD( source, INet6AddressParser );
77 SENF_PARSER_FIELD( destination, INet6AddressParser );
83 SENF_PARSER_FINALIZE(IPv6PacketParser);
86 /** \brief IPv6 packet
88 \par Packet type (typedef):
94 \par Associated registries:
98 Set \a length from payload size\n
99 Set \a nextHeader from type of next packet if found in \ref IpTypes
101 \ingroup protocolbundle_default
103 struct IPv6PacketType
104 : public PacketTypeBase,
105 public PacketTypeMixin<IPv6PacketType, IpTypes>
108 typedef PacketTypeMixin<IPv6PacketType, IpTypes> mixin;
109 typedef ConcretePacket<IPv6PacketType> packet;
110 typedef IPv6PacketParser parser;
112 using mixin::nextPacketRange;
113 using mixin::nextPacketType;
114 using mixin::initSize;
117 static key_t nextPacketKey(packet p)
118 { return p->nextHeader(); }
120 static void dump(packet p, std::ostream & os);
122 static void finalize(packet p);
125 /** \brief IPv6 packet typedef */
126 typedef ConcretePacket<IPv6PacketType> IPv6Packet;
131 ///////////////////////////////hh.e////////////////////////////////////////
133 #ifndef SENF_PACKETS_DECL_ONLY
134 //#include "IPv6Packet.cci"
135 //#include "IPv6Packet.ct"
136 //#include "IPv6Packet.cti"
143 // c-file-style: "senf"
144 // indent-tabs-mode: nil
145 // ispell-local-dictionary: "american"
146 // compile-command: "scons -u test"
147 // comment-column: 40