4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
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
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.
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.
19 // The Original Code is Fraunhofer FOKUS code.
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.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief EthernetPacket non-inline non-template implementation */
31 #include "EthernetPacket.hh"
32 //#include "EthernetPacket.ih"
35 #include "LlcSnapPacket.hh"
37 #include <boost/io/ios_state.hpp>
38 #include <senf/Utils/Format.hh>
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44 SENF_PACKET_REGISTRY_REGISTER( senf::EtherTypes, 0x8100, senf::EthVLanPacket);
47 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 // senf::EthernetPacketType
50 prefix_ void senf::EthernetPacketType::dump(packet p, std::ostream & os)
52 boost::io::ios_all_saver ias(os);
53 if (p->type_length() <= 1500)
54 os << "Ethernet 802.3";
55 else if (p->type_length() >= 0x600)
56 os << "Ethernet II (DIX)";
58 os << "Ethernet 802.3 (bad ethertype >1500 and <1536)";
60 << senf::fieldName("destination") << p->destination() << "\n"
61 << senf::fieldName("source") << p->source() << "\n"
62 << senf::fieldName("type/length") << senf::format::dumpint(p->type_length().value()) << "\n";
65 prefix_ senf::PacketInterpreterBase::factory_t senf::EthernetPacketType::nextPacketType(packet p)
67 if (p->type_length() >= 1536) return lookup(p->type_length());
68 else if (p->type_length() <= 1500) return LlcSnapPacket::factory();
69 else return no_factory();
72 prefix_ void senf::EthernetPacketType::finalize(packet p)
74 Packet n (p.next(nothrow));
76 optional_key_t k (key(n));
78 p->type_length() << k;
79 else if (n.is<LlcSnapPacket>())
80 p->type_length() << n.data().size();
82 // Do NOT reset type_length if the type is not known ... doing this will destroy read packets
85 prefix_ void senf::EthVLanPacketType::dump(packet p, std::ostream & os)
87 boost::io::ios_all_saver ias(os);
88 os << "Ethernet 802.1q (VLAN):\n"
89 << senf::fieldName("priority") << p->priority() << "\n"
90 << senf::fieldName("cfi") << p->cfi() << "\n"
91 << senf::fieldName("vlan-ID") << p->vlanId() << "\n"
92 << senf::fieldName("ethertype")
93 << " 0x" << std::hex << std::setw(4) << std::setfill('0') << std::right << p->type() << "\n";
96 prefix_ void senf::EthVLanPacketType::finalize(packet p)
98 p->type() << key(p.next(nothrow));
102 //-/////////////////////////////////////////////////////////////////////////////////////////////////
109 // c-file-style: "senf"
110 // indent-tabs-mode: nil
111 // ispell-local-dictionary: "american"
112 // compile-command: "scons -u test"
113 // comment-column: 40