INet6 network address. More...

#include <senf/Socket/Protocols/INet/INet6Address.hh>

Inheritance diagram for senf::INet6Address:

Public Types

enum  Resolve_t { ResolveINet6, ResolveINet4 }
 
enum  ScopeId {
  InterfaceScope = 1, LinkScope = 2, AdminScope = 4, SiteScope = 5,
  OrganizationScope = 8, GlobalScope = 14, ReservedScope = 0, UnassignedScope = 6
}
 Possible scope values. More...
 

Static Public Attributes

static INet6Address const None
 The empty (::0) address. More...
 
static INet6Address const Loopback
 The loopback (::1) address. More...
 
static INet6Address const AllNodes
 The 'all nodes' link-local multicast address. More...
 
static INet6Address const AllRouters
 The 'all routers' link-local multicast address. More...
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, INet6Address const &addr)
 Output INet6Address instance as it's string representation. More...
 
std::istream & operator>> (std::istream &is, INet6Address &addr)
 Try to initialize INet6Address instance from a string representation. More...
 

Structors and default members

 INet6Address (senf::NoInit_t)
 Construct uninitialized (!) address. More...
 
 INet6Address (boost::uint16_t a0=0u, boost::uint16_t a1=0u, boost::uint16_t a2=0u, boost::uint16_t a3=0u, boost::uint16_t a4=0u, boost::uint16_t a5=0u, boost::uint16_t a6=0u, boost::uint16_t a7=0u)
 Construct an address constant. More...
 
in6_addr toin6_addr () const
 get the linux in6_addr struct (convenience only) More...
 
static INet6Address from_in6addr (in6_addr const &in6addr)
 Construct from std C struct. More...
 
static INet6Address from_string (std::string const &s, Resolve_t resolve=ResolveINet6)
 Convert string to address. More...
 
template<class InputIterator >
static INet6Address from_data (InputIterator i)
 Construct address from 16 bytes of raw data. More...
 
static INet6Address from_inet4address (INet4Address const &addr)
 Construct an INet6-mapped INet4 address. More...
 
static INet6Address from_mac (MACAddress const &mac)
 Construct a link-local INet6 address. More...
 
static INet6Address from_eui64 (EUI64 const &eui)
 Construct link-local INet6 address. More...
 

Accessors

INet6Network network () const
 Return /64 Network of this address. More...
 
bool hasEUI64 () const
 true, if address is based on an EUID-64 More...
 
EUI64 id () const
 Return interface id (EUID-64) More...
 
bool universalId () const
 true, if the id() is universally assigned More...
 
bool groupId () const
 true, if the id()'s group bit is set More...
 
bool unicast () const
 true, if address is unicast More...
 
bool multicast () const
 true, if address is multicast More...
 
ScopeId scope () const
 Get address's scope. More...
 
bool globalScope () const
 true, if address is global unicast or multicast More...
 
bool linkScope () const
 true, if address is link-local unicast or multicast More...
 
INet4Address inet4address () const
 Return embedded INet4 address. More...
 
bool inet4Compatible () const
 true, if address is INet4 compatible More...
 
bool inet4Mapped () const
 true, if address is INet4 mapped More...
 
bool globalMulticastAddr () const
 true, if T bit is not set More...
 
bool prefixMulticastAddr () const
 true, if P bit is set More...
 
bool embeddedRpAddr () const
 true, if R bit is set More...
 
bool boolean_test () const
 true, if address != '::' (None) More...
 

Mutators

void network (boost::uint64_t net)
 Set network part of address. More...
 
void id (boost::uint64_t id)
 Set interface id part of address. More...
 

Additional Inherited Members

- Public Member Functions inherited from senf::comparable_safe_bool< INet6Address >
 operator bool_type () const
 
bool operator! () const
 
- Protected Types inherited from senf::safe_bool_base
typedef void(safe_bool_base::* bool_type) () const
 
- Protected Member Functions inherited from senf::comparable_safe_bool< INet6Address >
 ~comparable_safe_bool ()
 
- Protected Member Functions inherited from senf::safe_bool_base
void this_type_does_not_support_comparisons () const
 
 safe_bool_base ()
 
 safe_bool_base (const safe_bool_base &)
 
safe_bool_baseoperator= (const safe_bool_base &)
 
 ~safe_bool_base ()
 

Detailed Description

INet6 network address.

This implementation of an INet6 address is based strictly on RFC 4291: Internet Protocol Version 6 (INet6) Addressing Architecture. This class provides accessors to all the information fields defined in this document.

The INet6 addressing architecture however has several other components defined in other RFC's. These RFC's should be implemented in additional modules:

  • RFC 4193: Unique Local Addresses (ULA). Defines the fc00::/7 prefix
  • RFC 3306: Unicast-Prefix-based INet6 Multicast Addresses. Defines the ff30::/12 prefix
  • RFC 3956: Embedding the Rendezvous Point (RP) Address in an INet6 Multicast Address. Defines the ff70::/12 prefix
  • RFC 3056: Connection of INet6 Domains via INet4 Clouds. Defines 6to4 tunneling and the 2002::/16 prefix
  • RFC 3849: INet6 Address Prefix Reserved for Documentation. Defines the 2001:db8::/32 prefix

Here an overview of well-known prefixes:

Prefix Description Definition Note
::/96 INet4 compatible INet6 address RFC4291 deprecated
::ffff:0:0/96 INet6 mapped INet4 address RFC4291
2000::/3 Global unicast addresses RFC3587 only noted, not defined
2001:db8::/32 Documentation-only prefix RFC3849
2002::/16 6to4 addressing RFC3056
fc00::/7 ULA RFC4193
fe80::/64 Link-local addresses RFC4291
fec0::/10 Site-local addresses RFC4291 deprecated
ff00::/8 Multicast RFC4291
ff00::/12 Globally allocated multicast RFC4291
ff10::/12 Locally allocated multicast RFC4291
ff30::/12 Unicast prefix based multicast RFC3306
ff70::/12 Multicast address with embedded RP RFC3956

The following statements all create the same INet6 address 2001:db8::a0b1:1a2b:3dff:fe4e:5f00:

// Used to construct constant INet6 addresses
INet6Address(0x2001u,0xDB8u,0x0u,0xA0B1u 0x1A2Bu,0x3DFFu,0xFE4Eu,0x5F00u)
// Construct INet6 address from it's string representation
INet6Address::from_string("2001:db8::a0b1:1a2b:3dff:fe4e:5f00")
// Construct an INet6 address from raw data. 'from_data' takes an arbitrary iterator (e.g. a
// pointer) as argument. Here we use a fixed array but normally you will need this to build
// an INet6 address in a packet parser
char rawBytes[] = { 0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0xA0, 0xB1,
0x1a, 0x2b, 0x3d, 0xff, 0xfe, 0x4e, 0xff, 0x00 };
    Since INet6Address class is based on \c boost::array and is built as a fixed-size sequence
    of 16 bytes, you can access the raw data bytes of the address (in network byte order) using
    \c begin(), \c end() or \c operator[]
INet6Address ina = ...;
Packet::iterator i = ...;
std::copy(ina.begin(), ina.end(), i); // Copies 16 bytes
    \see CheckINet6Network \n INet6Network


    \par "Implementation note:" We awkwardly need to use static named constructors (<tt>from_</tt> members)
        instead of ordinarily overloaded constructors for one simple reason: <tt>char *</tt>
        doubles as string literal and as arbitrary data iterator. The iterator constructor can
        therefore not be distinguished from initialization with a string literal. Therefore we
        need to disambiguate using the named constructors.

Definition at line 119 of file INet6Address.hh.

Member Enumeration Documentation

◆ Resolve_t

Enumerator
ResolveINet6 
ResolveINet4 

Definition at line 132 of file INet6Address.hh.

◆ ScopeId

Possible scope values.

List of all possible scope values. This list includes all scope values defined for multicast addresses in RFC 4291. The values LinkScope, SiteScope and GlobalScope are also used with unicast addresses.

Enumerator
InterfaceScope 

Interface only scope

LinkScope 

Link-local scope

AdminScope 

Administration defined local scope

SiteScope 

Site-local scope

OrganizationScope 

Scope covering multiple sites of an organization

GlobalScope 

Global Internet scope

ReservedScope 

Reserved scope value

UnassignedScope 

Unassigned scope, may be defined locally

Definition at line 141 of file INet6Address.hh.

Constructor & Destructor Documentation

◆ INet6Address() [1/2]

senf::INet6Address::INet6Address ( senf::NoInit_t  )
explicit

Construct uninitialized (!) address.

◆ INet6Address() [2/2]

senf::INet6Address::INet6Address ( boost::uint16_t  a0 = 0u,
boost::uint16_t  a1 = 0u,
boost::uint16_t  a2 = 0u,
boost::uint16_t  a3 = 0u,
boost::uint16_t  a4 = 0u,
boost::uint16_t  a5 = 0u,
boost::uint16_t  a6 = 0u,
boost::uint16_t  a7 = 0u 
)
explicit

Construct an address constant.

Member Function Documentation

◆ boolean_test()

bool senf::INet6Address::boolean_test ( ) const

true, if address != '::' (None)

◆ embeddedRpAddr()

bool senf::INet6Address::embeddedRpAddr ( ) const

true, if R bit is set

In RFC 4291, the R bit is specified as defining a multicast address with embedded rendezvous point. See RFC 3956.

◆ from_data()

template<class InputIterator >
static INet6Address senf::INet6Address::from_data ( InputIterator  i)
static

Construct address from 16 bytes of raw data.

from_data will build an address from 16 bytes of raw data as accessed by the iterator. The data must be in network byte order.

◆ from_eui64()

senf::INet6Address senf::INet6Address::from_eui64 ( EUI64 const &  eui)
static

Construct link-local INet6 address.

This will construct a link local address of the form fe80::xxxx:xxxx:xxxx:xxxx.

Definition at line 103 of file INet6Address.cc.

◆ from_in6addr()

static INet6Address senf::INet6Address::from_in6addr ( in6_addr const &  in6addr)
static

Construct from std C struct.

◆ from_inet4address()

static INet6Address senf::INet6Address::from_inet4address ( INet4Address const &  addr)
static

Construct an INet6-mapped INet4 address.

This will construct an address of the form ::FFFF::w.x.y.z where w.x.y.z is the INet4Address value. This kind of address is called an INet6-mapped INet4 address (see RFC 4291).

INet4 compatible INet6 addresses are not directly supported, they are deprecated in the RFC.

◆ from_mac()

senf::INet6Address senf::INet6Address::from_mac ( MACAddress const &  mac)
static

Construct a link-local INet6 address.

This will construct a link local address of the form fe80::xxxx:xxff:fexx:xxxx.

Definition at line 87 of file INet6Address.cc.

◆ from_string()

senf::INet6Address senf::INet6Address::from_string ( std::string const &  s,
Resolve_t  resolve = ResolveINet6 
)
static

Convert string to address.

This member will try to convert the given string into an IP address. from_string() supports all standard IP literal representations as well as hostnames.

Attention
This call may block if s represents a hostname which must be looked up via some network protocol like DNS or NIS
Exceptions
AddressSyntaxExceptionif the address cannot be converted for some reason
UnknownHostnameExceptionif the hostname cannot be resolved
Parameters
[in]sAddress literal or hostname
[in]resolveIf this is set to ResolveINet4, the call will additionally try to interpret s as an INet4 address if no valid INet6 address is found. The address will be returned as mapped INet6 address.

Definition at line 38 of file INet6Address.cc.

◆ globalMulticastAddr()

bool senf::INet6Address::globalMulticastAddr ( ) const

true, if T bit is not set

Any multicast address with a cleared T bit must be globally assigned. See RFC 4291.

◆ globalScope()

bool senf::INet6Address::globalScope ( ) const

true, if address is global unicast or multicast

◆ groupId()

bool senf::INet6Address::groupId ( ) const

true, if the id()'s group bit is set

◆ hasEUI64()

bool senf::INet6Address::hasEUI64 ( ) const

true, if address is based on an EUID-64

◆ id() [1/2]

senf::EUI64 senf::INet6Address::id ( ) const

Return interface id (EUID-64)

Definition at line 113 of file INet6Address.cc.

◆ id() [2/2]

void senf::INet6Address::id ( boost::uint64_t  id)

Set interface id part of address.

◆ inet4address()

INet4Address senf::INet6Address::inet4address ( ) const

Return embedded INet4 address.

Returns the INet4 address embedded within an INet4 compatible or INet4 mapped unicast address. This address is given by the last 32 bits of the INet6 address.

The value returned is only a valid INet4 address if either inet4Compatible() or inet4Mapped() return true.

◆ inet4Compatible()

bool senf::INet6Address::inet4Compatible ( ) const

true, if address is INet4 compatible

INet4 compatible INet6 addresses are deprecated.

◆ inet4Mapped()

bool senf::INet6Address::inet4Mapped ( ) const

true, if address is INet4 mapped

◆ linkScope()

bool senf::INet6Address::linkScope ( ) const

true, if address is link-local unicast or multicast

◆ multicast()

bool senf::INet6Address::multicast ( ) const

true, if address is multicast

To support a linux specific extension, INet4 multicast addressed mapped to INet6 are also interpreted as multicast addresses. This is NOT part of the standard, however the standard officially only allows unicast v4 addresses to be mapped to v6 so this does not collide with any standard conforming use.

◆ network() [1/2]

INet6Network senf::INet6Address::network ( ) const

Return /64 Network of this address.

◆ network() [2/2]

void senf::INet6Address::network ( boost::uint64_t  net)

Set network part of address.

◆ prefixMulticastAddr()

bool senf::INet6Address::prefixMulticastAddr ( ) const

true, if P bit is set

In RFC 4291, the P bit is specified as defining a unicast prefix based multicast address. See RFC 3306.

◆ scope()

ScopeId senf::INet6Address::scope ( ) const

Get address's scope.

The scope of an address is one of the ScopeId values. We need to differentiate between unicast and multicast addresses: unicast addresses only have local, site or global scope (where site scope is deprecated), multicast address can have a number of scope values of which local, site and global are a few. See the ScopeId enumerators.

◆ toin6_addr()

in6_addr senf::INet6Address::toin6_addr ( ) const

get the linux in6_addr struct (convenience only)

Definition at line 81 of file INet6Address.cc.

◆ unicast()

bool senf::INet6Address::unicast ( ) const

true, if address is unicast

◆ universalId()

bool senf::INet6Address::universalId ( ) const

true, if the id() is universally assigned

Friends And Related Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
INet6Address const &  addr 
)
related

Output INet6Address instance as it's string representation.

◆ operator>>()

std::istream & operator>> ( std::istream &  is,
INet6Address addr 
)
related

Try to initialize INet6Address instance from a string representation.

sets std::ios::failbit on the stream if an error occurred

See also
INet6Address from_string()

Member Data Documentation

◆ AllNodes

senf::INet6Address const senf::INet6Address::AllNodes
static

The 'all nodes' link-local multicast address.

Definition at line 129 of file INet6Address.hh.

◆ AllRouters

senf::INet6Address const senf::INet6Address::AllRouters
static

The 'all routers' link-local multicast address.

Definition at line 130 of file INet6Address.hh.

◆ Loopback

senf::INet6Address const senf::INet6Address::Loopback
static

The loopback (::1) address.

Definition at line 128 of file INet6Address.hh.

◆ None

senf::INet6Address const senf::INet6Address::None
static

The empty (::0) address.

Definition at line 127 of file INet6Address.hh.


The documentation for this class was generated from the following files: