94fbafcfacf52280fd4ec7e786b5b12ff1c6bd82
[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
32 //#include "IPv6Extensions.mpp"
33 #define prefix_
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35
36 namespace {
37     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 44,  senf::IPv6FragmentPacket           );
38     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 43,  senf::IPv6RoutingPacket            );
39     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 0u,  senf::IPv6HopByHopOptionsPacket    );
40     SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 60u, senf::IPv6DestinationOptionsPacket );
41 }
42
43 prefix_ void senf::IPv6FragmentPacketType::dump(packet p, std::ostream & os)
44 {
45     os << "Internet protocol Version 6 fragment extension:\n"
46        << senf::fieldName("next header")               << unsigned(p->nextHeader()) << "\n"
47        << senf::fieldName("fragment offset")
48        << "0x" << std::hex << unsigned(p->fragmentOffset()) << "\n"
49        << senf::fieldName("more fragments")            << (p->moreFragments()?"yes":"no") << "\n"
50        << senf::fieldName("id")
51        << "0x" << std::hex << unsigned(p->id()) << "\n";
52 }
53
54 prefix_ void senf::IPv6FragmentPacketType::finalize(packet p)
55 {
56     try {
57         p->nextHeader() << key(p.next());
58     }
59     catch (InvalidPacketChainException & ex) {
60         p->nextHeader() << 59; // No next header
61     }
62 }
63
64 prefix_ void senf::IPv6RoutingPacketType::dump(packet p, std::ostream & os)
65 {
66     os << "Internet protocol Version 6 routing extension:\n"
67        << senf::fieldName("next header")               << unsigned(p->nextHeader()) << "\n"
68        << senf::fieldName("header length")             << unsigned(p->headerLength()) << "\n"
69        << senf::fieldName("routing type")              << unsigned(p->routingType()) << "\n"
70        << senf::fieldName("segments left")             << unsigned(p->segmentsLeft()) << "\n"
71        << "  further Hop Addresses:\n";
72     typedef IPv6RoutingPacket::Parser::hopAddresses_t::container addrContainer_t;
73     addrContainer_t hopAddresses (p->hopAddresses());
74     if ( p->segmentsLeft() != 0 )
75         for (addrContainer_t::iterator i (hopAddresses.begin()); i != hopAddresses.end(); ++i)
76             os << "    " << *i << "\n";
77 }
78
79 prefix_ void senf::IPv6RoutingPacketType::finalize(packet p)
80 {
81     try {
82         p->nextHeader() << key(p.next());
83     }
84     catch (InvalidPacketChainException & ex) {
85         p->nextHeader() << 59; // No next header
86     }
87 }
88
89 prefix_ void senf::IPv6HopByHopOptionsPacketType::dump(packet p, std::ostream & os)
90 {
91     os << "Internet protocol Version 6 Hop-By-Hop extension:\n"
92        << senf::fieldName("next header")               << unsigned(p->nextHeader()) << "\n"
93        << senf::fieldName("header length")             << unsigned(p->headerLength()) <<" ("<< unsigned((1+p->headerLength())*8)<< ")\n";
94     os << "  OptionTypes:\n";
95     typedef IPv6HopByHopOptionsPacket::Parser::options_t::container optContainer_t;
96     optContainer_t options (p->options());
97     for (optContainer_t::const_iterator i = options.begin(); i != options.end(); ++i)
98         i->dump( os);
99 }
100
101 prefix_ void senf::IPv6HopByHopOptionsPacketType::finalize(packet p)
102 {
103     try {
104         p->nextHeader() << key(p.next());
105     }
106     catch (InvalidPacketChainException & ex) {
107         p->nextHeader() << 59; // No next header
108     }
109 }
110
111 prefix_ void senf::IPv6DestinationOptionsPacketType::dump(packet p, std::ostream & os)
112 {
113     os << "Internet protocol Version 6 Destination Options extension:\n"
114        << senf::fieldName("next header")               << unsigned (p->nextHeader()) << "\n"
115        << senf::fieldName("header length")             << unsigned (p->headerLength()) << "\n";
116     os << "  OptionTypes:\n";
117     typedef IPv6DestinationOptionsPacket::Parser::options_t::container optContainer_t;
118     optContainer_t options (p->options());
119     for (optContainer_t::const_iterator i = options.begin(); i != options.end(); ++i)
120         i->dump( os);
121 }
122
123 prefix_ void senf::IPv6DestinationOptionsPacketType::finalize(packet p)
124 {
125     try {
126         p->nextHeader() << key(p.next());
127     }
128     catch (InvalidPacketChainException & ex) {
129         p->nextHeader() << 59; // No next header
130     }
131 }
132
133
134 //-/////////////////////////////////////////////////////////////////////////////////////////////////
135 #undef prefix_
136 //#include "IPv6Extensions.mpp"
137
138 \f
139 // Local Variables:
140 // mode: c++
141 // fill-column: 100
142 // c-file-style: "senf"
143 // indent-tabs-mode: nil
144 // ispell-local-dictionary: "american"
145 // compile-command: "scons -u test"
146 // comment-column: 40
147 // End: