TSDuck Version 3.16-1064 (TSDuck - The MPEG Transport Stream Toolkit)
ts::SocketAddress Class Reference

Socket address class (IP v4 address & port). More...

Inheritance diagram for ts::SocketAddress:
Collaboration diagram for ts::SocketAddress:

Public Member Functions

 SocketAddress ()
 Default constructor.
 
 SocketAddress (const IPAddress &addr, uint16_t port=AnyPort)
 Constructor from an IP address and optional port. More...
 
 SocketAddress (uint32_t addr, uint16_t port=AnyPort)
 Constructor from an integer address and optional port. More...
 
 SocketAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint16_t port=AnyPort)
 Constructor from 4 bytes (classical IPv4 notation) and optional port. More...
 
 SocketAddress (const ::in_addr &a, uint16_t port=AnyPort)
 Constructor from a system "struct in_addr" structure (socket API). More...
 
 SocketAddress (const ::sockaddr &s)
 Constructor from a system "struct sockaddr" structure (socket API). More...
 
 SocketAddress (const ::sockaddr_in &s)
 Constructor from a system "struct sockaddr_in" structure (socket API). More...
 
 SocketAddress (const UString &name, Report &report=(*ts::CerrReport::Instance()))
 Constructor from a string "addr[:port]" or "[addr:]port". More...
 
virtual ~SocketAddress ()
 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 and port.
 
void clearAddress ()
 Clear address.
 
void clearPort ()
 Clear port.
 
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 (::sockaddr &s) const
 Copy into a system "struct sockaddr" structure (socket API). More...
 
void copy (::sockaddr_in &s) const
 Copy 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 hasPort () const
 Check if port is set. 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 match (const SocketAddress &other) const
 Check if this socket 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 SocketAddress &other) const
 Comparison "less than" operator. More...
 
bool operator== (const IPAddress &a) const
 Equality operator. More...
 
uint16_t port () const
 Get the port. More...
 
bool resolve (const UString &name, Report &report=(*ts::CerrReport::Instance()))
 Decode a string "addr[:port]" or "[addr:]port". More...
 
void set (uint32_t addr, uint16_t port)
 Set an integer address and optional port. More...
 
void set (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint16_t port)
 Set address from 4 bytes (classical IPv4 notation) and optional port. 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...
 
void setPort (uint16_t port)
 Set the port. 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 uint16_t AnyPort = 0
 Wildcard integer value for "any port".
 
static const IPAddress LocalHost
 Local host address. More...
 

Detailed Description

Socket address class (IP v4 address & port).

Note: all address and port are used in host byte order.

Constructor & Destructor Documentation

◆ SocketAddress() [1/7]

ts::SocketAddress::SocketAddress ( const IPAddress addr,
uint16_t  port = AnyPort 
)
inline

Constructor from an IP address and optional port.

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

◆ SocketAddress() [2/7]

ts::SocketAddress::SocketAddress ( uint32_t  addr,
uint16_t  port = AnyPort 
)
inline

Constructor from an integer address and optional port.

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

◆ SocketAddress() [3/7]

ts::SocketAddress::SocketAddress ( uint8_t  b1,
uint8_t  b2,
uint8_t  b3,
uint8_t  b4,
uint16_t  port = AnyPort 
)
inline

Constructor from 4 bytes (classical IPv4 notation) and optional port.

Parameters
[in]b1First address byte.
[in]b2Second address byte.
[in]b3Third address byte.
[in]b4Fourth address byte.
[in]portThe port number as an integer in host byte order.

◆ SocketAddress() [4/7]

ts::SocketAddress::SocketAddress ( const ::in_addr &  a,
uint16_t  port = AnyPort 
)
inline

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

Parameters
[in]aA system "struct in_addr" structure.
[in]portThe port number as an integer in host byte order.

◆ SocketAddress() [5/7]

ts::SocketAddress::SocketAddress ( const ::sockaddr &  s)

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

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

◆ SocketAddress() [6/7]

ts::SocketAddress::SocketAddress ( const ::sockaddr_in &  s)

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

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

◆ SocketAddress() [7/7]

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

Constructor from a string "addr[:port]" or "[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()

uint16_t ts::SocketAddress::port ( ) const
inline

Get the port.

Returns
The port.

◆ setPort()

void ts::SocketAddress::setPort ( uint16_t  port)
inline

Set the port.

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

◆ set() [1/2]

void ts::SocketAddress::set ( uint32_t  addr,
uint16_t  port 
)
inline

Set an integer address and optional port.

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

◆ set() [2/2]

void ts::SocketAddress::set ( uint8_t  b1,
uint8_t  b2,
uint8_t  b3,
uint8_t  b4,
uint16_t  port 
)
inline

Set address from 4 bytes (classical IPv4 notation) and optional port.

Parameters
[in]b1First address byte.
[in]b2Second address byte.
[in]b3Third address byte.
[in]b4Fourth address byte.
[in]portThe port number as an integer in host byte order.

◆ hasPort()

bool ts::SocketAddress::hasPort ( ) const
inline

Check if port is set.

Returns
True if port is set.

◆ copy() [1/5]

void ts::SocketAddress::copy ( ::sockaddr &  s) const
inline

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

Parameters
[out]sA system "struct sockaddr" structure.

◆ copy() [2/5]

void ts::SocketAddress::copy ( ::sockaddr_in &  s) const
inline

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

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

◆ copy() [3/5]

void ts::SocketAddress::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::SocketAddress::resolve ( const UString name,
Report report = (*ts::CerrReport::Instance()) 
)

Decode a string "addr[:port]" or "[addr:]port".

Parameters
[in]nameA string containing either a host name or a numerical representation of the address and optional port.
[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 and port to AnyPort.

◆ match() [1/2]

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

◆ toString()

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

Convert to a string object.

Returns
This object, converted as a string.

Reimplemented from ts::IPAddress.

◆ operator<() [1/2]

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

◆ operator==()

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

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
inlineinherited

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
inlineinherited

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

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

◆ isMulticast()

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

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
inlineinherited

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
inlineinherited

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() [4/5]

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

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() [5/5]

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

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.

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

◆ operator<() [2/2]

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

Member Data Documentation

◆ LocalHost

const IPAddress ts::IPAddress::LocalHost
staticinherited

Local host address.

Usually resolves to the host name "localhost".


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