X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FEthernetPacket.cc;h=eced314dfbf220a377a5185d6b4b890073238f6c;hb=6a3a31fb7b2d2a5e8ae6d67d50797700274fb34e;hp=aef7dca1c34daae0ee139dd929fb1570975007f0;hpb=145f6a7d0f3a6aaa77b3625351c952d24cb0b8a1;p=senf.git diff --git a/Packets/DefaultBundle/EthernetPacket.cc b/Packets/DefaultBundle/EthernetPacket.cc index aef7dca..eced314 100644 --- a/Packets/DefaultBundle/EthernetPacket.cc +++ b/Packets/DefaultBundle/EthernetPacket.cc @@ -20,14 +20,15 @@ // 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 -#include +#include #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// @@ -37,71 +38,84 @@ namespace { registerEthVLanPacket(0x8100); } -prefix_ void senf::EthernetPacket::v_nextInterpreter() - const +/////////////////////////////////////////////////////////////////////////// +// senf::EthernetPacketType + +prefix_ void senf::EthernetPacketType::dump(packet p, std::ostream & os) { - /** \todo Add LLC/SNAP support -> only use the registry - for type() values >=1536, otherwise expect an LLC header */ - registerInterpreter(type(),begin()+bytes(),end()); + boost::io::ios_all_saver ias(os); + if (p->type_length() <= 1500) + os << "Ethernet 802.3"; + else if (p->type_length() >= 0x600) + os << "Ethernet II (DIX)"; + else + os << "Ethernet 802.3 (bad ethertype >1500 and <1536)"; + os << ": \n" + << " destination : " << p->destination() << "\n" + << " source : " << p->source() << "\n" + << " type/length : 0x" + << std::hex << std::setw(4) << std::setfill('0') << p->type_length() << "\n"; } -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]); - } +prefix_ senf::PacketInterpreterBase::factory_t senf::EthernetPacketType::nextPacketType(packet p) +{ + if (p->type_length() >= 1536) { + PkReg_Entry const * e; + e = PacketRegistry::lookup( p->type_length(), nothrow ); + return e ? e->factory() : no_factory(); } - + if (p->type_length() <= 1500) + return EthLlcSnapPacket::factory(); + return no_factory(); } -prefix_ void senf::EthernetPacket::v_dump(std::ostream & os) - const +prefix_ void senf::EthernetPacketType::finalize(packet p) { - if (type() <= 1500) - os << "Ethernet 802.3"; - else if (type() >= 0x600) - os << "Ethernet II (DIX)"; + optional_registry_key_t k = key(p.next()); + if (k) + p->type_length() << k; 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; + if (p.next().is()) + p->type_length() << p.next().data().size(); + else + p->type_length() << 0; } -prefix_ void senf::EthernetPacket::v_finalize() -{} +prefix_ void senf::EthVLanPacketType::dump(packet p, std::ostream & os) +{ + boost::io::ios_all_saver ias(os); + os << "Ethernet 802.1q (VLAN):\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::EthVLanPacket::v_nextInterpreter() - const +prefix_ void senf::EthVLanPacketType::finalize(packet p) { - /** \todo Add LLC/SNAP support (see above) */ - registerInterpreter(type(),begin()+bytes(),end()); + p->type() << key(p.next()); } -prefix_ void senf::EthVLanPacket::v_finalize() -{} +prefix_ void senf::EthLlcSnapPacketType::dump(packet p, std::ostream & os) +{ + boost::io::ios_all_saver ias(os); + os << "Ethernet LLC/SNAP" + << " LLC\n" + << " DSAP: " << p->dsap() << "\n" + << " SSAP: " << p->ssap() << "\n" + << " SNAP\n" + << " ProtocolId: " << p->protocolId() << "\n" + << " type : 0x" + << std::hex << std::setw(4) << std::setfill('0') << p->type() << "\n"; +} -prefix_ void senf::EthVLanPacket::v_dump(std::ostream & os) - const +prefix_ void senf::EthLlcSnapPacketType::finalize(packet p) { - os << "Ethernet 802.1q (VLAN):\n" - << " priority : " << priority() << "\n" - << " cfi : " << cfi() << "\n" - << " vlan-ID : " << vlanId() << "\n" - << " ethertype : " << boost::format("%04x") % type() << "\n"; + p->type() << key(p.next()); } + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_