X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FEthernetPacket.cc;h=78fe56c3746ad495b91a1ba6b9f7fd7548db9073;hb=d270abd20469df1cac466fe24d8dfa3dc119d987;hp=996f9297adbcf49d4b3dc2fa18a841e7c732a152;hpb=31d85cd6b8e03c5ecc924ca8892906be1bab702f;p=senf.git diff --git a/Packets/DefaultBundle/EthernetPacket.cc b/Packets/DefaultBundle/EthernetPacket.cc index 996f929..78fe56c 100644 --- a/Packets/DefaultBundle/EthernetPacket.cc +++ b/Packets/DefaultBundle/EthernetPacket.cc @@ -1,9 +1,9 @@ // $Id$ // // Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,14 +20,16 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// Definition of non-inline non-template functions +/** \file + \brief EthernetPacket non-inline non-template implementation */ #include "EthernetPacket.hh" //#include "EthernetPacket.ih" // Custom includes +#include "LlcSnapPacket.hh" #include -#include +#include #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// @@ -37,71 +39,62 @@ namespace { registerEthVLanPacket(0x8100); } -prefix_ void senf::EthernetPacket::v_nextInterpreter() - const -{ - /** \todo Add LLC/SNAP support -> only use the registry - for type() values >=1536, otherwise expect an LLC header */ - registerInterpreter(type(),begin()+bytes(),end()); -} - -namespace { - - void dumpmac(std::ostream & os, senf::EthernetPacket::Parse_MAC mac) - { - for (unsigned i = 0; i < 6; ++i) { - if (i > 0) - os << ':'; - os << std::hex << std::setw(2) << std::setfill('0') - << unsigned(mac[i]); - } - } - -} +/////////////////////////////////////////////////////////////////////////// +// senf::EthernetPacketType -prefix_ void senf::EthernetPacket::v_dump(std::ostream & os) - const +prefix_ void senf::EthernetPacketType::dump(packet p, std::ostream & os) { - if (type() <= 1500) + boost::io::ios_all_saver ias(os); + if (p->type_length() <= 1500) os << "Ethernet 802.3"; - else if (type() >= 0x600) + else if (p->type_length() >= 0x600) os << "Ethernet II (DIX)"; else os << "Ethernet 802.3 (bad ethertype >1500 and <1536)"; os << ": \n" - << " destination : "; - dumpmac(os,destination()); - os << "\n" - << " source : "; - dumpmac(os,source()); - os << "\n" - << " ethertype : " << std::hex << std::setw(4) << std::setfill('0') - << unsigned(type()) << "\n" << std::dec; + << " destination : " << p->destination() << "\n" + << " source : " << p->source() << "\n" + << " type/length : 0x" + << std::hex << std::setw(4) << std::setfill('0') << p->type_length() << "\n"; } -prefix_ void senf::EthernetPacket::v_finalize() -{} - -prefix_ void senf::EthVLanPacket::v_nextInterpreter() - const +prefix_ senf::PacketInterpreterBase::factory_t senf::EthernetPacketType::nextPacketType(packet p) { - /** \todo Add LLC/SNAP support (see above) */ - registerInterpreter(type(),begin()+bytes(),end()); + if (p->type_length() >= 1536) return lookup(p->type_length()); + else if (p->type_length() <= 1500) return LlcSnapPacket::factory(); + else return no_factory(); } -prefix_ void senf::EthVLanPacket::v_finalize() -{} +prefix_ void senf::EthernetPacketType::finalize(packet p) +{ + Packet n (p.next(nothrow)); + if (n) { + optional_key_t k (key(n)); + if (k) + p->type_length() << k; + else if (n.is()) + p->type_length() << n.data().size(); + } + // Do NOT reset type_length if the type is not known ... doing this will destroy read packets +} -prefix_ void senf::EthVLanPacket::v_dump(std::ostream & os) - const +prefix_ void senf::EthVLanPacketType::dump(packet p, std::ostream & os) { + boost::io::ios_all_saver ias(os); os << "Ethernet 802.1q (VLAN):\n" - << " priority : " << priority() << "\n" - << " cfi : " << cfi() << "\n" - << " vlan-ID : " << vlanId() << "\n" - << " ethertype : " << boost::format("%04x") % type() << "\n"; + << " priority : " << p->priority() << "\n" + << " cfi : " << p->cfi() << "\n" + << " vlan-ID : " << p->vlanId() << "\n" + << " ethertype : 0x" + << std::hex << std::setw(4) << std::setfill('0') << p->type() << "\n"; } +prefix_ void senf::EthVLanPacketType::finalize(packet p) +{ + p->type() << key(p.next(nothrow)); +} + + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ @@ -113,4 +106,5 @@ prefix_ void senf::EthVLanPacket::v_dump(std::ostream & os) // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" +// comment-column: 40 // End: