TSDuck v3.40-3968
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::IPSocketAddress Class Reference

Generic socket address class (IPv4 or IPv6 address & port). More...

#include <tsIPSocketAddress.h>

Inheritance diagram for ts::IPSocketAddress:
Collaboration diagram for ts::IPSocketAddress:

Public Types

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

Public Member Functions

 IPSocketAddress ()=default
 Default constructor The default initial value is AnySocketAddress4.
 
 IPSocketAddress (const ::in6_addr &a, Port port, bool bound=false)
 IPv6 constructor from a system "struct in6_addr" structure (IPv6 socket API).
 
 IPSocketAddress (const ::in_addr &a, Port port, bool bound=false)
 IPv4 constructor from a system "struct in_addr" structure (IPv4 socket API).
 
 IPSocketAddress (const ::sockaddr &a)
 Generic constructor from a system "struct sockaddr" structure (IPv4 or IPv6).
 
 IPSocketAddress (const ::sockaddr_in &a, bool bound=false)
 IPv4 constructor from a system "struct sockaddr_in" structure (IPv4 socket API).
 
 IPSocketAddress (const ::sockaddr_in6 &a, bool bound=false)
 IPv6 constructor from a system "struct sockaddr_in6" structure (IPv6 socket API).
 
 IPSocketAddress (const ::sockaddr_storage &a)
 Generic constructor from a system "struct sockaddr_storage" structure (IPv4 or IPv6).
 
 IPSocketAddress (const ByteBlock &bb, Port port, bool bound=false)
 Generic constructor from an address in binary format.
 
 IPSocketAddress (const IPAddress addr, Port port)
 Generic constructor from an address and port.
 
 IPSocketAddress (const uint8_t *addr, size_t size, Port port, bool bound=false)
 Generic constructor from an address in binary format.
 
 IPSocketAddress (const UString &name, Report &report, IP bound=IP::Any)
 Constructor from a string, host name or integer format.
 
 IPSocketAddress (IP bound)
 Constructor with no initial value but optionally bound to a generation.
 
 IPSocketAddress (uint16_t h1, uint16_t h2, uint16_t h3, uint16_t h4, uint16_t h5, uint16_t h6, uint16_t h7, uint16_t h8, Port port, bool bound=false)
 IPv6 constructor of an IPv6 address from 8 hexlets.
 
 IPSocketAddress (uint32_t addr, Port port, bool bound=false)
 IPv4 constructor from an integer IPv4 address.
 
 IPSocketAddress (uint64_t net, uint64_t ifid, Port port, bool bound=false)
 IPv6 constructor of an IPv6 address from network prefix and interface identifier.
 
 IPSocketAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, Port port, bool bound=false)
 IPv4 constructor from 4 bytes (classical IPv4 notation).
 
uint32_t address4 () const
 Get the IPv4 address as a 32-bit integer value in host byte order.
 
ByteBlock address6 () const
 Get the IPv6 address as a byte block.
 
virtual size_t binarySize () const override
 Get the maximum binary size in bytes for an address of that class.
 
IP boundGeneration () const
 Get the generation of IP addresses this instance is bound to.
 
void checkCompatibility (const IPAddress &other)
 Check if this object can hold a value of a specific IP generation and throw an exception if not.
 
void checkCompatibility (IP gen)
 Check if this object can hold a value of a specific IP generation and throw an exception if not.
 
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.
 
bool convert (IP gen)
 Convert an IP address to another generation, when possible.
 
virtual const UCharfamilyName () const override
 Get a human-readable family name for an address of that class.
 
IP generation () const
 Get the current generation of IP addresses.
 
size_t get (::sockaddr_storage *a, size_t size) const
 Get the address and port into a system "struct sockaddr_storage" structure.
 
void get4 (::sockaddr_in &a) const
 Get the IPv4 address and port into a system "struct sockaddr_in" structure.
 
void get6 (::sockaddr_in6 &a) const
 Get the IPv6 address and port into a system "struct sockaddr_in6" structure.
 
size_t getAddress (::sockaddr_storage *a, size_t size, Port port) const
 Copy the address into a system "struct sockaddr_storage" structure (socket API).
 
virtual size_t getAddress (void *addr, size_t size) const override
 Get the network address as binary data.
 
void getAddress4 (::in_addr &a) const
 Copy the IPv4 address into a system "struct in_addr" structure (socket API).
 
void getAddress4 (::sockaddr_in &a, Port port) const
 Copy the IPv4 address into a system "struct sockaddr_in" structure (socket API).
 
void getAddress6 (::in6_addr &a) const
 Copy the IPv6 address into a system "struct in6_addr" structure (socket API).
 
void getAddress6 (::sockaddr_in6 &a, Port port) const
 Copy the IPv6 address into a system "struct sockaddr_in6" structure (socket API).
 
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 hexlet6 (size_t i) const
 Get one of the 16-bit hexlets in the IPv6 address.
 
uint64_t interfaceIdentifier6 () const
 Get the IPv6 interface identifier (64 least significant bits) of the IPv6 address.
 
bool isBound () const
 Check if the address is bound to a specific generation of IP addresses.
 
bool isCompatible (const IPAddress &other)
 Check if this object can hold a value of a specific IP generation.
 
bool isCompatible (IP gen)
 Check if this object can hold a value of a specific IP generation.
 
bool isIPv4Mapped () const
 Check if the address is an IPv6 address which is mapped to an IPv4 one.
 
virtual bool isMulticast () const override
 Check if the address is a multicast address.
 
bool isSSM () const
 Check if the address is a source specific multicast (SSM) address.
 
bool match (const IPAddress &other) const
 Check if this address "matches" another one.
 
bool match (const IPSocketAddress &other) const
 Check if this socket address "matches" another one.
 
uint64_t networkPrefix6 () const
 Get the IPv6 network prefix (64 most significant bits) of the IPv6 address.
 
bool operator< (const IPAddress &other) const
 Comparison "less than" operator.
 
bool operator< (const IPSocketAddress &other) const
 Comparison "less than" operator.
 
bool operator== (const IPAddress &other) const
 Equality operator.
 
bool operator== (const IPSocketAddress &other) const
 Equality operator.
 
virtual Port port () const override
 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 set (const ::sockaddr &a)
 Set the IP address and port from a system "struct sockaddr" structure (IPv4 or IPv6).
 
void set (const ::sockaddr_storage &a)
 Set the IP address and port from a system "struct sockaddr_storage" structure (IPv4 or IPv6).
 
void set4 (const ::sockaddr_in &a)
 Set the IPv4 address and port from a system "struct sockaddr_in" structure.
 
void set6 (const ::sockaddr_in6 &a)
 Set the IPv6 address and port from a system "struct sockaddr_in6" structure.
 
void setAddress (const ::sockaddr &a)
 Set the IP address from a system "struct sockaddr" structure (IPv4 or IPv6).
 
void setAddress (const ::sockaddr_storage &a)
 Set the IP address from a system "struct sockaddr_storage" structure (IPv4 or IPv6).
 
void setAddress (const IPAddress &other)
 Set the IP address from another IPAddress object.
 
virtual bool setAddress (const void *addr, size_t size) override
 Set the network address from binary data.
 
void setAddress4 (const ::in_addr &a)
 Set the IPv4 address from a system "struct in_addr" structure.
 
void setAddress4 (const ::sockaddr_in &a)
 Set the IPv4 address from a system "struct sockaddr_in" structure.
 
void setAddress4 (uint32_t addr)
 Set the IP address from an IPv4 address as a 32-bit integer value in host byte order.
 
void setAddress4 (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4)
 Set the IP address from 4 bytes (classical IPv4 notation).
 
void setAddress6 (const ::in6_addr &a)
 Set the IPv6 address from a system "struct in6_addr" structure.
 
void setAddress6 (const ::sockaddr_in6 &a)
 Set the IPv6 address from a system "struct sockaddr_in6" structure.
 
void setAddress6 (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 an IPv6 address as 8 hexlets.
 
void setAddress6 (uint64_t net, uint64_t ifid)
 Set the IP address from an IPv6 address as network prefix and interface identifier.
 
virtual void setPort (Port port) override
 Set the port.
 
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 Member Functions

static size_t AddressBits (IP gen)
 Get the address size in bits for a given generation of IP protocols.
 
static const IPAddressAnyAddress (IP gen)
 Get the "any address" template for a given generation of IP protocols.
 
static const IPAddressLocalHost (IP gen)
 Get the "local host" address for a given generation of IP protocols.
 
static bool ResolveAllAddresses (IPAddressVector &addresses, const UString &name, Report &report, IP gen=IP::Any)
 Decode a host name and get all possible addresses for that host.
 

Static Public Attributes

static const IPAddress AnyAddress4
 Wildcard value for "any IPv4 address".
 
static const IPAddress AnyAddress6
 Wildcard value for "any IPv6 address".
 
static constexpr Port AnyPort = 0
 Wildcard integer value for "any port" or "no port".
 
static const IPSocketAddress AnySocketAddress4
 Wildcard socket address, unspecified IPv4 address and port.
 
static const IPSocketAddress AnySocketAddress6
 Wildcard socket address, unspecified IPv6 address and port.
 
static constexpr size_t BITS4 = 32
 Size in bits of an IPv4 address.
 
static constexpr size_t BITS6 = 128
 Size in bits of an IPv6 address.
 
static constexpr size_t BYTES4 = 4
 Size in bytes of an IPv4 address.
 
static constexpr size_t BYTES6 = 16
 Size in bytes of an IPv6 address.
 
static const IPAddress LocalHost4
 Local host IPv4 address ("localhost").
 
static const IPAddress LocalHost6
 Local host IPv6 address (::1, "localhost").
 

Detailed Description

Generic socket address class (IPv4 or IPv6 address & port).

The string representation is "addr[:port]" or "[addr:]port".

In this class, methods which apply to only one generation, IPv4 or IPv6, have a name ending in 4 or 6, respectively. Some constructors implicitly build one generation of address, IPv4 or IPv6, but their names remain IPAddress() without trailing 4 or 6 by design of C++.

Constructor & Destructor Documentation

◆ IPSocketAddress() [1/15]

ts::IPSocketAddress::IPSocketAddress ( IP  bound)
inline

Constructor with no initial value but optionally bound to a generation.

The default initial value is AnySocketAddress4, unless bound is IP::v6 in which case the default initial value is AnySocketAddress6.

Parameters
[in]boundBound generation of the IP address. When set to IP::Any, this instance can receive any generation of IP address. Otherwise, this instance can only receive addresses of the specified generation. In that case, trying to assign an address from a different generation thows the exception IncompatibleIPAddress.

◆ IPSocketAddress() [2/15]

ts::IPSocketAddress::IPSocketAddress ( const IPAddress  addr,
Port  port 
)
inline

Generic constructor from an address and port.

Parameters
[in]addrAddress.
[in]portPort number as an integer in host byte order.

◆ IPSocketAddress() [3/15]

ts::IPSocketAddress::IPSocketAddress ( const uint8_t addr,
size_t  size,
Port  port,
bool  bound = false 
)
inline

Generic constructor from an address in binary format.

Parameters
[in]addrAddress of the memory area containing the address in binary format.
[in]sizeSize of the memory area. If the size is 4, this is an IPv4 address. If the size is 16, this is an IPv6 address. For all other sizes, the address is AnyAddress4.
[in]portOptional port number as an integer in host byte order.
[in]boundIf true, this instance is bound to it generation. Otherwise, it can receive any address.

◆ IPSocketAddress() [4/15]

ts::IPSocketAddress::IPSocketAddress ( const ByteBlock bb,
Port  port,
bool  bound = false 
)
inline

Generic constructor from an address in binary format.

Parameters
[in]bbByte block containing the address in binary format. If the size is 4, this is an IPv4 address. If the size is 16, this is an IPv6 address. For all other sizes, the address is AnyAddress4.
[in]portOptional port number as an integer in host byte order.
[in]boundIf true, this instance is bound to it generation. Otherwise, it can receive any address.

◆ IPSocketAddress() [5/15]

ts::IPSocketAddress::IPSocketAddress ( uint32_t  addr,
Port  port,
bool  bound = false 
)
inline

IPv4 constructor from an integer IPv4 address.

Parameters
[in]addrThe IP v4 address as an integer in host byte order.
[in]portOptional port number as an integer in host byte order.
[in]boundIf true, this instance is bound to IPv4. Otherwise, it can receive any address.

◆ IPSocketAddress() [6/15]

ts::IPSocketAddress::IPSocketAddress ( uint8_t  b1,
uint8_t  b2,
uint8_t  b3,
uint8_t  b4,
Port  port,
bool  bound = false 
)
inline

IPv4 constructor from 4 bytes (classical IPv4 notation).

Parameters
[in]b1First address byte.
[in]b2Second address byte.
[in]b3Third address byte.
[in]b4Fourth address byte.
[in]portOptional port number as an integer in host byte order.
[in]boundIf true, this instance is bound to IPv4. Otherwise, it can receive any address.

◆ IPSocketAddress() [7/15]

ts::IPSocketAddress::IPSocketAddress ( uint16_t  h1,
uint16_t  h2,
uint16_t  h3,
uint16_t  h4,
uint16_t  h5,
uint16_t  h6,
uint16_t  h7,
uint16_t  h8,
Port  port,
bool  bound = false 
)
inline

IPv6 constructor of an IPv6 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.
[in]portOptional port number as an integer in host byte order.
[in]boundIf true, this instance is bound to IPv6. Otherwise, it can receive any address.

◆ IPSocketAddress() [8/15]

ts::IPSocketAddress::IPSocketAddress ( uint64_t  net,
uint64_t  ifid,
Port  port,
bool  bound = false 
)
inline

IPv6 constructor of an IPv6 address from network prefix and interface identifier.

Parameters
[in]netNetwork prefix.
[in]ifidInterface identifier.
[in]portOptional port number as an integer in host byte order.
[in]boundIf true, this instance is bound to IPv6. Otherwise, it can receive any address.

◆ IPSocketAddress() [9/15]

ts::IPSocketAddress::IPSocketAddress ( const ::sockaddr a)

Generic constructor from a system "struct sockaddr" structure (IPv4 or IPv6).

Parameters
[in]aA system "struct sockaddr" structure. Note: the structure "sockaddr" is deprecated because it cannot hold an IPv6 socket address. The structure "sockaddr_storage" should be used instead.

◆ IPSocketAddress() [10/15]

ts::IPSocketAddress::IPSocketAddress ( const ::sockaddr_storage a)
inline

Generic constructor from a system "struct sockaddr_storage" structure (IPv4 or IPv6).

Parameters
[in]aA system "struct sockaddr_storage" structure.

◆ IPSocketAddress() [11/15]

ts::IPSocketAddress::IPSocketAddress ( const ::in_addr a,
Port  port,
bool  bound = false 
)
inline

IPv4 constructor from a system "struct in_addr" structure (IPv4 socket API).

Parameters
[in]aA system "struct in_addr" structure.
[in]portOptional port number as an integer in host byte order.
[in]boundIf true, this instance is bound to IPv4. Otherwise, it can receive any address.

◆ IPSocketAddress() [12/15]

ts::IPSocketAddress::IPSocketAddress ( const ::sockaddr_in a,
bool  bound = false 
)

IPv4 constructor from a system "struct sockaddr_in" structure (IPv4 socket API).

Parameters
[in]aA system "struct sockaddr_in" structure.
[in]boundIf true, this instance is bound to IPv4. Otherwise, it can receive any address.

◆ IPSocketAddress() [13/15]

ts::IPSocketAddress::IPSocketAddress ( const ::in6_addr a,
Port  port,
bool  bound = false 
)
inline

IPv6 constructor from a system "struct in6_addr" structure (IPv6 socket API).

Parameters
[in]aA system "struct in6_addr" structure.
[in]portOptional port number as an integer in host byte order.
[in]boundIf true, this instance is bound to IPv6. Otherwise, it can receive any address.

◆ IPSocketAddress() [14/15]

ts::IPSocketAddress::IPSocketAddress ( const ::sockaddr_in6 a,
bool  bound = false 
)

IPv6 constructor from a system "struct sockaddr_in6" structure (IPv6 socket API).

Parameters
[in]aA system "struct sockaddr_in6" structure.
[in]boundIf true, this instance is bound to IPv6. Otherwise, it can receive any address.

◆ IPSocketAddress() [15/15]

ts::IPSocketAddress::IPSocketAddress ( const UString name,
Report report,
IP  bound = IP::Any 
)
inline

Constructor from a string, host name or integer format.

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

Parameters
[in]nameA string containing either a host name or a numerical representation of the address.
[in]reportWhere to report errors.
[in]boundBound generation of the IP address. If not set to IP::Any (the default), this instance becomes bound to that IP generation and the name resolution can only produce an address of that generation.

Member Function Documentation

◆ port()

virtual Port ts::IPSocketAddress::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::IPSocketAddress::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::IPSocketAddress::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::IPAddress.

◆ toFullString()

virtual UString ts::IPSocketAddress::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::IPAddress.

◆ toString()

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

Convert to a string object.

Returns
This object, converted as a string.

Reimplemented from ts::IPAddress.

◆ set() [1/2]

void ts::IPSocketAddress::set ( const ::sockaddr &  a)

Set the IP address and port from a system "struct sockaddr" structure (IPv4 or IPv6).

Parameters
[in]aA system "struct sockaddr" structure. Note: the structure "sockaddr" is deprecated because it cannot hold an IPv6 socket address. The structure "sockaddr_storage" should be used instead.

◆ set() [2/2]

void ts::IPSocketAddress::set ( const ::sockaddr_storage &  a)
inline

Set the IP address and port from a system "struct sockaddr_storage" structure (IPv4 or IPv6).

Parameters
[in]aA system "struct sockaddr_storage" structure.

◆ set4()

void ts::IPSocketAddress::set4 ( const ::sockaddr_in a)
inline

Set the IPv4 address and port from a system "struct sockaddr_in" structure.

Parameters
[in]aA system "struct sockaddr_in" structure.

◆ set6()

void ts::IPSocketAddress::set6 ( const ::sockaddr_in6 a)
inline

Set the IPv6 address and port from a system "struct sockaddr_in6" structure.

Parameters
[in]aA system "struct sockaddr_in6" structure.

◆ get()

size_t ts::IPSocketAddress::get ( ::sockaddr_storage a,
size_t  size 
) const
inline

Get the address and port into a system "struct sockaddr_storage" structure.

Note: the structure "sockaddr" is deprecated because it cannot hold an IPv6 socket address. The structure "sockaddr_storage" should be used instead.

Parameters
[out]aAddress of a system socket address structure.
[in]sizeSize in bytes of the system socket address structure.
Returns
Actual number of bytes used in the structure "sockaddr_storage", zero on error (system socket address structure is too small).

◆ get4()

void ts::IPSocketAddress::get4 ( ::sockaddr_in a) const
inline

Get the IPv4 address and port into a system "struct sockaddr_in" structure.

Parameters
[out]aA system "struct sockaddr_in" structure.

◆ get6()

void ts::IPSocketAddress::get6 ( ::sockaddr_in6 a) const
inline

Get the IPv6 address and port into a system "struct sockaddr_in6" structure.

Parameters
[out]aA system "struct sockaddr_in6" structure.

◆ match() [1/2]

bool ts::IPSocketAddress::match ( const IPSocketAddress 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]

Equality operator.

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

◆ operator<() [1/2]

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.

◆ AnyAddress()

static const IPAddress & ts::IPAddress::AnyAddress ( IP  gen)
inlinestaticinherited

Get the "any address" template for a given generation of IP protocols.

Parameters
[in]genGeneration of IP protocols.
Returns
A constant reference to the corresponding "any address".

◆ LocalHost()

static const IPAddress & ts::IPAddress::LocalHost ( IP  gen)
inlinestaticinherited

Get the "local host" address for a given generation of IP protocols.

Parameters
[in]genGeneration of IP protocols.
Returns
A constant reference to the corresponding "local host" address.

◆ AddressBits()

static size_t ts::IPAddress::AddressBits ( IP  gen)
inlinestaticinherited

Get the address size in bits for a given generation of IP protocols.

Parameters
[in]genGeneration of IP protocols.
Returns
Address size in bits.

◆ operator==() [2/2]

bool ts::IPAddress::operator== ( const IPAddress other) const
inherited

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::IPAddress::operator< ( const IPAddress other) const
inherited

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.

◆ match() [2/2]

bool ts::IPAddress::match ( const IPAddress 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.

◆ generation()

IP ts::IPAddress::generation ( ) const
inlineinherited

Get the current generation of IP addresses.

Returns
The IP generation of the address currently in this instance. Never IP::Any.

◆ isBound()

bool ts::IPAddress::isBound ( ) const
inlineinherited

Check if the address is bound to a specific generation of IP addresses.

Returns
True if the address is bound to a specific generation of IP addresses.

◆ boundGeneration()

IP ts::IPAddress::boundGeneration ( ) const
inlineinherited

Get the generation of IP addresses this instance is bound to.

Returns
The generation of IP addresses this instance is bound to. Return IP::Any if this instance is not bound to a generation.

◆ isCompatible() [1/2]

bool ts::IPAddress::isCompatible ( IP  gen)
inlineinherited

Check if this object can hold a value of a specific IP generation.

Parameters
[in]genThe IP generation to check.
Returns
True if this object is not bound to another IP generation.

◆ isCompatible() [2/2]

bool ts::IPAddress::isCompatible ( const IPAddress other)
inlineinherited

Check if this object can hold a value of a specific IP generation.

Parameters
[in]otherAnother IP to check.
Returns
True if this object is not bound to an IP generation other than the current generation of other.

◆ checkCompatibility() [1/2]

void ts::IPAddress::checkCompatibility ( IP  gen)
inherited

Check if this object can hold a value of a specific IP generation and throw an exception if not.

Parameters
[in]genThe IP generation to check.
Exceptions
IncompatibleIPAddresswhen this object is bound to another IP generation.

◆ checkCompatibility() [2/2]

void ts::IPAddress::checkCompatibility ( const IPAddress other)
inlineinherited

Check if this object can hold a value of a specific IP generation and throw an exception if not.

Parameters
[in]otherAnother IP to check.
Exceptions
IncompatibleIPAddresswhen this object is bound to an IP generation other than the current generation of other.

◆ isIPv4Mapped()

bool ts::IPAddress::isIPv4Mapped ( ) const
inherited

Check if the address is an IPv6 address which is mapped to an IPv4 one.

Returns
true if the address is an IPv6 address which is mapped to an IPv4 one.

◆ convert()

bool ts::IPAddress::convert ( IP  gen)
inherited

Convert an IP address to another generation, when possible.

Parameters
[in]genNew IP generation to apply. If gen is incompatible with the object (bound to another generation), return false. If gen is IP::Any or the same as the current generation, return true. A conversion from IPv4 to IPv6 always works (IPv4-mapped address). The conversion of an IPv6 address is only possible if it is an IPv4-mapped address. For convenience, the IPv4 and IPv6 loopback addressses are converted to each other.
Returns
True if the conversion was successful, false if the conversion was no possible.

◆ binarySize()

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

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

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

Implements ts::AbstractNetworkAddress.

◆ familyName()

virtual const UChar * ts::IPAddress::familyName ( ) const
overridevirtualinherited

Get a human-readable family name for an address of that class.

This is typically something like "IPv4" or "IPv6".

Returns
A human-readable family name for an address of that class.

Implements ts::AbstractNetworkAddress.

◆ hasAddress()

virtual bool ts::IPAddress::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::IPAddress::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]

size_t ts::IPAddress::getAddress ( ::sockaddr_storage *  a,
size_t  size,
Port  port 
) const
inherited

Copy the address into a system "struct sockaddr_storage" structure (socket API).

Note: the structure "sockaddr" is deprecated because it cannot hold an IPv6 socket address. The structure "sockaddr_storage" should be used instead.

Parameters
[out]aAddress of a system socket address structure.
[in]sizeSize in bytes of the system socket address structure.
[in]portPort number for the socket address.
Returns
Actual number of bytes used in the structure "sockaddr_storage", zero on error (system socket address structure is too small).

◆ setAddress() [1/4]

virtual bool ts::IPAddress::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::IPAddress::setAddress ( const IPAddress other)
inherited

Set the IP address from another IPAddress object.

Useful for subclasses to assign the address part only.

Parameters
[in]otherAnother IP address.

◆ setAddress() [3/4]

void ts::IPAddress::setAddress ( const ::sockaddr &  a)
inherited

Set the IP address from a system "struct sockaddr" structure (IPv4 or IPv6).

Parameters
[in]aA system "struct sockaddr" structure. Note: the structure "sockaddr" is deprecated because it cannot hold an IPv6 socket address. The structure "sockaddr_storage" should be used instead.

◆ setAddress() [4/4]

void ts::IPAddress::setAddress ( const ::sockaddr_storage &  a)
inlineinherited

Set the IP address from a system "struct sockaddr_storage" structure (IPv4 or IPv6).

Parameters
[in]aA system "struct sockaddr_storage" structure.

◆ clearAddress()

virtual void ts::IPAddress::clearAddress ( )
overridevirtualinherited

Clear the address field.

Implements ts::AbstractNetworkAddress.

◆ isMulticast()

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

◆ isSSM()

bool ts::IPAddress::isSSM ( ) const
inherited

Check if the address is a source specific multicast (SSM) address.

Returns
True if the address is an SSM address, false otherwise.

◆ address4()

uint32_t ts::IPAddress::address4 ( ) const
inlineinherited

Get the IPv4 address as a 32-bit integer value in host byte order.

Returns
The IPv4 address as a 32-bit integer value in host byte order or zero if not an IPv4 address.

◆ address6()

ByteBlock ts::IPAddress::address6 ( ) const
inherited

Get the IPv6 address as a byte block.

Returns
Byte block containing the IPv6 bytes.

◆ networkPrefix6()

uint64_t ts::IPAddress::networkPrefix6 ( ) const
inherited

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

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

◆ interfaceIdentifier6()

uint64_t ts::IPAddress::interfaceIdentifier6 ( ) const
inherited

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

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

◆ hexlet6()

uint16_t ts::IPAddress::hexlet6 ( size_t  i) const
inherited

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

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

◆ setAddress4() [1/4]

void ts::IPAddress::setAddress4 ( uint32_t  addr)
inherited

Set the IP address from an IPv4 address as a 32-bit integer value in host byte order.

Parameters
[in]addrThe IP v4 address as an integer in host byte order.

◆ setAddress4() [2/4]

void ts::IPAddress::setAddress4 ( uint8_t  b1,
uint8_t  b2,
uint8_t  b3,
uint8_t  b4 
)
inherited

Set the IP address from 4 bytes (classical IPv4 notation).

Parameters
[in]b1First address byte.
[in]b2Second address byte.
[in]b3Third address byte.
[in]b4Fourth address byte.

◆ setAddress4() [3/4]

void ts::IPAddress::setAddress4 ( const ::in_addr &  a)
inherited

Set the IPv4 address from a system "struct in_addr" structure.

Parameters
[in]aA system "struct in_addr" structure.

◆ setAddress4() [4/4]

void ts::IPAddress::setAddress4 ( const ::sockaddr_in &  a)
inherited

Set the IPv4 address from a system "struct sockaddr_in" structure.

Parameters
[in]aA system "struct sockaddr_in" structure.

◆ setAddress6() [1/4]

void ts::IPAddress::setAddress6 ( 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 an IPv6 address as 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.

◆ setAddress6() [2/4]

void ts::IPAddress::setAddress6 ( uint64_t  net,
uint64_t  ifid 
)
inherited

Set the IP address from an IPv6 address as network prefix and interface identifier.

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

◆ setAddress6() [3/4]

void ts::IPAddress::setAddress6 ( const ::in6_addr &  a)
inherited

Set the IPv6 address from a system "struct in6_addr" structure.

Parameters
[in]aA system "struct in6_addr" structure.

◆ setAddress6() [4/4]

void ts::IPAddress::setAddress6 ( const ::sockaddr_in6 &  a)
inherited

Set the IPv6 address from a system "struct sockaddr_in6" structure.

Parameters
[in]aA system "struct sockaddr_in6" structure.

◆ getAddress4() [1/2]

void ts::IPAddress::getAddress4 ( ::sockaddr_in &  a,
Port  port 
) const
inherited

Copy the IPv4 address into a system "struct sockaddr_in" structure (socket API).

Parameters
[out]aA system "struct sockaddr_in" structure.
[in]portPort number for the socket address.

◆ getAddress4() [2/2]

void ts::IPAddress::getAddress4 ( ::in_addr &  a) const
inherited

Copy the IPv4 address into a system "struct in_addr" structure (socket API).

Parameters
[out]aA system "struct in_addr" structure.

◆ getAddress6() [1/2]

void ts::IPAddress::getAddress6 ( ::sockaddr_in6 &  a,
Port  port 
) const
inherited

Copy the IPv6 address into a system "struct sockaddr_in6" structure (socket API).

Parameters
[out]aA system "struct sockaddr_in6" structure.
[in]portPort number for the socket address.

◆ getAddress6() [2/2]

void ts::IPAddress::getAddress6 ( ::in6_addr &  a) const
inherited

Copy the IPv6 address into a system "struct in6_addr" structure (socket API).

Parameters
[out]aA system "struct in6_addr" structure.

◆ ResolveAllAddresses()

static bool ts::IPAddress::ResolveAllAddresses ( IPAddressVector addresses,
const UString name,
Report report,
IP  gen = IP::Any 
)
staticinherited

Decode a host name and get all possible addresses for that host.

Parameters
[out]addressesList of possible addresses for name. If name is a valid numerical addresse, only this one is returned.
[in]nameA string containing either a host name or a numerical representation of the address.
[in,out]reportWhere to report errors.
[in]genIP generation of the returned address. Can be used to restrict the result to IPv4 or IPv6 addresses. Return all by default.
Returns
True if name was successfully resolved, false otherwise.

◆ 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


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