Fixed whitespace in all files (no tabs)
[senf.git] / Packets / EthernetPacket.cc
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
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.
12 //
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.
17 //
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.
22
23 // Definition of non-inline non-template functions
24
25 #include "EthernetPacket.hh"
26 //#include "EthernetPacket.ih"
27
28 // Custom includes
29 #include <iomanip>
30 #include <boost/format.hpp>
31
32 #define prefix_
33 ///////////////////////////////cc.p////////////////////////////////////////
34
35 namespace {
36     senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::EthVLanPacket>
37         registerEthVLanPacket(0x8100);
38 }
39
40 prefix_ void senf::EthernetPacket::v_nextInterpreter()
41     const
42 {
43     /** \todo Add LLC/SNAP support -> only use the registry
44         for type() values >=1536, otherwise expect an LLC header */
45     registerInterpreter(type(),begin()+bytes(),end());
46 }
47
48 namespace {
49
50     void dumpmac(std::ostream & os, senf::EthernetPacket::Parse_MAC mac)
51     {
52         for (unsigned i = 0; i < 6; ++i) {
53             if (i > 0)
54                 os << ':';
55             os << std::hex << std::setw(2) << std::setfill('0')
56                << unsigned(mac[i]);
57         }
58     }
59
60 }
61
62 prefix_ void senf::EthernetPacket::v_dump(std::ostream & os)
63     const
64 {
65     if (type() <= 1500)
66         os << "Ethernet 802.3";
67     else if (type() >= 0x600)
68         os << "Ethernet II (DIX)";
69     else
70         os << "Ethernet 802.3 (bad ethertype >1500 and <1536)";
71     os << ": \n"
72        << "  destination   : ";
73     dumpmac(os,destination());
74     os << "\n"
75        << "  source        : ";
76     dumpmac(os,source());
77     os << "\n"
78        << "  ethertype     : " << std::hex << std::setw(4) << std::setfill('0')
79        << unsigned(type()) << "\n" << std::dec;
80 }
81
82 prefix_ void senf::EthernetPacket::v_finalize()
83 {}
84
85 prefix_ void senf::EthVLanPacket::v_nextInterpreter()
86     const
87 {
88     /** \todo Add LLC/SNAP support (see above) */
89     registerInterpreter(type(),begin()+bytes(),end());
90 }
91
92 prefix_ void senf::EthVLanPacket::v_finalize()
93 {}
94
95 prefix_ void senf::EthVLanPacket::v_dump(std::ostream & os)
96     const
97 {
98     os << "Ethernet 802.1q (VLAN):\n"
99        << "  priority      : " << priority() << "\n"
100        << "  cfi           : " << cfi() << "\n"
101        << "  vlan-ID       : " << vlanId() << "\n"
102        << "  ethertype     : " << boost::format("%04x") % type() << "\n";
103 }
104
105 ///////////////////////////////cc.e////////////////////////////////////////
106 #undef prefix_
107
108 \f
109 // Local Variables:
110 // mode: c++
111 // fill-column: 100
112 // c-file-style: "senf"
113 // indent-tabs-mode: nil
114 // ispell-local-dictionary: "american"
115 // End: