TSDuck Version 3.32-2820 (TSDuck - The MPEG Transport Stream Toolkit)
ts::IPv6SocketAddress Class Reference

IP v6 socket address class (IP v6 address & port). More...

Inheritance diagram for ts::IPv6SocketAddress:
Collaboration diagram for ts::IPv6SocketAddress:

Public Types

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

Public Member Functions

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

Static Public Attributes

static const IPv6Address AnyAddress
 Wildcard integer value for "any IP address".
 
static const Port AnyPort = 0
 Wildcard integer value for "any port" or "no port".
 
static const IPv6SocketAddress AnySocketAddress
 Wildcard socket address, unspecified address and 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). More...
 

Detailed Description

IP v6 socket address class (IP v6 address & port).

The string representation is "[addr]:port". In the template string "[addr]:port", the square brackets do not mean that "addr" is optional. According to IPv6 URL representation, the square brackets are actual characters in the string. The address and port fields are optional. If the address is specified alone, without port, the square brackets may be omitted.

Constructor & Destructor Documentation

◆ IPv6SocketAddress() [1/6]

ts::IPv6SocketAddress::IPv6SocketAddress ( const IPv6Address addr,
uint16_t  port = AnyPort 
)
inline

Constructor from an IPv6 address and optional port.

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

◆ IPv6SocketAddress() [2/6]

ts::IPv6SocketAddress::IPv6SocketAddress ( const uint8_t *  addr,
size_t  size,
uint16_t  port = AnyPort 
)
inline

Constructor from 16 bytes address and optional port.

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.
[in]portThe port number as an integer in host byte order.

◆ IPv6SocketAddress() [3/6]

ts::IPv6SocketAddress::IPv6SocketAddress ( const ByteBlock bb,
uint16_t  port = AnyPort 
)
inline

Constructor from 16 bytes address and optional port.

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.
[in]portThe port number as an integer in host byte order.

◆ IPv6SocketAddress() [4/6]

ts::IPv6SocketAddress::IPv6SocketAddress ( uint16_t  h1,
uint16_t  h2,
uint16_t  h3,
uint16_t  h4,
uint16_t  h5,
uint16_t  h6,
uint16_t  h7,
uint16_t  h8,
uint16_t  port = AnyPort 
)
inline

Constructor from 8 hexlets and optional port.

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.
[in]portThe port number as an integer in host byte order.

◆ IPv6SocketAddress() [5/6]

ts::IPv6SocketAddress::IPv6SocketAddress ( uint64_t  net,
uint64_t  ifid,
uint16_t  port = AnyPort 
)
inline

Constructor from network prefix and interface identifier.

Parameters
[in]netNetwork prefix.
[in]ifidInterface identifier.
[in]portThe port number as an integer in host byte order.

◆ IPv6SocketAddress() [6/6]

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

Constructor from a string "[addr]:port".

Parameters
[in]nameA string containing either a host name or a numerical representation of the address and optional port. In case of error, the integer value of the address is set to AnyAddress and port to AnyPort.
[in]reportWhere to report errors.

Member Function Documentation

◆ port()

virtual Port ts::IPv6SocketAddress::port ( ) const
overridevirtual

Get the port if there is one.

The default implementation returns AnyPort.

Returns
The port number or AnyPort if there is none.

Reimplemented from ts::AbstractNetworkAddress.

◆ setPort()

virtual void ts::IPv6SocketAddress::setPort ( Port  port)
overridevirtual

Set the port.

The default implementation does nothing.

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

Reimplemented from ts::AbstractNetworkAddress.

◆ resolve()

virtual bool ts::IPv6SocketAddress::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.

Reimplemented from ts::IPv6Address.

◆ toString()

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

Convert to a string object.

Returns
This object, converted as a string.

Reimplemented from ts::IPv6Address.

◆ toFullString()

virtual UString ts::IPv6SocketAddress::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::IPv6Address.

◆ set() [1/4]

void ts::IPv6SocketAddress::set ( const uint8_t *  addr,
size_t  size,
uint16_t  port 
)
inline

Set the socket address from 16 bytes andport.

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.
[in]portThe port number as an integer in host byte order.

◆ set() [2/4]

void ts::IPv6SocketAddress::set ( const ByteBlock bb,
uint16_t  port 
)
inline

Set the socket address from 16 bytes and port.

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.
[in]portThe port number as an integer in host byte order.

◆ set() [3/4]

void ts::IPv6SocketAddress::set ( uint16_t  h1,
uint16_t  h2,
uint16_t  h3,
uint16_t  h4,
uint16_t  h5,
uint16_t  h6,
uint16_t  h7,
uint16_t  h8,
uint16_t  port 
)
inline

Set the socket address from 8 hexlets and port.

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.
[in]portThe port number as an integer in host byte order.

◆ set() [4/4]

void ts::IPv6SocketAddress::set ( uint64_t  net,
uint64_t  ifid,
uint16_t  port 
)
inline

Set the socket address from network prefix and interface identifier and port.

Parameters
[in]netNetwork prefix.
[in]ifidInterface identifier.
[in]portThe port number as an integer in host byte order.

◆ match() [1/2]

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

Check if this socket address "matches" another one.

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

◆ operator==() [1/2]

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

Equality operator.

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

◆ operator!=() [1/2]

bool ts::IPv6SocketAddress::operator!= ( const IPv6SocketAddress other) const
inline

Unequality operator.

Parameters
[in]otherAnother instance to compare with.
Returns
True if both object contains distinct addresses, false otherwise.

◆ operator<() [1/2]

bool ts::IPv6SocketAddress::operator< ( const IPv6SocketAddress other) const

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.

◆ binarySize()

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

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
overridevirtualinherited

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
overridevirtualinherited

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.

◆ getAddress() [2/2]

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

Get the IP address as a byte block.

Parameters
[out]bbByte block containing the IPv6 bytes.

◆ setAddress() [1/4]

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

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.

◆ setAddress() [2/4]

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

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 
)
inherited

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 
)
inherited

Set the IP address from network prefix and interface identifier.

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

◆ isMulticast()

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

Check if the address is a multicast address.

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

Implements ts::AbstractNetworkAddress.

◆ networkPrefix()

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

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
inlineinherited

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
inherited

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.

◆ match() [2/2]

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

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
inlineinherited

Get the IP address as a byte block.

Returns
Byte block containing the IPv6 bytes.

◆ operator==() [2/2]

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

Equality operator.

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

◆ operator!=() [2/2]

bool ts::IPv6Address::operator!= ( const IPv6Address other) const
inlineinherited

Unequality operator.

Parameters
[in]otherAnother instance to compare with.
Returns
True if both object contains distinct addresses, false otherwise.

◆ operator<() [2/2]

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

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.

◆ 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
staticinherited

Local host address (::1).

Usually resolves to the host name "localhost".


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