switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / DefaultBundle / IPv6Extensions.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27 //   Philipp Batroff <pug@berlios.de>
28
29 /** \file
30     \brief IPv6Extensions non-inline non-template implementation */
31
32 #include "IPv6Extensions.hh"
33 //#include "IPv6Extensions.ih"
34
35 // Custom includes
36
37 //#include "IPv6Extensions.mpp"
38 #define prefix_
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 namespace {
42     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 44,  senf::IPv6FragmentPacket           );
43     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 43,  senf::IPv6RoutingPacket            );
44     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 0u,  senf::IPv6HopByHopOptionsPacket    );
45     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 60u, senf::IPv6DestinationOptionsPacket );
46 }
47
48 prefix_ void senf::IPv6FragmentPacketType::dump(packet p, std::ostream & os)
49 {
50     os << "Internet protocol Version 6 fragment extension:\n"
51        << senf::fieldName("next header")               << unsigned(p->nextHeader()) << "\n"
52        << senf::fieldName("fragment offset")
53        << "0x" << std::hex << unsigned(p->fragmentOffset()) << "\n"
54        << senf::fieldName("more fragments")            << (p->moreFragments()?"yes":"no") << "\n"
55        << senf::fieldName("id")
56        << "0x" << std::hex << unsigned(p->id()) << "\n";
57 }
58
59 prefix_ void senf::IPv6FragmentPacketType::finalize(packet p)
60 {
61     try {
62         p->nextHeader() << key(p.next());
63     }
64     catch (InvalidPacketChainException & ex) {
65         p->nextHeader() << 59; // No next header
66     }
67 }
68
69 prefix_ void senf::IPv6RoutingPacketType::dump(packet p, std::ostream & os)
70 {
71     os << "Internet protocol Version 6 routing extension:\n"
72        << senf::fieldName("next header")               << unsigned(p->nextHeader()) << "\n"
73        << senf::fieldName("header length")             << unsigned(p->headerLength()) << "\n"
74        << senf::fieldName("routing type")              << unsigned(p->routingType()) << "\n"
75        << senf::fieldName("segments left")             << unsigned(p->segmentsLeft()) << "\n"
76        << "  further Hop Addresses:\n";
77     typedef IPv6RoutingPacket::Parser::hopAddresses_t::container addrContainer_t;
78     addrContainer_t hopAddresses (p->hopAddresses());
79     if ( p->segmentsLeft() != 0 )
80         for (addrContainer_t::iterator i (hopAddresses.begin()); i != hopAddresses.end(); ++i)
81             os << "    " << *i << "\n";
82 }
83
84 prefix_ void senf::IPv6RoutingPacketType::finalize(packet p)
85 {
86     try {
87         p->nextHeader() << key(p.next());
88     }
89     catch (InvalidPacketChainException & ex) {
90         p->nextHeader() << 59; // No next header
91     }
92 }
93
94 prefix_ void senf::IPv6HopByHopOptionsPacketType::dump(packet p, std::ostream & os)
95 {
96     os << "Internet protocol Version 6 Hop-By-Hop extension:\n"
97        << senf::fieldName("next header")               << unsigned(p->nextHeader()) << "\n"
98        << senf::fieldName("header length")             << unsigned(p->headerLength()) <<" ("<< unsigned((1+p->headerLength())*8)<< ")\n";
99     os << "  OptionTypes:\n";
100     typedef IPv6HopByHopOptionsPacket::Parser::options_t::container optContainer_t;
101     optContainer_t options (p->options());
102     for (optContainer_t::const_iterator i = options.begin(); i != options.end(); ++i)
103         i->dump( os);
104 }
105
106 prefix_ void senf::IPv6HopByHopOptionsPacketType::finalize(packet p)
107 {
108     try {
109         p->nextHeader() << key(p.next());
110     }
111     catch (InvalidPacketChainException & ex) {
112         p->nextHeader() << 59; // No next header
113     }
114 }
115
116 prefix_ void senf::IPv6DestinationOptionsPacketType::dump(packet p, std::ostream & os)
117 {
118     os << "Internet protocol Version 6 Destination Options extension:\n"
119        << senf::fieldName("next header")               << unsigned (p->nextHeader()) << "\n"
120        << senf::fieldName("header length")             << unsigned (p->headerLength()) << "\n";
121     os << "  OptionTypes:\n";
122     typedef IPv6DestinationOptionsPacket::Parser::options_t::container optContainer_t;
123     optContainer_t options (p->options());
124     for (optContainer_t::const_iterator i = options.begin(); i != options.end(); ++i)
125         i->dump( os);
126 }
127
128 prefix_ void senf::IPv6DestinationOptionsPacketType::finalize(packet p)
129 {
130     try {
131         p->nextHeader() << key(p.next());
132     }
133     catch (InvalidPacketChainException & ex) {
134         p->nextHeader() << 59; // No next header
135     }
136 }
137
138
139 //-/////////////////////////////////////////////////////////////////////////////////////////////////
140 #undef prefix_
141 //#include "IPv6Extensions.mpp"
142
143 \f
144 // Local Variables:
145 // mode: c++
146 // fill-column: 100
147 // c-file-style: "senf"
148 // indent-tabs-mode: nil
149 // ispell-local-dictionary: "american"
150 // compile-command: "scons -u test"
151 // comment-column: 40
152 // End: