4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief EthernetPacket non-inline non-template implementation */
26 #include "EthernetPacket.hh"
27 //#include "EthernetPacket.ih"
31 #include <boost/io/ios_state.hpp>
32 #include <boost/tokenizer.hpp>
35 ///////////////////////////////cc.p////////////////////////////////////////
38 senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::EthVLanPacket>
39 registerEthVLanPacket(0x8100);
42 ///////////////////////////////////////////////////////////////////////////
46 senf::PacketParserBase::byte hexToNibble(char c)
49 throw senf::MACAddress::SyntaxException();
53 throw senf::MACAddress::SyntaxException();
57 throw senf::MACAddress::SyntaxException();
61 throw senf::MACAddress::SyntaxException();
64 template <class Range>
65 senf::PacketParserBase::byte hexToByte(Range const & range)
67 if (boost::size(range) != 2)
68 throw senf::MACAddress::SyntaxException();
69 typename boost::range_const_iterator<Range>::type i (boost::begin(range));
70 return hexToNibble(i[0])*16+hexToNibble(i[1]);
74 prefix_ senf::MACAddress::MACAddress(std::string addr)
76 typedef boost::char_separator<char> separator;
77 typedef boost::tokenizer<separator> tokenizer;
79 tokenizer tok (addr,sep);
80 tokenizer::iterator i (tok.begin());
81 tokenizer::iterator i_end (tok.end());
83 iterator j_end (end());
84 for (; i!=i_end && j!=j_end; ++i, ++j)
86 if (i!=i_end || j!=j_end)
87 throw SyntaxException();
90 ///////////////////////////////////////////////////////////////////////////
91 // senf::EthernetPacketType
94 void dumpmac(std::ostream & os, senf::MACAddress mac)
96 boost::io::ios_all_saver ias(os);
97 for (unsigned i = 0; i < 6; ++i) {
100 os << std::hex << std::setw(2) << std::setfill('0')
106 prefix_ void senf::EthernetPacketType::dump(packet p, std::ostream & os)
108 if (p->type() <= 1500)
109 os << "Ethernet 802.3";
110 else if (p->type() >= 0x600)
111 os << "Ethernet II (DIX)";
113 os << "Ethernet 802.3 (bad ethertype >1500 and <1536)";
115 << " destination : ";
116 dumpmac(os,p->destination());
119 dumpmac(os,p->source());
121 << " ethertype : " << std::hex << std::setw(4) << std::setfill('0')
122 << unsigned(p->type()) << "\n" << std::dec;
125 prefix_ void senf::EthVLanPacketType::dump(packet p, std::ostream & os)
127 os << "Ethernet 802.1q (VLAN):\n"
128 << " priority : " << p->priority() << "\n"
129 << " cfi : " << p->cfi() << "\n"
130 << " vlan-ID : " << p->vlanId() << "\n"
131 << " ethertype : " << std::hex << std::setw(4) << std::setfill('0')
132 << p->type() << "\n" << std::dec;
135 ///////////////////////////////cc.e////////////////////////////////////////
142 // c-file-style: "senf"
143 // indent-tabs-mode: nil
144 // ispell-local-dictionary: "american"
145 // compile-command: "scons -u test"
146 // comment-column: 40