INet6Address.hh
Go to the documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef HH_SENF_Socket_Protocols_INet_INet6Address_
00027 #define HH_SENF_Socket_Protocols_INet_INet6Address_ 1
00028
00029
00030 #include <iostream>
00031 #include <string>
00032 #include <netinet/in.h>
00033 #include <boost/cstdint.hpp>
00034 #include <boost/array.hpp>
00035 #include <boost/operators.hpp>
00036 #include <senf/Utils/safe_bool.hh>
00037 #include <senf/Utils/Tags.hh>
00038 #include "INet4Address.hh"
00039
00040
00041 #include "INet6Address.ih"
00042
00043
00044 namespace senf {
00045
00046 class EUI64;
00047 class MACAddress;
00048 class INet6Network;
00049
00129 class INet6Address
00130 : public boost::array<boost::uint8_t,16>,
00131 public comparable_safe_bool<INet6Address>
00132 {
00133 public:
00134
00135
00136
00137 static INet6Address const None;
00138 static INet6Address const Loopback;
00139 static INet6Address const AllNodes;
00140 static INet6Address const AllRouters;
00141
00142 enum Resolve_t { ResolveINet6, ResolveINet4 };
00143
00151 enum ScopeId {
00152 InterfaceScope = 1
00153 , LinkScope = 2
00154 , AdminScope = 4
00155 , SiteScope = 5
00156 , OrganizationScope = 8
00157 , GlobalScope = 14
00159 , ReservedScope = 0
00160 , UnassignedScope = 6
00161 };
00162
00163
00165
00166
00167 explicit INet6Address(senf::NoInit_t);
00168 explicit INet6Address(boost::uint16_t a0=0u, boost::uint16_t a1=0u, boost::uint16_t a2=0u,
00169 boost::uint16_t a3=0u, boost::uint16_t a4=0u, boost::uint16_t a5=0u,
00170 boost::uint16_t a6=0u, boost::uint16_t a7=0u);
00172
00173 static INet6Address from_in6addr(in6_addr const & in6addr);
00174
00175 static INet6Address from_string(std::string const & s, Resolve_t resolve = ResolveINet6);
00177
00194 template <class InputIterator>
00195 static INet6Address from_data(InputIterator i);
00197
00201 static INet6Address from_inet4address(INet4Address const & addr);
00203
00211 static INet6Address from_mac(MACAddress const & mac);
00213
00216 static INet6Address from_eui64(EUI64 const & eui);
00218
00221 in6_addr toin6_addr() const;
00222
00223
00224
00226
00227
00228 INet6Network network() const;
00229 bool hasEUI64() const;
00230 EUI64 id() const;
00231 bool universalId() const;
00232 bool groupId() const;
00233
00234 bool unicast() const;
00235 bool multicast() const;
00236
00243 ScopeId scope() const;
00244
00251 bool globalScope() const;
00252 bool linkScope() const;
00253
00254 INet4Address inet4address() const;
00255
00261 bool inet4Compatible() const;
00262
00263 bool inet4Mapped() const;
00264
00265 bool globalMulticastAddr() const;
00266
00269 bool prefixMulticastAddr() const;
00270
00274 bool embeddedRpAddr() const;
00275
00280 bool boolean_test() const;
00281
00282
00284
00285
00286 void network(boost::uint64_t net);
00287 void id(boost::uint64_t id);
00288
00289
00290
00291 };
00292
00296 std::ostream & operator<<(std::ostream & os, INet6Address const & addr);
00297
00304 std::istream & operator>>(std::istream & is, INet6Address & addr);
00305
00333 template <unsigned a0, unsigned a1, unsigned a2=0u, unsigned a3=0u, unsigned a4=0u,
00334 unsigned a5=0u, unsigned a6=0u, unsigned a7=0u, unsigned a8=0u>
00335 struct CheckINet6Network
00336 #ifndef DOXYGEN
00337 : public detail::CheckINet6Network_impl<a0,a1,a2,a3,a4,a5,a6,a7,a8>
00338 #endif
00339 {};
00340
00345 class INet6Network
00346 : public boost::equality_comparable<INet6Network>,
00347 public comparable_safe_bool<INet6Network>
00348 {
00349 public:
00350
00352
00353
00354 INet6Network();
00355 INet6Network(INet6Address const & address, unsigned prefix_len);
00357 explicit INet6Network(std::string const & s);
00358
00359
00360
00361
00362 INet6Address const & address() const;
00363 unsigned prefix_len() const;
00364
00365 bool boolean_test() const;
00366 bool operator==(INet6Network const & other) const;
00368
00369 bool match(INet6Address const & addr) const;
00370 bool match(INet6Network const & net) const;
00371
00373 INet6Address host(boost::uint64_t id);
00374
00378 INet6Network subnet(boost::uint64_t net, unsigned prefix_len);
00380
00390 protected:
00391
00392 private:
00393 unsigned prefix_len_;
00394 INet6Address address_;
00395 };
00396
00400 std::ostream & operator<<(std::ostream & os, INet6Network const & addr);
00401
00407 std::istream & operator>>(std::istream & is, INet6Network & addr);
00408 }
00409
00410
00411 #include "INet6Address.cci"
00412 #include "INet6Address.ct"
00413 #include "INet6Address.cti"
00414 #endif
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425