TSDuck Version 3.15-964 (TSDuck - The MPEG Transport Stream Toolkit)
ts::IPAddress Class Reference

A basic representation of an IP v4 address. More...

Inheritance diagram for ts::IPAddress:
Collaboration diagram for ts::IPAddress:

Public Member Functions

 IPAddress ()
 Default constructor.
 
 IPAddress (uint32_t addr)
 Constructor from an integer address. More...
 
 IPAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4)
 Constructor from 4 bytes (classical IPv4 notation). More...
 
 IPAddress (const ::in_addr &a)
 Constructor from a system "struct in_addr" structure (socket API). More...
 
 IPAddress (const ::sockaddr &a)
 Constructor from a system "struct sockaddr" structure (socket API). More...
 
 IPAddress (const ::sockaddr_in &a)
 Constructor from a system "struct sockaddr_in" structure (socket API). More...
 
 IPAddress (const UString &name, Report &report=(*ts::CerrReport::Instance()))
 Constructor from a string, host name or "a.b.c.d" integer format. More...
 
virtual ~IPAddress ()
 Virtual destructor.
 
uint32_t address () const
 Get the IP address as a 32-bit integer value in host byte order. More...
 
void clear ()
 Clear address (set it to AnyAddress).
 
void copy (::sockaddr &a, uint16_t port) const
 Copy the address into a system "struct sockaddr" structure (socket API). More...
 
void copy (::sockaddr_in &a, uint16_t port) const
 Copy the address into a system "struct sockaddr_in" structure (socket API). More...
 
void copy (::in_addr &a) const
 Copy the address into a system "struct in_addr" structure (socket API). More...
 
bool hasAddress () const
 Check if this object is set to a valid address (ie not AnyAddress). More...
 
bool isMulticast () const
 Check if the address is a multicast address. More...
 
bool isSSM () const
 Check if the address is a source specific multicast (SSM) address. More...
 
bool match (const IPAddress &other) const
 Check if this address "matches" another one. More...
 
bool operator!= (const IPAddress &a) const
 Unequality operator. More...
 
bool operator< (const IPAddress &other) const
 Comparison "less than" operator. More...
 
bool operator== (const IPAddress &a) const
 Equality operator. More...
 
bool resolve (const UString &name, Report &report=(*ts::CerrReport::Instance()))
 Decode a string, numeric address or hostname which is resolved. More...
 
void setAddress (uint32_t addr)
 Set the IP address from a 32-bit integer value in host byte order. More...
 
void setAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4)
 Set the IP address from 4 bytes (classical IPv4 notation). More...
 
virtual UString toString () const override
 Convert to a string object. More...
 

Static Public Attributes

static const uint32_t AnyAddress = 0
 Wildcard integer value for "any IP address".
 
static const IPAddress LocalHost
 Local host address. More...
 

Detailed Description

A basic representation of an IP v4 address.

IP v4 addresses are sometimes manipulated as 32-bit integer values. There is always some ambiguity in the operating system interface about the byte order of these integer values. In this class, all publicly available integer values are in the natural host byte order. Whenever a conversion is required, the internal guts of this class will do it for you (and hide it from you).

Constructor & Destructor Documentation

◆ IPAddress() [1/6]

ts::IPAddress::IPAddress ( uint32_t  addr)
inline

Constructor from an integer address.

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

◆ IPAddress() [2/6]

ts::IPAddress::IPAddress ( uint8_t  b1,
uint8_t  b2,
uint8_t  b3,
uint8_t  b4 
)

Constructor from 4 bytes (classical IPv4 notation).

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

◆ IPAddress() [3/6]

ts::IPAddress::IPAddress ( const ::in_addr &  a)
inline

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

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

◆ IPAddress() [4/6]

ts::IPAddress::IPAddress ( const ::sockaddr &  a)

Constructor from a system "struct sockaddr" structure (socket API).

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

◆ IPAddress() [5/6]

ts::IPAddress::IPAddress ( const ::sockaddr_in &  a)

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

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

◆ IPAddress() [6/6]

ts::IPAddress::IPAddress ( const UString name,
Report report = (*ts::CerrReport::Instance()) 
)
inline

Constructor from a string, host name or "a.b.c.d" integer format.

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

Parameters
[in]nameA string containing either a host name or a numerical representation of the address "a.b.c.d".
[in]reportWhere to report errors.

Member Function Documentation

◆ operator==()

bool ts::IPAddress::operator== ( const IPAddress a) const
inline

Equality operator.

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

◆ operator!=()

bool ts::IPAddress::operator!= ( const IPAddress a) const
inline

Unequality operator.

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

◆ address()

uint32_t ts::IPAddress::address ( ) const
inline

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

Returns
The IP address as a 32-bit integer value in host byte order.

◆ setAddress() [1/2]

void ts::IPAddress::setAddress ( uint32_t  addr)
inline

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

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

◆ setAddress() [2/2]

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

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.

◆ isMulticast()

bool ts::IPAddress::isMulticast ( ) const
inline

Check if the address is a multicast address.

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

◆ isSSM()

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

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

Note: SSM addresses are in the range 232.0.0.0/8.

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

◆ hasAddress()

bool ts::IPAddress::hasAddress ( ) const
inline

Check if this object is set to a valid address (ie not AnyAddress).

Returns
True if this object is set to a valid address (ie not AnyAddress), false otherwise.

◆ copy() [1/3]

void ts::IPAddress::copy ( ::sockaddr &  a,
uint16_t  port 
) const

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

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

◆ copy() [2/3]

void ts::IPAddress::copy ( ::sockaddr_in &  a,
uint16_t  port 
) const

Copy the 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.

◆ copy() [3/3]

void ts::IPAddress::copy ( ::in_addr &  a) const
inline

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

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

◆ resolve()

bool ts::IPAddress::resolve ( const UString name,
Report report = (*ts::CerrReport::Instance()) 
)

Decode a string, numeric address or hostname which is resolved.

Parameters
[in]nameA string containing either a host name or a numerical representation of the address "a.b.c.d".
[in]reportWhere to report errors.
Returns
True if name was successfully resolved, false otherwise. In the later case, the integer value of the address is set to AnyAddress.

◆ match()

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

◆ toString()

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

Convert to a string object.

Returns
This object, converted as a string.

Implements ts::StringifyInterface.

Reimplemented in ts::SocketAddress.

◆ operator<()

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

Member Data Documentation

◆ LocalHost

const IPAddress ts::IPAddress::LocalHost
static

Local host address.

Usually resolves to the host name "localhost".


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