IPv6Packet.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #include "IPv6Packet.hh"
18 //#include "IPv6Packet.ih"
19 
20 // Custom includes
21 #include <iomanip>
22 #include <boost/io/ios_state.hpp>
23 #include "EthernetPacket.hh"
24 
25 #define prefix_
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 
29 SENF_PACKET_REGISTRY_REGISTER( senf::IPTypes, 41, senf::IPv6Packet); // IP6-in-IP(6) encapsulation
30 
32 
33 prefix_ void senf::IPv6PacketType::dump(packet p, std::ostream & os)
34 {
35  boost::io::ios_all_saver ias(os);
36  os << "Internet protocol Version 6:\n"
37  << senf::fieldName("version") << unsigned(p->version()) << "\n"
38  << senf::fieldName("traffic class")
39  << "0x" << std::hex << std::setw(2) << std::setfill('0') << std::right << unsigned(p->trafficClass()) << "\n"
40  << senf::fieldName("flow label")
41  << "0x" << std::hex << std::setw(5) << std::setfill('0') << std::right << unsigned(p->flowLabel()) << "\n"
42  << senf::fieldName("payload length") << std::dec << unsigned(p->length()) << "\n"
43  << senf::fieldName("next header") << unsigned(p->nextHeader()) << "\n"
44  << senf::fieldName("hop limit") << unsigned(p->hopLimit()) << "\n"
45  << senf::fieldName("source") << p->source() << "\n"
46  << senf::fieldName("destination") << p->destination() << "\n";
47 }
48 
50 {
51  p->length() << (p.size() - IPv6PacketParser::fixed_bytes);
52  try {
53  p->nextHeader() << key(p.next());
54  }
55  catch (InvalidPacketChainException & ex) {
56  p->nextHeader() << 59; // No next header
57  }
58 }
59 
60 //-/////////////////////////////////////////////////////////////////////////////////////////////////
61 #undef prefix_
62 //#include "IPv6Packet.mpp"
63 
64 
65 // Local Variables:
66 // mode: c++
67 // fill-column: 100
68 // c-file-style: "senf"
69 // indent-tabs-mode: nil
70 // ispell-local-dictionary: "american"
71 // compile-command: "scons -u test"
72 // comment-column: 40
73 // End:
IPv6Packet public header.
EthernetPacket public header.
static optional_key_t key(Packet const &p)
Find key of packet from registry.
std::string fieldName(std::string const &s)
Definition: DumpFormat.cc:28
SENF_PACKET_REGISTRY_REGISTER(senf::EtherTypes, senf::IPv6PacketType::etherType, senf::IPv6Packet)
Protocol specific packet handle.
Definition: Packet.hh:87
Invalid packet chain operation.
Packet next() const
Get next packet in chain.
#define prefix_
Definition: IPv6Packet.cc:25
static const EtherTypes::key_t etherType
Definition: IPv6Packet.hh:133
EtherType registry.
Definition: Registries.hh:34
static void finalize(packet p)
Finalize packet.
Definition: IPv6Packet.cc:49
size_type size() const
Return size of packet in bytes.
static void dump(packet p, std::ostream &os)
Dump given IPv6Packet in readable form to given output stream.
Definition: IPv6Packet.cc:33
IP protocol number registry.
Definition: Registries.hh:60
SENF_PACKET_INSTANTIATE_TEMPLATE(senf::IPv6Packet)