4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.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 MACAddress inline non-template implementation */
28 #include <boost/lambda/lambda.hpp>
31 #define prefix_ inline
32 ///////////////////////////////cci.p///////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////
37 prefix_ senf::MACAddress::MACAddress()
39 std::fill(begin(),end(),0u);
42 prefix_ senf::MACAddress::MACAddress(senf::NoInit_t)
45 prefix_ senf::MACAddress::MACAddress(boost::uint64_t v)
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 );
55 prefix_ bool senf::MACAddress::local()
58 return (*this)[0] & 0x02;
61 prefix_ bool senf::MACAddress::multicast()
64 return (*this)[0] & 0x01;
67 prefix_ bool senf::MACAddress::broadcast()
70 using boost::lambda::_1;
71 return std::find_if(begin(),end(), _1 != 0xffu) == end();
74 prefix_ bool senf::MACAddress::boolean_test()
77 using boost::lambda::_1;
78 return std::find_if(begin(),end(), _1 != 0x00u) != end();
81 prefix_ boost::uint32_t senf::MACAddress::oui()
85 (boost::uint32_t((*this)[0])<<16) |
86 (boost::uint32_t((*this)[1])<<8) |
90 prefix_ boost::uint32_t senf::MACAddress::nic()
94 (boost::uint32_t((*this)[3])<<16) |
95 (boost::uint32_t((*this)[4])<<8) |
99 prefix_ boost::uint64_t senf::MACAddress::eui64()
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] ) );
112 prefix_ boost::uint64_t senf::MACAddress::uint64()
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] ) );
124 prefix_ bool senf::operator==(MACAddress const & mac, EUI64 const & eui64)
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);
131 prefix_ bool senf::operator==(EUI64 const & eui64, MACAddress const & mac)
136 ///////////////////////////////cci.e///////////////////////////////////////
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"