INet6Address.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Socket_Protocols_INet_INet6Address_
18 #define HH_SENF_Socket_Protocols_INet_INet6Address_ 1
19 
20 // Custom includes
21 #include <string>
22 #include <netinet/in.h>
23 #include <boost/cstdint.hpp>
24 #include <boost/array.hpp>
25 #include <boost/operators.hpp>
26 #include <senf/Utils/safe_bool.hh>
27 #include <senf/Utils/Tags.hh>
28 #include "INet4Address.hh"
29 
30 //#include "INet6Address.mpp"
31 #include "INet6Address.ih"
32 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33 
34 namespace senf {
35 
36  struct EUI64;
37  struct MACAddress;
38  class INet6Network;
39 
120  : public boost::array<boost::uint8_t,16>,
121  public comparable_safe_bool<INet6Address>
122  {
123  public:
124  //-////////////////////////////////////////////////////////////////////////
125  // Types
126 
127  static INet6Address const None;
128  static INet6Address const Loopback;
129  static INet6Address const AllNodes;
130  static INet6Address const AllRouters;
131 
133 
141  enum ScopeId {
143  , LinkScope = 2
144  , AdminScope = 4
145  , SiteScope = 5
147  , GlobalScope = 14
151  };
152 
153  //-////////////////////////////////////////////////////////////////////////
155  //\{
156 
157  explicit INet6Address(senf::NoInit_t);
158  explicit INet6Address(boost::uint16_t a0=0u, boost::uint16_t a1=0u, boost::uint16_t a2=0u,
159  boost::uint16_t a3=0u, boost::uint16_t a4=0u, boost::uint16_t a5=0u,
160  boost::uint16_t a6=0u, boost::uint16_t a7=0u);
162 
163  static INet6Address from_in6addr(in6_addr const & in6addr);
164 
165  static INet6Address from_string(std::string const & s, Resolve_t resolve = ResolveINet6);
167 
184  template <class InputIterator>
185  static INet6Address from_data(InputIterator i);
187 
191  static INet6Address from_inet4address(INet4Address const & addr);
193 
201  static INet6Address from_mac(MACAddress const & mac);
203 
206  static INet6Address from_eui64(EUI64 const & eui);
208 
211  in6_addr toin6_addr() const;
212 
213  //\}
214  //-////////////////////////////////////////////////////////////////////////
216  //\{
217 
218  INet6Network network() const;
219  bool hasEUI64() const;
220  EUI64 id() const;
221  bool universalId() const;
222  bool groupId() const;
223 
224  bool unicast() const;
225  bool multicast() const;
226 
233  ScopeId scope() const;
234 
241  bool globalScope() const;
242  bool linkScope() const;
243 
244  INet4Address inet4address() const;
245 
251  bool inet4Compatible() const;
252 
253  bool inet4Mapped() const;
254 
255  bool globalMulticastAddr() const;
256 
259  bool prefixMulticastAddr() const;
260 
264  bool embeddedRpAddr() const;
265 
270  bool boolean_test() const;
271 
272  //\}
274  //\{
275 
276  void network(boost::uint64_t net);
277  void id(boost::uint64_t id);
278 
279  //\}
280 
281  };
282 
286  std::ostream & operator<<(std::ostream & os, INet6Address const & addr);
287 
294  std::istream & operator>>(std::istream & is, INet6Address & addr);
295 
323  template <unsigned a0, unsigned a1, unsigned a2=0u, unsigned a3=0u, unsigned a4=0u,
324  unsigned a5=0u, unsigned a6=0u, unsigned a7=0u, unsigned a8=0u>
326 #ifndef DOXYGEN
327  : public detail::CheckINet6Network_impl<a0,a1,a2,a3,a4,a5,a6,a7,a8>
328 #endif
329  {};
330 
336  : public boost::equality_comparable<INet6Network>,
337  public comparable_safe_bool<INet6Network>
338  {
339  public:
340  //-////////////////////////////////////////////////////////////////////////
342  //\{
343 
344  INet6Network();
345  INet6Network(INet6Address const & address, unsigned prefix_len);
347  explicit INet6Network(std::string const & s);
348 
349  //\}
350  //-////////////////////////////////////////////////////////////////////////
351 
352  INet6Address const & address() const;
353  unsigned prefix_len() const;
354 
355  bool boolean_test() const;
356  bool operator==(INet6Network const & other) const;
358 
359  bool match(INet6Address const & addr) const;
360  bool match(INet6Network const & net) const;
361 
363  INet6Address host(boost::uint64_t id);
364 
368  INet6Network subnet(boost::uint64_t net, unsigned prefix_len);
370 
380  protected:
381 
382  private:
383  unsigned prefix_len_;
384  INet6Address address_;
385 
386  unsigned prefix_len_checked(unsigned prefix_len) const;
387  };
388 
392  std::ostream & operator<<(std::ostream & os, INet6Network const & addr);
393 
399  std::istream & operator>>(std::istream & is, INet6Network & addr);
400 }
401 
402 //-/////////////////////////////////////////////////////////////////////////////////////////////////
403 #include "INet6Address.cci"
404 #include "INet6Address.ct"
405 #include "INet6Address.cti"
406 #endif
407 
408 
409 // Local Variables:
410 // mode: c++
411 // fill-column: 100
412 // comment-column: 40
413 // c-file-style: "senf"
414 // indent-tabs-mode: nil
415 // ispell-local-dictionary: "american"
416 // compile-command: "scons -u test"
417 // End:
bool groupId() const
true, if the id()&#39;s group bit is set
ScopeId scope() const
Get address&#39;s scope.
static INet6Address from_string(std::string const &s, Resolve_t resolve=ResolveINet6)
Convert string to address.
Definition: INet6Address.cc:38
INet4Address inet4address() const
Return embedded INet4 address.
bool inet4Compatible() const
true, if address is INet4 compatible
EUI-64 data type.
Definition: EUI64.hh:66
INet6 network prefix.
bool unicast() const
true, if address is unicast
Ethernet MAC address.
Definition: MACAddress.hh:72
Check INet6Address against a fixed network prefix.
bool embeddedRpAddr() const
true, if R bit is set
bool universalId() const
true, if the id() is universally assigned
bool globalMulticastAddr() const
true, if T bit is not set
static INet6Address const Loopback
The loopback (::1) address.
NoInit_t
in6_addr toin6_addr() const
get the linux in6_addr struct (convenience only)
Definition: INet6Address.cc:81
INet6Network network() const
Return /64 Network of this address.
std::ostream & operator<<(std::ostream &os, INet6Address const &addr)
Output INet6Address instance as it&#39;s string representation.
INet4Address public header.
bool linkScope() const
true, if address is link-local unicast or multicast
static INet6Address const AllNodes
The &#39;all nodes&#39; link-local multicast address.
static INet6Address from_inet4address(INet4Address const &addr)
Construct an INet6-mapped INet4 address.
bool operator==(EUI64 const &eui64, MACAddress const &mac)
static INet6Address const AllRouters
The &#39;all routers&#39; link-local multicast address.
static INet6Address from_in6addr(in6_addr const &in6addr)
Construct from std C struct.
bool boolean_test() const
true, if address != &#39;::&#39; (None)
bool inet4Mapped() const
true, if address is INet4 mapped
INet6 network address.
EUI64 id() const
Return interface id (EUID-64)
INet6Address(senf::NoInit_t)
Construct uninitialized (!) address.
static INet6Address from_data(InputIterator i)
Construct address from 16 bytes of raw data.
IPv4 Internet address.
Definition: INet4Address.hh:78
std::istream & operator>>(std::istream &is, INet6Address &addr)
Try to initialize INet6Address instance from a string representation.
bool globalScope() const
true, if address is global unicast or multicast
static INet6Address from_eui64(EUI64 const &eui)
Construct link-local INet6 address.
bool hasEUI64() const
true, if address is based on an EUID-64
static INet6Address const None
The empty (::0) address.
ScopeId
Possible scope values.
bool multicast() const
true, if address is multicast
static INet6Address from_mac(MACAddress const &mac)
Construct a link-local INet6 address.
Definition: INet6Address.cc:87
bool prefixMulticastAddr() const
true, if P bit is set