Skip to content
Snippets Groups Projects
EthernetPacket.cc 3.3 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.

// Definition of non-inline non-template functions

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

// Custom includes
#include <iomanip>
#include <boost/format.hpp>

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

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

prefix_ void senf::EthernetPacket::v_nextInterpreter()
sbund's avatar
sbund committed
    const
{
    /** \todo Add LLC/SNAP support -> only use the registry
        for type() values >=1536, otherwise expect an LLC header */
sbund's avatar
sbund committed
    registerInterpreter(type(),begin()+bytes(),end());
}

namespace {
    void dumpmac(std::ostream & os, senf::EthernetPacket::Parse_MAC mac)
sbund's avatar
sbund committed
    {
        for (unsigned i = 0; i < 6; ++i) {
            if (i > 0)
sbund's avatar
sbund committed
                os << ':';
            os << std::hex << std::setw(2) << std::setfill('0')
               << unsigned(mac[i]);
        }
    }

}

prefix_ void senf::EthernetPacket::v_dump(std::ostream & os)
sbund's avatar
sbund committed
    const
{
    if (type() <= 1500)
        os << "Ethernet 802.3";
    else if (type() >= 0x600)
        os << "Ethernet II (DIX)";
sbund's avatar
sbund committed
        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;
}

prefix_ void senf::EthernetPacket::v_finalize()
sbund's avatar
sbund committed
{}

prefix_ void senf::EthVLanPacket::v_nextInterpreter()
sbund's avatar
sbund committed
    const
{
    /** \todo Add LLC/SNAP support (see above) */
sbund's avatar
sbund committed
    registerInterpreter(type(),begin()+bytes(),end());
}

prefix_ void senf::EthVLanPacket::v_finalize()
sbund's avatar
sbund committed
{}

prefix_ void senf::EthVLanPacket::v_dump(std::ostream & os)
sbund's avatar
sbund committed
    const
{
    os << "Ethernet 802.1q (VLAN):\n"
       << "  priority      : " << priority() << "\n"
       << "  cfi           : " << cfi() << "\n"
       << "  vlan-ID       : " << vlanId() << "\n"
       << "  ethertype     : " << boost::format("%04x") % type() << "\n";
}

///////////////////////////////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: