X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FEthernetPacket.cc;h=00ef6cb220992f9fefa282327a3bfa92fdd0f90a;hb=6ec7989c834d8e5064f505af9f3294679f62b18a;hp=99e61bb1f2b7e5a868721cdabb3486b0177da929;hpb=2d6585ff852e9d282c17003ba1db0b73eb3a8500;p=senf.git diff --git a/Packets/DefaultBundle/EthernetPacket.cc b/Packets/DefaultBundle/EthernetPacket.cc index 99e61bb..00ef6cb 100644 --- a/Packets/DefaultBundle/EthernetPacket.cc +++ b/Packets/DefaultBundle/EthernetPacket.cc @@ -20,15 +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//////////////////////////////////////// @@ -39,98 +40,64 @@ namespace { } /////////////////////////////////////////////////////////////////////////// -// senf::MACAddress - -namespace { - senf::PacketParserBase::byte hexToNibble(char c) - { - if (c<'0') - throw senf::MACAddress::SyntaxException(); - else if (c<='9') - return c-'-'; - else if (c<'A') - throw senf::MACAddress::SyntaxException(); - else if (c<='F') - return c-'A'+10; - else if (c<'a') - throw senf::MACAddress::SyntaxException(); - else if (c<='f') - return c-'a'+10; - else - throw senf::MACAddress::SyntaxException(); - } - - template - senf::PacketParserBase::byte hexToByte(Range const & range) - { - if (boost::size(range) != 2) - throw senf::MACAddress::SyntaxException(); - typename boost::range_const_iterator::type i (boost::begin(range)); - return hexToNibble(i[0])*16+hexToNibble(i[1]); - } -} - -prefix_ senf::MACAddress::MACAddress(std::string addr) -{ - typedef boost::char_separator separator; - typedef boost::tokenizer tokenizer; - separator sep (":"); - tokenizer tok (addr,sep); - tokenizer::iterator i (tok.begin()); - tokenizer::iterator i_end (tok.end()); - iterator j (begin()); - iterator j_end (end()); - for (; i!=i_end && j!=j_end; ++i, ++j) - *j = hexToByte(*i); - if (i!=i_end || j!=j_end) - throw SyntaxException(); -} - -/////////////////////////////////////////////////////////////////////////// // senf::EthernetPacketType -namespace { - void dumpmac(std::ostream & os, senf::MACAddress mac) - { - boost::io::ios_all_saver ias(os); - for (unsigned i = 0; i < 6; ++i) { - if (i > 0) - os << ':'; - os << std::hex << std::setw(2) << std::setfill('0') - << unsigned(mac[i]); - } - } -} - prefix_ void senf::EthernetPacketType::dump(packet p, std::ostream & os) { - if (p->type() <= 1500) + boost::io::ios_all_saver ias(os); + if (p->type_length() <= 1500) os << "Ethernet 802.3"; - else if (p->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,p->destination()); - os << "\n" - << " source : "; - dumpmac(os,p->source()); - os << "\n" - << " ethertype : " << std::hex << std::setw(4) << std::setfill('0') - << unsigned(p->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_ 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 LlcSnapPacket::factory(); + return no_factory(); +} + +prefix_ void senf::EthernetPacketType::finalize(packet p) +{ + optional_registry_key_t k = key(p.next()); + if (k) + p->type_length() << k; + else + if (p.next().is()) + p->type_length() << p.next().data().size(); + // Do NOT reset type_length if the type is not known ... doing this will destroy read packets } 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 : " << std::hex << std::setw(4) << std::setfill('0') - << p->type() << "\n" << std::dec; + << " 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()); } + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_