MACAddress.cci
Go to the documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026
00027 #include <algorithm>
00028 #include <boost/lambda/lambda.hpp>
00029 #include "EUI64.hh"
00030
00031 #define prefix_ inline
00032
00033
00034
00035
00036
00037 prefix_ senf::MACAddress::MACAddress()
00038 {
00039 std::fill(begin(),end(),0u);
00040 }
00041
00042 prefix_ senf::MACAddress::MACAddress(senf::NoInit_t)
00043 {}
00044
00045 prefix_ senf::MACAddress::MACAddress(boost::uint64_t v)
00046 {
00047 (*this)[0] = boost::uint8_t( v>>40 );
00048 (*this)[1] = boost::uint8_t( v>>32 );
00049 (*this)[2] = boost::uint8_t( v>>24 );
00050 (*this)[3] = boost::uint8_t( v>>16 );
00051 (*this)[4] = boost::uint8_t( v>> 8 );
00052 (*this)[5] = boost::uint8_t( v );
00053 }
00054
00055 prefix_ bool senf::MACAddress::local()
00056 const
00057 {
00058 return (*this)[0] & 0x02;
00059 }
00060
00061 prefix_ bool senf::MACAddress::multicast()
00062 const
00063 {
00064 return (*this)[0] & 0x01;
00065 }
00066
00067 prefix_ bool senf::MACAddress::broadcast()
00068 const
00069 {
00070 using boost::lambda::_1;
00071 return std::find_if(begin(),end(), _1 != 0xffu) == end();
00072 }
00073
00074 prefix_ bool senf::MACAddress::boolean_test()
00075 const
00076 {
00077 using boost::lambda::_1;
00078 return std::find_if(begin(),end(), _1 != 0x00u) != end();
00079 }
00080
00081 prefix_ boost::uint32_t senf::MACAddress::oui()
00082 const
00083 {
00084 return
00085 (boost::uint32_t((*this)[0])<<16) |
00086 (boost::uint32_t((*this)[1])<<8) |
00087 (*this)[2];
00088 }
00089
00090 prefix_ boost::uint32_t senf::MACAddress::nic()
00091 const
00092 {
00093 return
00094 (boost::uint32_t((*this)[3])<<16) |
00095 (boost::uint32_t((*this)[4])<<8) |
00096 (*this)[5];
00097 }
00098
00099 prefix_ boost::uint64_t senf::MACAddress::eui64()
00100 const
00101 {
00102 return
00103 (boost::uint64_t( (*this)[0] ) << 56) |
00104 (boost::uint64_t( (*this)[1] ) << 48) |
00105 (boost::uint64_t( (*this)[2] ) << 40) |
00106 (boost::uint64_t( 0xfffe ) << 24) |
00107 (boost::uint64_t( (*this)[3] ) << 16) |
00108 (boost::uint64_t( (*this)[4] ) << 8) |
00109 (boost::uint64_t( (*this)[5] ) );
00110 }
00111
00112 prefix_ boost::uint64_t senf::MACAddress::uint64()
00113 const
00114 {
00115 return
00116 (boost::uint64_t( (*this)[0] ) << 40) |
00117 (boost::uint64_t( (*this)[1] ) << 32) |
00118 (boost::uint64_t( (*this)[2] ) << 24) |
00119 (boost::uint64_t( (*this)[3] ) << 16) |
00120 (boost::uint64_t( (*this)[4] ) << 8) |
00121 (boost::uint64_t( (*this)[5] ) );
00122 }
00123
00124 prefix_ bool senf::operator==(MACAddress const & mac, EUI64 const & eui64)
00125 {
00126 return eui64.isMACCompatible()
00127 && std::equal(eui64.begin(), eui64.begin()+3, mac.begin())
00128 && std::equal(eui64.begin()+5, eui64.end(), mac.begin()+3);
00129 }
00130
00131 prefix_ bool senf::operator==(EUI64 const & eui64, MACAddress const & mac)
00132 {
00133 return mac == eui64;
00134 }
00135
00136
00137 #undef prefix_
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148