EUI64.cci

Go to the documentation of this file.
00001 // $Id: EUI64.cci 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2009
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 //#include "EUI64.ih"
00027 
00028 // Custom includes
00029 #include <algorithm>
00030 #include <boost/lambda/lambda.hpp>
00031 #include "MACAddress.hh"
00032 
00033 #define prefix_ inline
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 
00036 prefix_ senf::EUI64::EUI64(boost::uint64_t v)
00037 {
00038     (*this)[0] = (v>>56) & 0xffu;
00039     (*this)[1] = (v>>48) & 0xffu;
00040     (*this)[2] = (v>>40) & 0xffu;
00041     (*this)[3] = (v>>32) & 0xffu;
00042     (*this)[4] = (v>>24) & 0xffu;
00043     (*this)[5] = (v>>16) & 0xffu;
00044     (*this)[6] = (v>> 8) & 0xffu;
00045     (*this)[7] = (v    ) & 0xffu;
00046 }
00047 
00048 prefix_ senf::EUI64::EUI64(senf::NoInit_t)
00049 {}
00050 
00051 prefix_ senf::EUI64 senf::EUI64::from_mac(MACAddress const & mac)
00052 {
00053     EUI64 eui (senf::noinit);
00054     eui[0] = mac[0];
00055     eui[1] = mac[1];
00056     eui[2] = mac[2];
00057     eui[3] = 0xffu;
00058     eui[4] = 0xfeu;
00059     eui[5] = mac[3];
00060     eui[6] = mac[4];
00061     eui[7] = mac[5];
00062     return eui;
00063 }
00064 
00065 prefix_ bool senf::EUI64::isMACCompatible()
00066     const
00067 {
00068     return (*this)[3] == 0xffu && (*this)[4] == 0xfeu;
00069 }
00070 
00071 prefix_ bool senf::EUI64::local()
00072     const
00073 {
00074     return (*this)[0]&0x02;
00075 }
00076 
00077 prefix_ bool senf::EUI64::group()
00078     const
00079 {
00080     return (*this)[0]&0x01;
00081 }
00082 
00083 prefix_ bool senf::EUI64::boolean_test()
00084     const
00085 {
00086     using boost::lambda::_1;
00087     return std::find_if(begin(),end(), _1 != 0x00u) != end();
00088 }
00089 
00090 prefix_ boost::uint64_t senf::EUI64::uint64()
00091     const
00092 {
00093     return (boost::uint64_t((*this)[0])<<56)
00094         |  (boost::uint64_t((*this)[1])<<48)
00095         |  (boost::uint64_t((*this)[2])<<40)
00096         |  (boost::uint64_t((*this)[3])<<32)
00097         |  (boost::uint64_t((*this)[4])<<24)
00098         |  (boost::uint64_t((*this)[5])<<16)
00099         |  (boost::uint64_t((*this)[6])<< 8)
00100         |  (boost::uint64_t((*this)[7])    );
00101 }
00102 
00103 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00104 #undef prefix_
00105 
00106 
00107 // Local Variables:
00108 // mode: c++
00109 // fill-column: 100
00110 // comment-column: 40
00111 // c-file-style: "senf"
00112 // indent-tabs-mode: nil
00113 // ispell-local-dictionary: "american"
00114 // compile-command: "scons -u test"
00115 // End: