Socket/Protocols/INet: Implement INet4Address add rename old INet4Address to INet4Soc...
[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_ senf::MACAddress::MACAddress(boost::uint64_t v)
43 {
44     (*this)[0] = boost::uint8_t( v>>40 );
45     (*this)[1] = boost::uint8_t( v>>32 );
46     (*this)[2] = boost::uint8_t( v>>24 );
47     (*this)[3] = boost::uint8_t( v>>16 );
48     (*this)[4] = boost::uint8_t( v>> 8 );
49     (*this)[5] = boost::uint8_t( v     );
50 }
51
52 prefix_ bool senf::MACAddress::local()
53     const
54 {
55     return (*this)[0] & 0x02;
56 }
57
58 prefix_ bool senf::MACAddress::multicast()
59     const
60 {
61     return (*this)[0] & 0x01;
62 }
63
64 prefix_ bool senf::MACAddress::broadcast()
65     const
66 {
67     using  boost::lambda::_1;
68     return std::find_if(begin(),end(), _1 != 0xffu) == end();
69 }
70
71 prefix_ bool senf::MACAddress::boolean_test()
72     const
73 {
74     using boost::lambda::_1;
75     return std::find_if(begin(),end(), _1 != 0x00u) != end();
76 }
77
78 prefix_ boost::uint32_t senf::MACAddress::oui()
79     const
80 {
81     return 
82         (boost::uint32_t((*this)[0])<<16) | 
83         (boost::uint32_t((*this)[1])<<8) | 
84         (*this)[2];
85 }
86
87 prefix_ boost::uint32_t senf::MACAddress::nic()
88     const
89 {
90     return 
91         (boost::uint32_t((*this)[3])<<16) | 
92         (boost::uint32_t((*this)[4])<<8) | 
93         (*this)[5];
94 }
95
96 prefix_ boost::uint64_t senf::MACAddress::eui64()
97     const
98 {
99     return
100         (boost::uint64_t( (*this)[0] ) << 56) | 
101         (boost::uint64_t( (*this)[1] ) << 48) | 
102         (boost::uint64_t( (*this)[2] ) << 40) | 
103         (boost::uint64_t( 0xfffe     ) << 24) |
104         (boost::uint64_t( (*this)[3] ) << 16) | 
105         (boost::uint64_t( (*this)[4] ) <<  8) | 
106         (boost::uint64_t( (*this)[5] )      );
107 }
108
109 ///////////////////////////////cci.e///////////////////////////////////////
110 #undef prefix_
111
112 \f
113 // Local Variables:
114 // mode: c++
115 // fill-column: 100
116 // comment-column: 40
117 // c-file-style: "senf"
118 // indent-tabs-mode: nil
119 // ispell-local-dictionary: "american"
120 // compile-command: "scons -u test"
121 // End: