switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / Protocols / Raw / EUI64.cci
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
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
10 //
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.
14 //
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.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
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.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief EUI64 inline non-template implementation */
30
31 //#include "EUI64.ih"
32
33 // Custom includes
34 #include <algorithm>
35 #include <boost/lambda/lambda.hpp>
36 #include "MACAddress.hh"
37
38 #define prefix_ inline
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 prefix_ senf::EUI64::EUI64(boost::uint64_t v)
42 {
43     (*this)[0] = (v>>56) & 0xffu;
44     (*this)[1] = (v>>48) & 0xffu;
45     (*this)[2] = (v>>40) & 0xffu;
46     (*this)[3] = (v>>32) & 0xffu;
47     (*this)[4] = (v>>24) & 0xffu;
48     (*this)[5] = (v>>16) & 0xffu;
49     (*this)[6] = (v>> 8) & 0xffu;
50     (*this)[7] = (v    ) & 0xffu;
51 }
52
53 prefix_ senf::EUI64::EUI64(senf::NoInit_t)
54 {}
55
56 prefix_ senf::EUI64 senf::EUI64::from_mac(MACAddress const & mac)
57 {
58     EUI64 eui (senf::noinit);
59     eui[0] = mac[0];
60     eui[1] = mac[1];
61     eui[2] = mac[2];
62     eui[3] = 0xffu;
63     eui[4] = 0xfeu;
64     eui[5] = mac[3];
65     eui[6] = mac[4];
66     eui[7] = mac[5];
67     return eui;
68 }
69
70 prefix_ bool senf::EUI64::isMACCompatible()
71     const
72 {
73     return (*this)[3] == 0xffu && (*this)[4] == 0xfeu;
74 }
75
76 prefix_ bool senf::EUI64::local()
77     const
78 {
79     return (*this)[0]&0x02;
80 }
81
82 prefix_ bool senf::EUI64::group()
83     const
84 {
85     return (*this)[0]&0x01;
86 }
87
88 prefix_ bool senf::EUI64::boolean_test()
89     const
90 {
91     using boost::lambda::_1;
92     return std::find_if(begin(),end(), _1 != 0x00u) != end();
93 }
94
95 prefix_ boost::uint64_t senf::EUI64::uint64()
96     const
97 {
98     return (boost::uint64_t((*this)[0])<<56)
99         |  (boost::uint64_t((*this)[1])<<48)
100         |  (boost::uint64_t((*this)[2])<<40)
101         |  (boost::uint64_t((*this)[3])<<32)
102         |  (boost::uint64_t((*this)[4])<<24)
103         |  (boost::uint64_t((*this)[5])<<16)
104         |  (boost::uint64_t((*this)[6])<< 8)
105         |  (boost::uint64_t((*this)[7])    );
106 }
107
108 //-/////////////////////////////////////////////////////////////////////////////////////////////////
109 #undef prefix_
110
111 \f
112 // Local Variables:
113 // mode: c++
114 // fill-column: 100
115 // comment-column: 40
116 // c-file-style: "senf"
117 // indent-tabs-mode: nil
118 // ispell-local-dictionary: "american"
119 // compile-command: "scons -u test"
120 // End: