4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief INet6Address inline non-template implementation */
28 #include <boost/lambda/lambda.hpp>
30 #define prefix_ inline
31 ///////////////////////////////cci.p///////////////////////////////////////
33 prefix_ senf::INet6Address::INet6Address(NoInit_t)
36 prefix_ senf::INet6Address::INet6Address(boost::uint16_t a0, boost::uint16_t a1,
37 boost::uint16_t a2, boost::uint16_t a3,
38 boost::uint16_t a4, boost::uint16_t a5,
39 boost::uint16_t a6, boost::uint16_t a7)
41 (*this)[ 0] = boost::uint8_t(a0>>8);
42 (*this)[ 1] = boost::uint8_t(a0);
43 (*this)[ 2] = boost::uint8_t(a1>>8);
44 (*this)[ 3] = boost::uint8_t(a1);
45 (*this)[ 4] = boost::uint8_t(a2>>8);
46 (*this)[ 5] = boost::uint8_t(a2);
47 (*this)[ 6] = boost::uint8_t(a3>>8);
48 (*this)[ 7] = boost::uint8_t(a3);
49 (*this)[ 8] = boost::uint8_t(a4>>8);
50 (*this)[ 9] = boost::uint8_t(a4);
51 (*this)[10] = boost::uint8_t(a5>>8);
52 (*this)[11] = boost::uint8_t(a5);
53 (*this)[12] = boost::uint8_t(a6>>8);
54 (*this)[13] = boost::uint8_t(a6);
55 (*this)[14] = boost::uint8_t(a7>>8);
56 (*this)[15] = boost::uint8_t(a7);
59 prefix_ senf::INet6Address senf::INet6Address::from_inet4address(INet4Address addr4)
64 std::copy(addr4.begin(), addr4.end(), addr.begin()+12);
68 prefix_ boost::uint64_t senf::INet6Address::network()
72 ((boost::uint64_t((*this)[0]) & 0xff) << 56 ) |
73 ((boost::uint64_t((*this)[1]) & 0xff) << 48 ) |
74 ((boost::uint64_t((*this)[2]) & 0xff) << 40 ) |
75 ((boost::uint64_t((*this)[3]) & 0xff) << 32 ) |
76 ((boost::uint64_t((*this)[4]) & 0xff) << 24 ) |
77 ((boost::uint64_t((*this)[5]) & 0xff) << 16 ) |
78 ((boost::uint64_t((*this)[6]) & 0xff) << 8 ) |
79 ((boost::uint64_t((*this)[7]) & 0xff) );
82 prefix_ bool senf::INet6Address::hasEuid64()
85 return unicast() && ((*this)[0]&0xE0u) != 0u;
88 prefix_ boost::uint64_t senf::INet6Address::id()
92 ((boost::uint64_t((*this)[ 8]) & 0xff) << 56 ) |
93 ((boost::uint64_t((*this)[ 9]) & 0xff) << 48 ) |
94 ((boost::uint64_t((*this)[10]) & 0xff) << 40 ) |
95 ((boost::uint64_t((*this)[11]) & 0xff) << 32 ) |
96 ((boost::uint64_t((*this)[12]) & 0xff) << 24 ) |
97 ((boost::uint64_t((*this)[13]) & 0xff) << 16 ) |
98 ((boost::uint64_t((*this)[14]) & 0xff) << 8 ) |
99 ((boost::uint64_t((*this)[15]) & 0xff) );
102 prefix_ bool senf::INet6Address::universalId()
105 return (*this)[8] & 2u;
108 prefix_ bool senf::INet6Address::groupId()
111 return (*this)[8] & 1u;
114 prefix_ bool senf::INet6Address::unicast()
117 return ! multicast();
120 prefix_ bool senf::INet6Address::multicast()
123 return (*this)[0] == 0xFFu;
126 prefix_ senf::INet6Address::ScopeId senf::INet6Address::scope()
129 static ScopeId const scopeMap[]
130 = { ReservedScope, InterfaceScope, LinkScope, ReservedScope,
131 AdminScope, SiteScope, UnassignedScope, UnassignedScope,
132 OrganizationScope, UnassignedScope, UnassignedScope, UnassignedScope,
133 UnassignedScope, UnassignedScope, GlobalScope, ReservedScope };
134 return multicast() ? scopeMap[(*this)[1] & 0x0Fu] :
135 (*this)[0] == 0xFEu ? (((*this)[1]&0xC0) == 0x80 ? LinkScope :
136 ((*this)[1]&0xC0) == 0xC0 ? SiteScope : GlobalScope )
140 prefix_ bool senf::INet6Address::globalScope()
143 return scope() == GlobalScope;
146 prefix_ bool senf::INet6Address::linkScope()
149 return scope() == LinkScope;
152 prefix_ senf::INet4Address senf::INet6Address::inet4address()
155 return INet4Address::from_data(&(*this)[12]);
158 prefix_ bool senf::INet6Address::ipv4Compatible()
161 return CheckINet6Network<0u,96>::match(*this);
164 prefix_ bool senf::INet6Address::ipv4Mapped()
167 return CheckINet6Network<0u,0u,0u,0u,0u,0xFFFFu,96>::match(*this);
170 prefix_ bool senf::INet6Address::globalMulticastAddr()
173 return multicast() && ! ((*this)[1] & 0x10u);
176 prefix_ bool senf::INet6Address::prefixMulticastAddr()
179 return multicast() && ((*this)[1] & 0x20u);
182 prefix_ bool senf::INet6Address::embeddedRpAddr()
185 return multicast() && ((*this)[1] & 0x40u);
188 prefix_ bool senf::INet6Address::boolean_test()
191 using boost::lambda::_1;
192 return std::find_if(begin(),end(), _1 != 0x00) != end();
195 prefix_ void senf::INet6Address::network(boost::uint64_t net)
197 (*this)[ 0] = net >> 56;
198 (*this)[ 1] = net >> 48;
199 (*this)[ 2] = net >> 40;
200 (*this)[ 3] = net >> 32;
201 (*this)[ 4] = net >> 24;
202 (*this)[ 5] = net >> 16;
203 (*this)[ 6] = net >> 8;
207 prefix_ void senf::INet6Address::id(boost::uint64_t id)
209 (*this)[ 8] = id >> 56;
210 (*this)[ 9] = id >> 48;
211 (*this)[10] = id >> 40;
212 (*this)[11] = id >> 32;
213 (*this)[12] = id >> 24;
214 (*this)[13] = id >> 16;
215 (*this)[14] = id >> 8;
219 ///////////////////////////////cci.e///////////////////////////////////////
226 // comment-column: 40
227 // c-file-style: "senf"
228 // indent-tabs-mode: nil
229 // ispell-local-dictionary: "american"
230 // compile-command: "scons -u test"