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