git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@129 270642c3-0616-0410...
[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     namespace pkf = satcom::pkf;
37     pkf::PacketRegistry<pkf::EtherTypes>::RegistrationProxy<pkf::EthVLanPacket> 
38         registerEthVLanPacket(0x8100);
39 }
40
41 prefix_ void satcom::pkf::EthernetPacket::v_nextInterpreter()
42     const
43 {
44     // TODO: Add LLC/SNAP support -> only use the registry
45     // for type() values >=1536, otherwise expect an LLC header
46     registerInterpreter(type(),begin()+bytes(),end());
47 }
48
49 namespace {
50     
51     void dumpmac(std::ostream & os, satcom::pkf::EthernetPacket::Parse_MAC mac)
52     {
53         for (unsigned i = 0; i < 6; ++i) {
54             if (i > 0) 
55                 os << ':';
56             os << std::hex << std::setw(2) << std::setfill('0')
57                << unsigned(mac[i]);
58         }
59     }
60
61 }
62
63 prefix_ void satcom::pkf::EthernetPacket::v_dump(std::ostream & os)
64     const
65 {
66     if (type() <= 1500)
67         os << "Ethernet 802.3";
68     else if (type() >= 0x600)
69         os << "Ethernet II (DIX)";
70     else 
71         os << "Ethernet 802.3 (bad ethertype >1500 and <1536)";
72     os << ": \n"
73        << "  destination   : ";
74     dumpmac(os,destination());
75     os << "\n"
76        << "  source        : ";
77     dumpmac(os,source());
78     os << "\n"
79        << "  ethertype     : " << std::hex << std::setw(4) << std::setfill('0')
80        << unsigned(type()) << "\n" << std::dec;
81 }
82
83 prefix_ void satcom::pkf::EthernetPacket::v_finalize()
84 {}
85
86 prefix_ void satcom::pkf::EthVLanPacket::v_nextInterpreter()
87     const
88 {
89     // TODO: Add LLC/SNAP support -> only use the registry
90     // for type() values >=1536, otherwise expect an LLC header
91     registerInterpreter(type(),begin()+bytes(),end());
92 }
93
94 prefix_ void satcom::pkf::EthVLanPacket::v_finalize()
95 {}
96
97 prefix_ void satcom::pkf::EthVLanPacket::v_dump(std::ostream & os)
98     const
99 {
100     os << "Ethernet 802.1q (VLAN):\n"
101        << "  priority      : " << priority() << "\n"
102        << "  cfi           : " << cfi() << "\n"
103        << "  vlan-ID       : " << vlanId() << "\n"
104        << "  ethertype     : " << boost::format("%04x") % type() << "\n";
105 }
106
107 ///////////////////////////////cc.e////////////////////////////////////////
108 #undef prefix_
109
110 \f
111 // Local Variables:
112 // mode: c++
113 // c-file-style: "satcom"
114 // End: