TSDuck Version 3.32-2780 (TSDuck - The MPEG Transport Stream Toolkit)
ts::IPv4SocketAddress Class Reference

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

Inheritance diagram for ts::IPv4SocketAddress:
Collaboration diagram for ts::IPv4SocketAddress:

Public Types

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

Public Member Functions

 IPv4SocketAddress ()
 Default constructor.
 
 IPv4SocketAddress (const ::in_addr &a, uint16_t port=AnyPort)
 Constructor from a system "struct in_addr" structure (socket API). More...
 
 IPv4SocketAddress (const ::sockaddr &s)
 Constructor from a system "struct sockaddr" structure (socket API). More...
 
 IPv4SocketAddress (const ::sockaddr_in &s)
 Constructor from a system "struct sockaddr_in" structure (socket API). More...
 
 IPv4SocketAddress (const IPv4Address &addr, uint16_t port=AnyPort)
 Constructor from an IP address and optional port. More...
 
 IPv4SocketAddress (const UString &name, Report &report)
 Constructor from a string "addr[:port]" or "[addr:]port". More...
 
 IPv4SocketAddress (uint32_t addr, uint16_t port=AnyPort)
 Constructor from an integer address and optional port. More...
 
 IPv4SocketAddress (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...
 
virtual ~IPv4SocketAddress () override
 Virtual destructor.
 
uint32_t address () const
 Get the IP address as a 32-bit integer value in host byte order. More...
 
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 copy (::in_addr &a) const
 Copy the address into a system "struct in_addr" structure (socket API). More...
 
void copy (::sockaddr &a, uint16_t port) const
 Copy the address into a system "struct sockaddr" structure (socket API). More...
 
void copy (::sockaddr &s) const
 Copy 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_in &s) const
 Copy into a system "struct sockaddr_in" structure (socket API). 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...
 
virtual bool isMulticast () const override
 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 IPv4Address &other) const
 Check if this address "matches" another one. More...
 
bool match (const IPv4SocketAddress &other) const
 Check if this socket address "matches" another one. More...
 
bool operator!= (const IPv4Address &a) const
 Unequality operator. More...
 
bool operator!= (const IPv4SocketAddress &other) const
 Unequality operator. More...
 
bool operator< (const IPv4Address &other) const
 Comparison "less than" operator. More...
 
bool operator< (const IPv4SocketAddress &other) const
 Comparison "less than" operator. More...
 
bool operator== (const IPv4Address &a) const
 Equality operator. More...
 
bool operator== (const IPv4SocketAddress &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 (uint32_t addr, uint16_t port)
 Set an integer address and 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 port. More...
 
void setAddress (const IPv4Address &addr)
 Set the IP address from another IPv4Address object. More...
 
virtual bool setAddress (const void *addr, size_t size) override
 Set the network address from binary data. 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 void setPort (Port port) override
 Set the port. More...
 
virtual UString toFullString () const
 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 uint32_t AnyAddress = 0
 Wildcard integer value for "any IP address".
 
static const Port AnyPort = 0
 Wildcard integer value for "any port" or "no port".
 
static const IPv4SocketAddress AnySocketAddress
 Wildcard socket address, unspecified address and port.
 
static constexpr size_t BITS = 32
 Size in bits of an IPv4 address.
 
static constexpr size_t BYTES = 4
 Size in bytes of an IPv4 address.
 
static const IPv4Address 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.

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

Constructor & Destructor Documentation

◆ IPv4SocketAddress() [1/7]

ts::IPv4SocketAddress::IPv4SocketAddress ( const IPv4Address 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.

◆ IPv4SocketAddress() [2/7]

ts::IPv4SocketAddress::IPv4SocketAddress ( 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.

◆ IPv4SocketAddress() [3/7]

ts::IPv4SocketAddress::IPv4SocketAddress ( 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.

◆ IPv4SocketAddress() [4/7]

ts::IPv4SocketAddress::IPv4SocketAddress ( 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.

◆ IPv4SocketAddress() [5/7]

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

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

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

◆ IPv4SocketAddress() [6/7]

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

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

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

◆ IPv4SocketAddress() [7/7]

ts::IPv4SocketAddress::IPv4SocketAddress ( const UString name,
Report report 
)
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()

virtual Port ts::IPv4SocketAddress::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::IPv4SocketAddress::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::IPv4SocketAddress::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::IPv4Address.

◆ toString()

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

Convert to a string object.

Returns
This object, converted as a string.

Reimplemented from ts::IPv4Address.

◆ set() [1/2]

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

Set an integer address and 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::IPv4SocketAddress::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 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.

◆ copy() [1/5]

void ts::IPv4SocketAddress::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::IPv4SocketAddress::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::IPv4SocketAddress::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.

◆ match() [1/2]

bool ts::IPv4SocketAddress::match ( const IPv4SocketAddress 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::IPv4SocketAddress::operator== ( const IPv4SocketAddress 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::IPv4SocketAddress::operator!= ( const IPv4SocketAddress 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::IPv4SocketAddress::operator< ( const IPv4SocketAddress 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::IPv4Address::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::IPv4Address::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()

virtual size_t ts::IPv4Address::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.

◆ setAddress() [1/4]

virtual bool ts::IPv4Address::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::IPv4Address::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() [3/4]

void ts::IPv4Address::setAddress ( const IPv4Address addr)
inlineinherited

Set the IP address from another IPv4Address object.

Useful for subclasses.

Parameters
[in]addrAnother IP address.

◆ setAddress() [4/4]

void ts::IPv4Address::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()

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

◆ address()

uint32_t ts::IPv4Address::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.

◆ isSSM()

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

◆ copy() [4/5]

void ts::IPv4Address::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::IPv4Address::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::IPv4Address::match ( const IPv4Address 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::IPv4Address::operator== ( const IPv4Address a) const
inlineinherited

Equality operator.

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

◆ operator!=() [2/2]

bool ts::IPv4Address::operator!= ( const IPv4Address a) const
inlineinherited

Unequality operator.

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

◆ operator<() [2/2]

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

◆ toFullString()

virtual UString ts::AbstractNetworkAddress::toFullString ( ) const
virtualinherited

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 in ts::IPv6SocketAddress, and ts::IPv6Address.

Member Data Documentation

◆ LocalHost

const IPv4Address ts::IPv4Address::LocalHost
staticinherited

Local host address.

Usually resolves to the host name "localhost".


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