EUI64.cci
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief EUI64 inline non-template implementation */
16 
17 //#include "EUI64.ih"
18 
19 // Custom includes
20 #include <algorithm>
21 #include <boost/lambda/lambda.hpp>
22 #include "MACAddress.hh"
23 
24 #define prefix_ inline
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
27 prefix_ senf::EUI64::EUI64(boost::uint64_t v)
28 {
29  (*this)[0] = (v>>56) & 0xffu;
30  (*this)[1] = (v>>48) & 0xffu;
31  (*this)[2] = (v>>40) & 0xffu;
32  (*this)[3] = (v>>32) & 0xffu;
33  (*this)[4] = (v>>24) & 0xffu;
34  (*this)[5] = (v>>16) & 0xffu;
35  (*this)[6] = (v>> 8) & 0xffu;
36  (*this)[7] = (v ) & 0xffu;
37 }
38 
39 prefix_ senf::EUI64::EUI64(senf::NoInit_t)
40 {}
41 
42 prefix_ senf::EUI64 senf::EUI64::from_mac(MACAddress const & mac)
43 {
44  EUI64 eui (senf::noinit);
45  eui[0] = mac[0];
46  eui[1] = mac[1];
47  eui[2] = mac[2];
48  eui[3] = 0xffu;
49  eui[4] = 0xfeu;
50  eui[5] = mac[3];
51  eui[6] = mac[4];
52  eui[7] = mac[5];
53  return eui;
54 }
55 
56 prefix_ bool senf::EUI64::isMACCompatible()
57  const
58 {
59  return (*this)[3] == 0xffu && (*this)[4] == 0xfeu;
60 }
61 
62 prefix_ bool senf::EUI64::local()
63  const
64 {
65  return (*this)[0]&0x02;
66 }
67 
68 prefix_ bool senf::EUI64::group()
69  const
70 {
71  return (*this)[0]&0x01;
72 }
73 
74 prefix_ senf::EUI64::operator bool()
75  const
76 {
77  using boost::lambda::_1;
78  return std::find_if(begin(),end(), _1 != 0x00u) != end();
79 }
80 
81 prefix_ boost::uint64_t senf::EUI64::uint64()
82  const
83 {
84  return (boost::uint64_t((*this)[0])<<56)
85  | (boost::uint64_t((*this)[1])<<48)
86  | (boost::uint64_t((*this)[2])<<40)
87  | (boost::uint64_t((*this)[3])<<32)
88  | (boost::uint64_t((*this)[4])<<24)
89  | (boost::uint64_t((*this)[5])<<16)
90  | (boost::uint64_t((*this)[6])<< 8)
91  | (boost::uint64_t((*this)[7]) );
92 }
93 
94 //-/////////////////////////////////////////////////////////////////////////////////////////////////
95 #undef prefix_
96 
97 
98 // Local Variables:
99 // mode: c++
100 // fill-column: 100
101 // comment-column: 40
102 // c-file-style: "senf"
103 // indent-tabs-mode: nil
104 // ispell-local-dictionary: "american"
105 // compile-command: "scons -u test"
106 // End: