Skip to content
Snippets Groups Projects
EthernetPacket.cc 3.58 KiB
Newer Older
sbund's avatar
sbund committed
// $Id$
//
// Copyright (C) 2006
sbund's avatar
sbund committed
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
//
// 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
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

/** \file
    \brief EthernetPacket non-inline non-template implementation */
sbund's avatar
sbund committed

#include "EthernetPacket.hh"
//#include "EthernetPacket.ih"

// Custom includes
sbund's avatar
sbund committed
#include <iomanip>
#include <boost/io/ios_state.hpp>
sbund's avatar
sbund committed

#define prefix_
///////////////////////////////cc.p////////////////////////////////////////

namespace {
    senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::EthVLanPacket>
sbund's avatar
sbund committed
        registerEthVLanPacket(0x8100);
}

///////////////////////////////////////////////////////////////////////////
// senf::EthernetPacketType
prefix_ void senf::EthernetPacketType::dump(packet p, std::ostream & os)
sbund's avatar
sbund committed
{
    boost::io::ios_all_saver ias(os);
    if (p->type_length() <= 1500)
sbund's avatar
sbund committed
        os << "Ethernet 802.3";
    else if (p->type_length() >= 0x600)
sbund's avatar
sbund committed
        os << "Ethernet II (DIX)";
sbund's avatar
sbund committed
        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";
}

prefix_ senf::PacketInterpreterBase::factory_t senf::EthernetPacketType::nextPacketType(packet p)
{
    if (p->type_length() >= 1536) {
        PkReg_Entry const * e;
        e = PacketRegistry<senf::EtherTypes>::lookup( p->type_length(), nothrow );
        return e ? e->factory() : no_factory();
    }
    if (p->type_length() <= 1500)
        return LlcSnapPacket::factory();
    return no_factory();
sbund's avatar
sbund committed
}

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<LlcSnapPacket>())
            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)
sbund's avatar
sbund committed
{
    boost::io::ios_all_saver ias(os);
sbund's avatar
sbund committed
    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";
sbund's avatar
sbund committed
}

prefix_ void senf::EthVLanPacketType::finalize(packet p)
{
    p->type() << key(p.next());
}

sbund's avatar
sbund committed
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_


// Local Variables:
// mode: c++
// fill-column: 100
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u test"
// comment-column: 40
sbund's avatar
sbund committed
// End: