senf::INet6Address Class Reference
[Addressing classes]

INet6 network address. More...

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

Inheritance diagram for senf::INet6Address:
Inheritance graph
[legend]

List of all members.


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 };
INet6Address::from_data(rawBytes)

Since INet6Address class is based on 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 begin(), end() or operator[]

INet6Address ina = ...;
Packet::iterator i = ...;
std::copy(ina.begin(), ina.end(), i); // Copies 16 bytes
See also:
CheckINet6Network
INet6Network
Implementation note:
We awkwardly need to use static named constructors (from_ members) instead of ordinarily overloaded constructors for one simple reason: char * 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 129 of file INet6Address.hh.


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.
static INet6Address const  Loopback
  The loopback (::1) address.
static INet6Address const  AllNodes
  The 'all nodes' link-local multicast address.
static INet6Address const  AllRouters
  The 'all routers' link-local multicast address.

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.
std::istream &  operator>> (std::istream &is, INet6Address &addr)
  Try to initialize INet6Address instance from a string representation.

Structors and default members

  INet6Address (senf::NoInit_t)
  Construct uninitialized (!) address.
  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.
in6_addr  toin6_addr () const
  get the linux in6_addr struct (convenience only)
static INet6Address  from_in6addr (in6_addr const &in6addr)
  Construct from std C struct.
static INet6Address  from_string (std::string const &s, Resolve_t resolve=ResolveINet6)
  Convert string to address.
template<class InputIterator >
static INet6Address  from_data (InputIterator i)
  Construct address from 16 bytes of raw data.
static INet6Address  from_inet4address (INet4Address const &addr)
  Construct an INet6-mapped INet4 address.
static INet6Address  from_mac (MACAddress const &mac)
  Construct a link-local INet6 address.
static INet6Address  from_eui64 (EUI64 const &eui)
  Construct link-local INet6 address.

Accessors

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

Mutators

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

Member Enumeration Documentation

enum senf::INet6Address::
Resolve_t
Enumerator:
ResolveINet6 
ResolveINet4 

Definition at line 142 of file INet6Address.hh.

enum senf::INet6Address::
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 151 of file INet6Address.hh.


Constructor & Destructor Documentation

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

Construct uninitialized (!) address.

Definition at line 35 of file INet6Address.cci.

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 )

Construct an address constant.

Definition at line 38 of file INet6Address.cci.


Member Function Documentation

bool senf::INet6Address::
boolean_test ()

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

Definition at line 173 of file INet6Address.cci.

bool senf::INet6Address::
embeddedRpAddr ()

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.

Definition at line 167 of file INet6Address.cci.

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

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.

Definition at line 37 of file INet6Address.ct.

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

Construct link-local INet6 address.

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

Definition at line 113 of file INet6Address.cc.

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

Construct from std C struct.

Definition at line 61 of file INet6Address.cci.

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

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.

Definition at line 66 of file INet6Address.cci.

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

Construct a link-local INet6 address.

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

Definition at line 97 of file INet6Address.cc.

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

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:
AddressSyntaxException  if the address cannot be converted for some reason
UnknownHostnameException  if the hostname cannot be resolved
Parameters:
[in]  s  Address literal or hostname
[in]  resolve  If 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 47 of file INet6Address.cc.

bool senf::INet6Address::
globalMulticastAddr ()

true, if T bit is not set

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

Definition at line 155 of file INet6Address.cci.

bool senf::INet6Address::
globalScope ()

true, if address is global unicast or multicast

Definition at line 137 of file INet6Address.cci.

bool senf::INet6Address::
groupId ()

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

Definition at line 87 of file INet6Address.cci.

bool senf::INet6Address::
hasEUI64 ()

true, if address is based on an EUID-64

Definition at line 131 of file INet6Address.cci.

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

Set interface id part of address.

Definition at line 192 of file INet6Address.cci.

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

Return interface id (EUID-64).

Definition at line 123 of file INet6Address.cc.

senf::INet4Address senf::INet6Address::
inet4address ()

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.

Definition at line 93 of file INet6Address.cci.

bool senf::INet6Address::
inet4Compatible ()

true, if address is INet4 compatible

INet4 compatible INet6 addresses are deprecated.

Definition at line 149 of file INet6Address.cci.

bool senf::INet6Address::
inet4Mapped ()

true, if address is INet4 mapped

Definition at line 99 of file INet6Address.cci.

bool senf::INet6Address::
linkScope ()

true, if address is link-local unicast or multicast

Definition at line 143 of file INet6Address.cci.

bool senf::INet6Address::
multicast ()

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.

Definition at line 105 of file INet6Address.cci.

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

Set network part of address.

Definition at line 180 of file INet6Address.cci.

senf::INet6Network senf::INet6Address::
network ()

Return /64 Network of this address.

Definition at line 75 of file INet6Address.cci.

bool senf::INet6Address::
prefixMulticastAddr ()

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.

Definition at line 161 of file INet6Address.cci.

senf::INet6Address::ScopeId senf::INet6Address::
scope ()

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.

Definition at line 111 of file INet6Address.cci.

in6_addr senf::INet6Address::
toin6_addr ()

get the linux in6_addr struct (convenience only)

Definition at line 91 of file INet6Address.cc.

bool senf::INet6Address::
unicast ()

true, if address is unicast

Definition at line 125 of file INet6Address.cci.

bool senf::INet6Address::
universalId ()

true, if the id() is universally assigned

Definition at line 81 of file INet6Address.cci.


Friends And Related Function Documentation

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

Output INet6Address instance as it's string representation.

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

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

The 'all nodes' link-local multicast address.

Definition at line 139 of file INet6Address.hh.

The 'all routers' link-local multicast address.

Definition at line 140 of file INet6Address.hh.

The loopback (::1) address.

Definition at line 138 of file INet6Address.hh.

The empty (::0) address.

Definition at line 137 of file INet6Address.hh.


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