221eef8a7b17aad357275ced351da26decd6efc1
[senf.git] / senf / Socket / Protocols / Raw / EUI64.cci
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief EUI64 inline non-template implementation */
25
26 //#include "EUI64.ih"
27
28 // Custom includes
29 #include <algorithm>
30 #include <boost/lambda/lambda.hpp>
31 #include "MACAddress.hh"
32
33 #define prefix_ inline
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35
36 prefix_ senf::EUI64::EUI64(boost::uint64_t v)
37 {
38     (*this)[0] = (v>>56) & 0xffu;
39     (*this)[1] = (v>>48) & 0xffu;
40     (*this)[2] = (v>>40) & 0xffu;
41     (*this)[3] = (v>>32) & 0xffu;
42     (*this)[4] = (v>>24) & 0xffu;
43     (*this)[5] = (v>>16) & 0xffu;
44     (*this)[6] = (v>> 8) & 0xffu;
45     (*this)[7] = (v    ) & 0xffu;
46 }
47
48 prefix_ senf::EUI64::EUI64(senf::NoInit_t)
49 {}
50
51 prefix_ senf::EUI64 senf::EUI64::from_mac(MACAddress const & mac)
52 {
53     EUI64 eui (senf::noinit);
54     eui[0] = mac[0];
55     eui[1] = mac[1];
56     eui[2] = mac[2];
57     eui[3] = 0xffu;
58     eui[4] = 0xfeu;
59     eui[5] = mac[3];
60     eui[6] = mac[4];
61     eui[7] = mac[5];
62     return eui;
63 }
64
65 prefix_ bool senf::EUI64::isMACCompatible()
66     const
67 {
68     return (*this)[3] == 0xffu && (*this)[4] == 0xfeu;
69 }
70
71 prefix_ bool senf::EUI64::local()
72     const
73 {
74     return (*this)[0]&0x02;
75 }
76
77 prefix_ bool senf::EUI64::group()
78     const
79 {
80     return (*this)[0]&0x01;
81 }
82
83 prefix_ bool senf::EUI64::boolean_test()
84     const
85 {
86     using boost::lambda::_1;
87     return std::find_if(begin(),end(), _1 != 0x00u) != end();
88 }
89
90 prefix_ boost::uint64_t senf::EUI64::uint64()
91     const
92 {
93     return (boost::uint64_t((*this)[0])<<56)
94         |  (boost::uint64_t((*this)[1])<<48)
95         |  (boost::uint64_t((*this)[2])<<40)
96         |  (boost::uint64_t((*this)[3])<<32)
97         |  (boost::uint64_t((*this)[4])<<24)
98         |  (boost::uint64_t((*this)[5])<<16)
99         |  (boost::uint64_t((*this)[6])<< 8)
100         |  (boost::uint64_t((*this)[7])    );
101 }
102
103 //-/////////////////////////////////////////////////////////////////////////////////////////////////
104 #undef prefix_
105
106 \f
107 // Local Variables:
108 // mode: c++
109 // fill-column: 100
110 // comment-column: 40
111 // c-file-style: "senf"
112 // indent-tabs-mode: nil
113 // ispell-local-dictionary: "american"
114 // compile-command: "scons -u test"
115 // End: