00001 // $Id: LlcSnapPacket.cc 1792 2011-06-09 15:49:59Z tho $ 00002 // 00003 // Copyright (C) 2007 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Thorsten Horstmann <tho@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00026 #include "LlcSnapPacket.hh" 00027 //#include "LlcSnapPacket.ih" 00028 00029 // Custom includes 00030 #include <iomanip> 00031 #include <boost/io/ios_state.hpp> 00032 00033 #define prefix_ 00034 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00035 00036 prefix_ void senf::LlcSnapPacketType::dump(packet p, std::ostream & os) 00037 { 00038 boost::io::ios_all_saver ias(os); 00039 os << "LLC/SNAP:\n" 00040 << std::hex << std::setfill('0') << std::right 00041 << " LLC\n" 00042 << senf::fieldName(" dsap") << "0x" << unsigned(p->dsap()) << "\n" 00043 << senf::fieldName(" ssap") << "0x" << unsigned(p->ssap()) << "\n" 00044 << senf::fieldName(" control id") << "0x" << unsigned(p->ctrl()) << "\n" 00045 << " SNAP\n" 00046 << senf::fieldName(" protocol id") << "0x" << std::setw(6) << unsigned(p->protocolId()) << "\n" 00047 << senf::fieldName(" type/length") << "0x" << std::setw(4) << unsigned(p->type_length()) << "\n"; 00048 } 00049 00050 prefix_ senf::PacketInterpreterBase::factory_t senf::LlcSnapPacketType::nextPacketType(packet p) 00051 { 00052 if (p->type_length() >= 1536) { 00053 PacketRegistry<senf::EtherTypes>::Entry const * e ( 00054 PacketRegistry<senf::EtherTypes>::lookup( p->type_length(), nothrow )); 00055 return e ? e->factory() : no_factory(); 00056 } 00057 if (p->type_length() <= 1500) 00058 return EthernetPacket::factory(); 00059 return no_factory(); 00060 } 00061 00062 prefix_ void senf::LlcSnapPacketType::finalize(packet p) 00063 { 00064 optional_key_t k (key(p.next(nothrow))); 00065 if (k) 00066 p->type_length() << k; 00067 else if (p.next().is<EthernetPacket>()) 00068 p->type_length() << p.next().data().size(); 00069 } 00070 00071 00072 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00073 #undef prefix_ 00074 00075 00076 // Local Variables: 00077 // mode: c++ 00078 // fill-column: 100 00079 // c-file-style: "senf" 00080 // indent-tabs-mode: nil 00081 // ispell-local-dictionary: "american" 00082 // compile-command: "scons -u test" 00083 // comment-column: 40 00084 // End: