removed some useless spaces; not very important, I know :)
[senf.git] / Socket / Protocols / Raw / MACAddress.cci
1 // $Id$
2 //
3 // Copyright (C) 2007
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 MACAddress inline non-template implementation */
25
26 // Custom includes
27 #include <algorithm>
28 #include <boost/lambda/lambda.hpp>
29
30 #define prefix_ inline
31 ///////////////////////////////cci.p///////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::MACAddress
35
36 prefix_ senf::MACAddress::MACAddress()
37 {
38     std::fill(begin(),end(),0u);
39 }
40
41 prefix_ senf::MACAddress::MACAddress(senf::NoInit_t)
42 {}
43
44 prefix_ senf::MACAddress::MACAddress(boost::uint64_t v)
45 {
46     (*this)[0] = boost::uint8_t( v>>40 );
47     (*this)[1] = boost::uint8_t( v>>32 );
48     (*this)[2] = boost::uint8_t( v>>24 );
49     (*this)[3] = boost::uint8_t( v>>16 );
50     (*this)[4] = boost::uint8_t( v>> 8 );
51     (*this)[5] = boost::uint8_t( v     );
52 }
53
54 prefix_ bool senf::MACAddress::local()
55     const
56 {
57     return (*this)[0] & 0x02;
58 }
59
60 prefix_ bool senf::MACAddress::multicast()
61     const
62 {
63     return (*this)[0] & 0x01;
64 }
65
66 prefix_ bool senf::MACAddress::broadcast()
67     const
68 {
69     using  boost::lambda::_1;
70     return std::find_if(begin(),end(), _1 != 0xffu) == end();
71 }
72
73 prefix_ bool senf::MACAddress::boolean_test()
74     const
75 {
76     using boost::lambda::_1;
77     return std::find_if(begin(),end(), _1 != 0x00u) != end();
78 }
79
80 prefix_ boost::uint32_t senf::MACAddress::oui()
81     const
82 {
83     return 
84         (boost::uint32_t((*this)[0])<<16) | 
85         (boost::uint32_t((*this)[1])<<8) | 
86         (*this)[2];
87 }
88
89 prefix_ boost::uint32_t senf::MACAddress::nic()
90     const
91 {
92     return 
93         (boost::uint32_t((*this)[3])<<16) | 
94         (boost::uint32_t((*this)[4])<<8) | 
95         (*this)[5];
96 }
97
98 prefix_ boost::uint64_t senf::MACAddress::eui64()
99     const
100 {
101     return
102         (boost::uint64_t( (*this)[0] ) << 56) | 
103         (boost::uint64_t( (*this)[1] ) << 48) | 
104         (boost::uint64_t( (*this)[2] ) << 40) | 
105         (boost::uint64_t( 0xfffe     ) << 24) |
106         (boost::uint64_t( (*this)[3] ) << 16) | 
107         (boost::uint64_t( (*this)[4] ) <<  8) | 
108         (boost::uint64_t( (*this)[5] )      );
109 }
110
111 ///////////////////////////////cci.e///////////////////////////////////////
112 #undef prefix_
113
114 \f
115 // Local Variables:
116 // mode: c++
117 // fill-column: 100
118 // comment-column: 40
119 // c-file-style: "senf"
120 // indent-tabs-mode: nil
121 // ispell-local-dictionary: "american"
122 // compile-command: "scons -u test"
123 // End: