TSDuck v3.38-3703
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::IPv6Address Class Reference

A basic representation of an IPv6 address. More...

#include <tsIPv6Address.h>

Inheritance diagram for ts::IPv6Address:
Collaboration diagram for ts::IPv6Address:

Public Types

using Port = uint16_t
 The concept of port is used by TCP and UDP over IP networks.
 

Public Member Functions

 IPv6Address ()
 Default constructor.
 
 IPv6Address (const ByteBlock &bb)
 Constructor from 16 bytes.
 
 IPv6Address (const uint8_t *addr, size_t size)
 Constructor from 16 bytes.
 
 IPv6Address (const UString &name, Report &report)
 Constructor from a string in standard IPv6 numerical format.
 
 IPv6Address (uint16_t h1, uint16_t h2, uint16_t h3, uint16_t h4, uint16_t h5, uint16_t h6, uint16_t h7, uint16_t h8)
 Constructor from 8 hexlets.
 
 IPv6Address (uint64_t net, uint64_t ifid)
 Constructor from network prefix and interface identifier.
 
virtual size_t binarySize () const override
 Get the maximum binary size for an address of that class.
 
virtual void clear ()
 Clear the object, address and port if there is any.
 
virtual void clearAddress () override
 Clear the address field.
 
virtual void clearPort ()
 Clear the port.
 
void getAddress (ByteBlock &bb) const
 Get the IP address as a byte block.
 
virtual size_t getAddress (void *addr, size_t size) const override
 Get the network address as binary data.
 
virtual bool hasAddress () const override
 Check if this object is set to a valid address.
 
virtual bool hasPort () const
 Check if a port is set.
 
uint16_t hexlet (size_t i) const
 Get one of the 16-bit hexlets in the address.
 
uint64_t interfaceIdentifier () const
 Get the interface identifier (64 least significant bits) of the IPv6 address.
 
virtual bool isMulticast () const override
 Check if the address is a multicast address.
 
bool match (const IPv6Address &other) const
 Check if this address "matches" another one.
 
uint64_t networkPrefix () const
 Get the network prefix (64 most significant bits) of the IPv6 address.
 
bool operator< (const IPv6Address &other) const
 Comparison "less than" operator.
 
bool operator== (const IPv6Address &other) const
 Equality operator.
 
virtual Port port () const
 Get the port if there is one.
 
virtual bool resolve (const UString &name, Report &report) override
 Decode a string containing a network address in family-specific format.
 
void setAddress (const ByteBlock &bb)
 Set the IP address from 16 bytes.
 
virtual bool setAddress (const void *addr, size_t size) override
 Set the network address from binary data.
 
void setAddress (uint16_t h1, uint16_t h2, uint16_t h3, uint16_t h4, uint16_t h5, uint16_t h6, uint16_t h7, uint16_t h8)
 Set the IP address from 8 hexlets.
 
void setAddress (uint64_t net, uint64_t ifid)
 Set the IP address from network prefix and interface identifier.
 
virtual void setPort (Port port)
 Set the port.
 
ByteBlock toBytes () const
 Get the IP address as a byte block.
 
virtual UString toFullString () const override
 Convert to a string object in numeric format without the default compaction.
 
virtual UString toString () const override
 Convert to a string object.
 

Static Public Attributes

static const IPv6Address AnyAddress
 Wildcard integer value for "any IP address".
 
static constexpr Port AnyPort = 0
 Wildcard integer value for "any port" or "no port".
 
static constexpr size_t BITS = 128
 Size in bits of an IPv6 address.
 
static constexpr size_t BYTES = 16
 Size in bytes of an IPv6 address.
 
static const IPv6Address LocalHost
 Local host address (::1).
 

Detailed Description

A basic representation of an IPv6 address.

See also
https://en.wikipedia.org/wiki/IPv6_address

An IPv6 address is made of 128 bits (16 bytes). It can be manipulated as

  • 16 bytes
  • 8 groups of 16 bits or hextets.
  • 2 64-bit values, the network prefix and the network identifier.

This class is incomplete. Currently, it does not allow IPv6 networking. It is only designed to manipulate IPv6 addresses in DVB signalization.

Constructor & Destructor Documentation

◆ IPv6Address() [1/6]

ts::IPv6Address::IPv6Address ( )
inline

Default constructor.

The default value is AnyAddress.

◆ IPv6Address() [2/6]

ts::IPv6Address::IPv6Address ( const uint8_t *  addr,
size_t  size 
)
inline

Constructor from 16 bytes.

Parameters
[in]addrAddress of the memory area containing the IPv6 bytes.
[in]sizeSize of the memory area. If the size is shorter than 16, the IPv6 is padded on the left (most significant bytes) with zeroes. If the size is larger than 16, extra bytes are ignored.

◆ IPv6Address() [3/6]

ts::IPv6Address::IPv6Address ( const ByteBlock bb)
inline

Constructor from 16 bytes.

Parameters
[in]bbByte block containing the IPv6 bytes. If the size is shorter than 16, the IPv6 is padded on the left (most significant bytes) with zeroes. If the size is larger than 16, extra bytes are ignored.

◆ IPv6Address() [4/6]

ts::IPv6Address::IPv6Address ( uint16_t  h1,
uint16_t  h2,
uint16_t  h3,
uint16_t  h4,
uint16_t  h5,
uint16_t  h6,
uint16_t  h7,
uint16_t  h8 
)
inline

Constructor from 8 hexlets.

Parameters
[in]h1First address hexlet.
[in]h22nd address hexlet.
[in]h33rd address hexlet.
[in]h44th address hexlet.
[in]h55th address hexlet.
[in]h66th address hexlet.
[in]h77th address hexlet.
[in]h88th address hexlet.

◆ IPv6Address() [5/6]

ts::IPv6Address::IPv6Address ( uint64_t  net,
uint64_t  ifid 
)
inline

Constructor from network prefix and interface identifier.

Parameters
[in]netNetwork prefix.
[in]ifidInterface identifier.

◆ IPv6Address() [6/6]

ts::IPv6Address::IPv6Address ( const UString name,
Report report 
)
inline

Constructor from a string in standard IPv6 numerical format.

If name cannot be resolved, the address is set to AnyAddress.

Parameters
[in]nameA string containing a string in standard IPv6 numerical format.
[in]reportWhere to report errors.
See also
https://en.wikipedia.org/wiki/IPv6_address

Member Function Documentation

◆ binarySize()

virtual size_t ts::IPv6Address::binarySize ( ) const
overridevirtual

Get the maximum binary size for an address of that class.

Returns
The maximum binary size for an address of that class.

Implements ts::AbstractNetworkAddress.

◆ hasAddress()

virtual bool ts::IPv6Address::hasAddress ( ) const
overridevirtual

Check if this object is set to a valid address.

Returns
True if this object is set to a valid address, false otherwise.

Implements ts::AbstractNetworkAddress.

◆ getAddress() [1/2]

virtual size_t ts::IPv6Address::getAddress ( void *  addr,
size_t  size 
) const
overridevirtual

Get the network address as binary data.

Parameters
[out]addrAddress of binary buffer to receive binary data.
[in]sizeSize in bytes of buffer.
Returns
Number of copied bytes on success, zero on error (data too short).

Implements ts::AbstractNetworkAddress.

◆ setAddress() [1/4]

virtual bool ts::IPv6Address::setAddress ( const void *  addr,
size_t  size 
)
overridevirtual

Set the network address from binary data.

Parameters
[in]addrAddress of binary data.
[in]sizeSize in bytes of binary data.
Returns
True on success, false on error (data too short).

Implements ts::AbstractNetworkAddress.

◆ clearAddress()

virtual void ts::IPv6Address::clearAddress ( )
overridevirtual

Clear the address field.

Implements ts::AbstractNetworkAddress.

◆ isMulticast()

virtual bool ts::IPv6Address::isMulticast ( ) const
overridevirtual

Check if the address is a multicast address.

Returns
True if the address is a multicast address, false otherwise.

Implements ts::AbstractNetworkAddress.

◆ resolve()

virtual bool ts::IPv6Address::resolve ( const UString name,
Report report 
)
overridevirtual

Decode a string containing a network address in family-specific format.

Parameters
[in]nameA string containing either a host name or a numerical representation of the address.
[in]reportWhere to report errors.
Returns
True if name was successfully resolved, false otherwise. In the later case, the address is invalidated.

Implements ts::AbstractNetworkAddress.

Reimplemented in ts::IPv6SocketAddress.

◆ toString()

virtual UString ts::IPv6Address::toString ( ) const
overridevirtual

Convert to a string object.

Returns
This object, converted as a string.

Implements ts::StringifyInterface.

Reimplemented in ts::IPv6SocketAddress.

◆ toFullString()

virtual UString ts::IPv6Address::toFullString ( ) const
overridevirtual

Convert to a string object in numeric format without the default compaction.

The method toString() (inherited from StringifyInterface) returns a default representation of the string, with possible compaction of omitted defaults. This method returns a complete version of the address representation. The default implementation returns the same value as toString().

Returns
This object, converted as a string.

Reimplemented from ts::AbstractNetworkAddress.

Reimplemented in ts::IPv6SocketAddress.

◆ getAddress() [2/2]

void ts::IPv6Address::getAddress ( ByteBlock bb) const
inline

Get the IP address as a byte block.

Parameters
[out]bbByte block containing the IPv6 bytes.

◆ networkPrefix()

uint64_t ts::IPv6Address::networkPrefix ( ) const
inline

Get the network prefix (64 most significant bits) of the IPv6 address.

Returns
The network prefix (64 most significant bits) of the IPv6 address.

◆ interfaceIdentifier()

uint64_t ts::IPv6Address::interfaceIdentifier ( ) const
inline

Get the interface identifier (64 least significant bits) of the IPv6 address.

Returns
The interface identifier (64 least significant bits) of the IPv6 address.

◆ hexlet()

uint16_t ts::IPv6Address::hexlet ( size_t  i) const

Get one of the 16-bit hexlets in the address.

Parameters
[in]iHexlet index, from 0 to 7.
Returns
The corresponding hexlet or zero if i is out of range.

◆ setAddress() [2/4]

void ts::IPv6Address::setAddress ( const ByteBlock bb)
inline

Set the IP address from 16 bytes.

Parameters
[in]bbByte block containing the IPv6 bytes. If the size is shorter than 16, the IPv6 is padded on the left (most significant bytes) with zeroes. If the size is larger than 16, extra bytes are ignored.

◆ setAddress() [3/4]

void ts::IPv6Address::setAddress ( uint16_t  h1,
uint16_t  h2,
uint16_t  h3,
uint16_t  h4,
uint16_t  h5,
uint16_t  h6,
uint16_t  h7,
uint16_t  h8 
)

Set the IP address from 8 hexlets.

Parameters
[in]h1First address hexlet.
[in]h22nd address hexlet.
[in]h33rd address hexlet.
[in]h44th address hexlet.
[in]h55th address hexlet.
[in]h66th address hexlet.
[in]h77th address hexlet.
[in]h88th address hexlet.

◆ setAddress() [4/4]

void ts::IPv6Address::setAddress ( uint64_t  net,
uint64_t  ifid 
)

Set the IP address from network prefix and interface identifier.

Parameters
[in]netNetwork prefix.
[in]ifidInterface identifier.

◆ match()

bool ts::IPv6Address::match ( const IPv6Address other) const

Check if this address "matches" another one.

Parameters
[in]otherAnother instance to compare.
Returns
False if this and other addresses are both specified and are different. True otherwise.

◆ toBytes()

ByteBlock ts::IPv6Address::toBytes ( ) const
inline

Get the IP address as a byte block.

Returns
Byte block containing the IPv6 bytes.

◆ operator==()

bool ts::IPv6Address::operator== ( const IPv6Address other) const
inline

Equality operator.

Parameters
[in]otherAnother instance to compare with.
Returns
True if both object contains the same address, false otherwise.

◆ operator<()

bool ts::IPv6Address::operator< ( const IPv6Address other) const
inline

Comparison "less than" operator.

It does not really makes sense. Only defined to allow usage in containers.

Parameters
[in]otherOther instance to compare.
Returns
True if this instance is less than to other.

◆ hasPort()

virtual bool ts::AbstractNetworkAddress::hasPort ( ) const
virtualinherited

Check if a port is set.

Returns
True if port is set.

◆ port()

virtual Port ts::AbstractNetworkAddress::port ( ) const
virtualinherited

Get the port if there is one.

The default implementation returns AnyPort.

Returns
The port number or AnyPort if there is none.

Reimplemented in ts::IPv4SocketAddress, and ts::IPv6SocketAddress.

◆ setPort()

virtual void ts::AbstractNetworkAddress::setPort ( Port  port)
virtualinherited

Set the port.

The default implementation does nothing.

Parameters
[in]portThe port number as an integer in host byte order.

Reimplemented in ts::IPv4SocketAddress, and ts::IPv6SocketAddress.

◆ clearPort()

virtual void ts::AbstractNetworkAddress::clearPort ( )
virtualinherited

Clear the port.

The default implementatio sets the port to AnyPort

Member Data Documentation

◆ LocalHost

const IPv6Address ts::IPv6Address::LocalHost
static

Local host address (::1).

Usually resolves to the host name "localhost".


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