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

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

Inheritance diagram for ts::IPv4Address:
Collaboration diagram for ts::IPv4Address:

Public Types

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

Public Member Functions

 IPv4Address ()
 Default constructor.
 
 IPv4Address (const ::in_addr &a)
 Constructor from a system "struct in_addr" structure (socket API). More...
 
 IPv4Address (const ::sockaddr &a)
 Constructor from a system "struct sockaddr" structure (socket API). More...
 
 IPv4Address (const ::sockaddr_in &a)
 Constructor from a system "struct sockaddr_in" structure (socket API). More...
 
 IPv4Address (const UString &name, Report &report)
 Constructor from a string, host name or "a.b.c.d" integer format. More...
 
 IPv4Address (uint32_t addr)
 Constructor from an integer address. More...
 
 IPv4Address (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4)
 Constructor from 4 bytes (classical IPv4 notation). More...
 
virtual ~IPv4Address () 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_in &a, uint16_t port) const
 Copy the address 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 operator!= (const IPv4Address &a) const
 Unequality operator. More...
 
bool operator< (const IPv4Address &other) const
 Comparison "less than" operator. More...
 
bool operator== (const IPv4Address &a) const
 Equality operator. More...
 
virtual Port port () const
 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 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)
 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 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

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

The string representation is "int.int.int.int".

Constructor & Destructor Documentation

◆ IPv4Address() [1/6]

ts::IPv4Address::IPv4Address ( uint32_t  addr)
inline

Constructor from an integer address.

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

◆ IPv4Address() [2/6]

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

◆ IPv4Address() [3/6]

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

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

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

◆ IPv4Address() [4/6]

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

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

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

◆ IPv4Address() [5/6]

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

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

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

◆ IPv4Address() [6/6]

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

◆ binarySize()

virtual size_t ts::IPv4Address::binarySize ( ) const
overridevirtual

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
overridevirtual

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
overridevirtual

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

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.

◆ isMulticast()

virtual bool ts::IPv4Address::isMulticast ( ) const
overridevirtual

Check if the address is a multicast address.

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

Implements ts::AbstractNetworkAddress.

◆ resolve()

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

Implements ts::AbstractNetworkAddress.

Reimplemented in ts::IPv4SocketAddress.

◆ toString()

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

Convert to a string object.

Returns
This object, converted as a string.

Implements ts::StringifyInterface.

Reimplemented in ts::IPv4SocketAddress.

◆ address()

uint32_t ts::IPv4Address::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() [2/4]

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

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

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 
)

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.

◆ isSSM()

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

◆ copy() [1/3]

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

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

◆ operator==()

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

Unequality operator.

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

◆ operator<()

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

◆ hasPort()

virtual bool ts::AbstractNetworkAddress::hasPort ( ) const
virtualinherited

Check if a port is set.

Returns
True if port is set.

◆ port()

virtual Port ts::AbstractNetworkAddress::port ( ) const
virtualinherited

Get the port if there is one.

The default implementation returns AnyPort.

Returns
The port number or AnyPort if there is none.

Reimplemented in ts::IPv6SocketAddress, and ts::IPv4SocketAddress.

◆ setPort()

virtual void ts::AbstractNetworkAddress::setPort ( Port  port)
virtualinherited

Set the port.

The default implementation does nothing.

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

Reimplemented in ts::IPv6SocketAddress, and ts::IPv4SocketAddress.

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

Local host address.

Usually resolves to the host name "localhost".


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