03ab5be0a20e8b9c8ba098a6bc836894420580f0
[senf.git] / senf / Packets / DefaultBundle / IPv6Extensions.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //     Philipp Batroff <philipp.batroff@fokus.fraunhofer.de>
8 //
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the
21 // Free Software Foundation, Inc.,
22 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
24 /** \file
25     \brief IPv6Extensions non-inline non-template implementation */
26
27 #include "IPv6Extensions.hh"
28 //#include "IPv6Extensions.ih"
29
30 // Custom includes
31 #include <senf/Utils/hexdump.hh>
32
33 //#include "IPv6Extensions.mpp"
34 #define prefix_
35 ///////////////////////////////cc.p////////////////////////////////////////
36
37 namespace {
38     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 44,  senf::IPv6FragmentPacket           );
39     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 43,  senf::IPv6RoutingPacket            );
40     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 0u,  senf::IPv6HopByHopOptionsPacket    );
41     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 60u, senf::IPv6DestinationOptionsPacket );
42 }
43
44 prefix_ void senf::IPv6FragmentPacketType::dump(packet p, std::ostream & os)
45 {
46     os << "Internet protocol Version 6 fragment extension:\n"
47        << senf::fieldName("next header")               << unsigned(p->nextHeader()) << "\n"
48        << senf::fieldName("fragment offset")
49        << "0x" << std::hex << unsigned(p->fragmentOffset()) << "\n"
50        << senf::fieldName("more fragments")            << (p->moreFragments()?"yes":"no") << "\n"
51        << senf::fieldName("id")
52        << "0x" << std::hex << unsigned(p->id()) << "\n";
53 }
54
55 prefix_ void senf::IPv6FragmentPacketType::finalize(packet p)
56 {
57     try {
58         p->nextHeader() << key(p.next());
59     }
60     catch (InvalidPacketChainException & ex) {
61         p->nextHeader() << 59; // No next header
62     }
63 }
64
65 prefix_ void senf::IPv6RoutingPacketType::dump(packet p, std::ostream & os)
66 {
67     os << "Internet protocol Version 6 routing extension:\n"
68        << senf::fieldName("next header")               << unsigned(p->nextHeader()) << "\n"
69        << senf::fieldName("header length")             << unsigned(p->headerLength()) << "\n"
70        << senf::fieldName("routing type")              << unsigned(p->routingType()) << "\n"
71        << senf::fieldName("segments left")             << unsigned(p->segmentsLeft()) << "\n"
72        << "  further Hop Addresses:\n";
73     typedef IPv6RoutingPacket::Parser::hopAddresses_t::container addrContainer_t;
74     addrContainer_t hopAddresses (p->hopAddresses());
75     if ( p->segmentsLeft() != 0 )
76         for (addrContainer_t::iterator i (hopAddresses.begin()); i != hopAddresses.end(); ++i)
77             os << "    " << *i << "\n";
78 }
79
80 prefix_ void senf::IPv6RoutingPacketType::finalize(packet p)
81 {
82     try {
83         p->nextHeader() << key(p.next());
84     }
85     catch (InvalidPacketChainException & ex) {
86         p->nextHeader() << 59; // No next header
87     }
88 }
89
90 prefix_ void senf::IPv6HopByHopOptionsPacketType::dump(packet p, std::ostream & os)
91 {
92     os << "Internet protocol Version 6 Hop-By-Hop extension:\n"
93        << senf::fieldName("next header")               << unsigned(p->nextHeader()) << "\n"
94        << senf::fieldName("header length")             << unsigned(p->headerLength()) <<" ("<< unsigned((1+p->headerLength())*8)<< ")\n";
95     os << "  OptionTypes:\n";
96     typedef IPv6HopByHopOptionsPacket::Parser::options_t::container optContainer_t;
97     optContainer_t options (p->options());
98     for (optContainer_t::const_iterator i = options.begin(); i != options.end(); ++i)
99         i->dump( os);
100 }
101
102 prefix_ void senf::IPv6HopByHopOptionsPacketType::finalize(packet p)
103 {
104     try {
105         p->nextHeader() << key(p.next());
106     }
107     catch (InvalidPacketChainException & ex) {
108         p->nextHeader() << 59; // No next header
109     }
110 }
111
112 prefix_ void senf::IPv6DestinationOptionsPacketType::dump(packet p, std::ostream & os)
113 {
114     os << "Internet protocol Version 6 Destination Options extension:\n"
115        << senf::fieldName("next header")               << unsigned (p->nextHeader()) << "\n"
116        << senf::fieldName("header length")             << unsigned (p->headerLength()) << "\n";
117     os << "  OptionTypes:\n";
118     typedef IPv6DestinationOptionsPacket::Parser::options_t::container optContainer_t;
119     optContainer_t options (p->options());
120     for (optContainer_t::const_iterator i = options.begin(); i != options.end(); ++i)
121         i->dump( os);
122 }
123
124 prefix_ void senf::IPv6DestinationOptionsPacketType::finalize(packet p)
125 {
126     try {
127         p->nextHeader() << key(p.next());
128     }
129     catch (InvalidPacketChainException & ex) {
130         p->nextHeader() << 59; // No next header
131     }
132 }
133
134
135 ///////////////////////////////cc.e////////////////////////////////////////
136 #undef prefix_
137 //#include "IPv6Extensions.mpp"
138
139 \f
140 // Local Variables:
141 // mode: c++
142 // fill-column: 100
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
148 // End: