4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief MACAddress inline non-template implementation */
33 #include <boost/lambda/lambda.hpp>
36 #define prefix_ inline
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 prefix_ senf::MACAddress::MACAddress()
44 std::fill(begin(),end(),0u);
47 prefix_ senf::MACAddress::MACAddress(senf::NoInit_t)
50 prefix_ senf::MACAddress::MACAddress(boost::uint64_t v)
52 (*this)[0] = boost::uint8_t( v>>40 );
53 (*this)[1] = boost::uint8_t( v>>32 );
54 (*this)[2] = boost::uint8_t( v>>24 );
55 (*this)[3] = boost::uint8_t( v>>16 );
56 (*this)[4] = boost::uint8_t( v>> 8 );
57 (*this)[5] = boost::uint8_t( v );
60 prefix_ bool senf::MACAddress::local()
63 return (*this)[0] & 0x02;
66 prefix_ bool senf::MACAddress::multicast()
69 return (*this)[0] & 0x01;
72 prefix_ bool senf::MACAddress::broadcast()
75 using boost::lambda::_1;
76 return std::find_if(begin(),end(), _1 != 0xffu) == end();
79 prefix_ bool senf::MACAddress::boolean_test()
82 using boost::lambda::_1;
83 return std::find_if(begin(),end(), _1 != 0x00u) != end();
86 prefix_ boost::uint32_t senf::MACAddress::oui()
90 (boost::uint32_t((*this)[0])<<16) |
91 (boost::uint32_t((*this)[1])<<8) |
95 prefix_ boost::uint32_t senf::MACAddress::nic()
99 (boost::uint32_t((*this)[3])<<16) |
100 (boost::uint32_t((*this)[4])<<8) |
104 prefix_ boost::uint64_t senf::MACAddress::eui64()
108 (boost::uint64_t( (*this)[0] ) << 56) |
109 (boost::uint64_t( (*this)[1] ) << 48) |
110 (boost::uint64_t( (*this)[2] ) << 40) |
111 (boost::uint64_t( 0xfffe ) << 24) |
112 (boost::uint64_t( (*this)[3] ) << 16) |
113 (boost::uint64_t( (*this)[4] ) << 8) |
114 (boost::uint64_t( (*this)[5] ) );
117 prefix_ boost::uint64_t senf::MACAddress::uint64()
121 (boost::uint64_t( (*this)[0] ) << 40) |
122 (boost::uint64_t( (*this)[1] ) << 32) |
123 (boost::uint64_t( (*this)[2] ) << 24) |
124 (boost::uint64_t( (*this)[3] ) << 16) |
125 (boost::uint64_t( (*this)[4] ) << 8) |
126 (boost::uint64_t( (*this)[5] ) );
129 prefix_ bool senf::operator==(MACAddress const & mac, EUI64 const & eui64)
131 return eui64.isMACCompatible()
132 && std::equal(eui64.begin(), eui64.begin()+3, mac.begin())
133 && std::equal(eui64.begin()+5, eui64.end(), mac.begin()+3);
136 prefix_ bool senf::operator==(EUI64 const & eui64, MACAddress const & mac)
141 //-/////////////////////////////////////////////////////////////////////////////////////////////////
148 // comment-column: 40
149 // c-file-style: "senf"
150 // indent-tabs-mode: nil
151 // ispell-local-dictionary: "american"
152 // compile-command: "scons -u test"