Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Socket / Protocols / Raw / MACAddress.cci
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.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 /** \file
24     \brief MACAddress inline non-template implementation */
25
26 // Custom includes
27 #include <algorithm>
28 #include <boost/lambda/lambda.hpp>
29 #include "EUI64.hh"
30
31 #define prefix_ inline
32 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35 // senf::MACAddress
36
37 prefix_ senf::MACAddress::MACAddress()
38 {
39     std::fill(begin(),end(),0u);
40 }
41
42 prefix_ senf::MACAddress::MACAddress(senf::NoInit_t)
43 {}
44
45 prefix_ senf::MACAddress::MACAddress(boost::uint64_t v)
46 {
47     (*this)[0] = boost::uint8_t( v>>40 );
48     (*this)[1] = boost::uint8_t( v>>32 );
49     (*this)[2] = boost::uint8_t( v>>24 );
50     (*this)[3] = boost::uint8_t( v>>16 );
51     (*this)[4] = boost::uint8_t( v>> 8 );
52     (*this)[5] = boost::uint8_t( v     );
53 }
54
55 prefix_ bool senf::MACAddress::local()
56     const
57 {
58     return (*this)[0] & 0x02;
59 }
60
61 prefix_ bool senf::MACAddress::multicast()
62     const
63 {
64     return (*this)[0] & 0x01;
65 }
66
67 prefix_ bool senf::MACAddress::broadcast()
68     const
69 {
70     using  boost::lambda::_1;
71     return std::find_if(begin(),end(), _1 != 0xffu) == end();
72 }
73
74 prefix_ bool senf::MACAddress::boolean_test()
75     const
76 {
77     using boost::lambda::_1;
78     return std::find_if(begin(),end(), _1 != 0x00u) != end();
79 }
80
81 prefix_ boost::uint32_t senf::MACAddress::oui()
82     const
83 {
84     return
85         (boost::uint32_t((*this)[0])<<16) |
86         (boost::uint32_t((*this)[1])<<8) |
87         (*this)[2];
88 }
89
90 prefix_ boost::uint32_t senf::MACAddress::nic()
91     const
92 {
93     return
94         (boost::uint32_t((*this)[3])<<16) |
95         (boost::uint32_t((*this)[4])<<8) |
96         (*this)[5];
97 }
98
99 prefix_ boost::uint64_t senf::MACAddress::eui64()
100     const
101 {
102     return
103         (boost::uint64_t( (*this)[0] ) << 56) |
104         (boost::uint64_t( (*this)[1] ) << 48) |
105         (boost::uint64_t( (*this)[2] ) << 40) |
106         (boost::uint64_t( 0xfffe     ) << 24) |
107         (boost::uint64_t( (*this)[3] ) << 16) |
108         (boost::uint64_t( (*this)[4] ) <<  8) |
109         (boost::uint64_t( (*this)[5] )      );
110 }
111
112 prefix_ boost::uint64_t senf::MACAddress::uint64()
113     const
114 {
115     return
116         (boost::uint64_t( (*this)[0] ) << 40) |
117         (boost::uint64_t( (*this)[1] ) << 32) |
118         (boost::uint64_t( (*this)[2] ) << 24) |
119         (boost::uint64_t( (*this)[3] ) << 16) |
120         (boost::uint64_t( (*this)[4] ) <<  8) |
121         (boost::uint64_t( (*this)[5] )      );
122 }
123
124 prefix_ bool senf::operator==(MACAddress const & mac, EUI64 const & eui64)
125 {
126     return eui64.isMACCompatible()
127         && std::equal(eui64.begin(), eui64.begin()+3, mac.begin())
128         && std::equal(eui64.begin()+5, eui64.end(), mac.begin()+3);
129 }
130
131 prefix_ bool senf::operator==(EUI64 const & eui64, MACAddress const & mac)
132 {
133     return mac == eui64;
134 }
135
136 //-/////////////////////////////////////////////////////////////////////////////////////////////////
137 #undef prefix_
138
139
140 // Local Variables:
141 // mode: c++
142 // fill-column: 100
143 // comment-column: 40
144 // c-file-style: "senf"
145 // indent-tabs-mode: nil
146 // ispell-local-dictionary: "american"
147 // compile-command: "scons -u test"
148 // End: