TSDuck v3.40-3963
MPEG Transport Stream Toolkit
|
A basic representation of an IP v4 address. More...
#include <tsIPv4Address.h>
Public Types | |
using | Port = uint16_t |
The concept of port is used by TCP and UDP over IP networks. | |
Public Member Functions | |
IPv4Address ()=default | |
Default constructor. | |
IPv4Address (const ::in_addr &a) | |
Constructor from a system "struct in_addr" structure (socket API). | |
IPv4Address (const ::sockaddr &a) | |
Constructor from a system "struct sockaddr" structure (socket API). | |
IPv4Address (const ::sockaddr_in &a) | |
Constructor from a system "struct sockaddr_in" structure (socket API). | |
IPv4Address (const UString &name, Report &report) | |
Constructor from a string, host name or "a.b.c.d" integer format. | |
IPv4Address (uint32_t addr) | |
Constructor from an integer address. | |
IPv4Address (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) | |
Constructor from 4 bytes (classical IPv4 notation). | |
uint32_t | address () const |
Get the IP address as a 32-bit integer value in host byte order. | |
virtual size_t | binarySize () const override |
Get the maximum binary size for an address of that class. | |
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. | |
void | copy (::in_addr &a) const |
Copy the address into a system "struct in_addr" structure (socket API). | |
void | copy (::sockaddr &a, uint16_t port) const |
Copy the address into a system "struct sockaddr" structure (socket API). | |
void | copy (::sockaddr_in &a, uint16_t port) const |
Copy the address into a system "struct sockaddr_in" structure (socket API). | |
virtual const UChar * | familyName () const override |
Get a human-readable family name for an address of that class. | |
virtual size_t | getAddress (void *addr, size_t size) const override |
Get the network address as binary data. | |
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. | |
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 IPv4Address &other) const |
Check if this address "matches" another one. | |
bool | operator< (const IPv4Address &other) const |
Comparison "less than" operator. | |
bool | operator== (const IPv4Address &a) const |
Equality operator. | |
virtual Port | port () const |
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 | setAddress (const IPv4Address &addr) |
Set the IP address from another IPv4Address object. | |
virtual bool | setAddress (const void *addr, size_t size) override |
Set the network address from binary data. | |
void | setAddress (uint32_t addr) |
Set the IP address from a 32-bit integer value in host byte order. | |
void | setAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) |
Set the IP address from 4 bytes (classical IPv4 notation). | |
virtual void | setPort (Port port) |
Set the port. | |
virtual UString | toFullString () const |
Convert to a string object in numeric format without the default compaction. | |
virtual UString | toString () const override |
Convert to a string object. | |
Static Public Attributes | |
static constexpr uint32_t | AnyAddress = 0 |
Wildcard integer value for "any IP address". | |
static constexpr 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. | |
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".
|
inline |
Constructor from an integer address.
[in] | addr | The IP v4 address as an integer in host byte order. |
ts::IPv4Address::IPv4Address | ( | uint8_t | b1, |
uint8_t | b2, | ||
uint8_t | b3, | ||
uint8_t | b4 | ||
) |
Constructor from 4 bytes (classical IPv4 notation).
[in] | b1 | First address byte. |
[in] | b2 | Second address byte. |
[in] | b3 | Third address byte. |
[in] | b4 | Fourth address byte. |
|
inline |
Constructor from a system "struct in_addr" structure (socket API).
[in] | a | A system "struct in_addr" structure. |
ts::IPv4Address::IPv4Address | ( | const ::sockaddr & | a | ) |
Constructor from a system "struct sockaddr" structure (socket API).
[in] | a | A system "struct sockaddr" structure. |
ts::IPv4Address::IPv4Address | ( | const ::sockaddr_in & | a | ) |
Constructor from a system "struct sockaddr_in" structure (socket API).
[in] | a | A system "struct sockaddr_in" structure. |
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.
[in] | name | A string containing either a host name or a numerical representation of the address "a.b.c.d". |
[in] | report | Where to report errors. |
|
overridevirtual |
Get the maximum binary size for an address of that class.
Implements ts::AbstractNetworkAddress.
|
overridevirtual |
Get a human-readable family name for an address of that class.
This is typically something like "IPv4" or "IPv6".
Implements ts::AbstractNetworkAddress.
|
overridevirtual |
Check if this object is set to a valid address.
Implements ts::AbstractNetworkAddress.
|
overridevirtual |
Get the network address as binary data.
[out] | addr | Address of binary buffer to receive binary data. |
[in] | size | Size in bytes of buffer. |
Implements ts::AbstractNetworkAddress.
|
overridevirtual |
Set the network address from binary data.
[in] | addr | Address of binary data. |
[in] | size | Size in bytes of binary data. |
Implements ts::AbstractNetworkAddress.
|
overridevirtual |
Clear the address field.
Implements ts::AbstractNetworkAddress.
|
overridevirtual |
Check if the address is a multicast address.
Implements ts::AbstractNetworkAddress.
Decode a string containing a network address in family-specific format.
[in] | name | A string containing either a host name or a numerical representation of the address. |
[in] | report | Where to report errors. |
Implements ts::AbstractNetworkAddress.
Reimplemented in ts::IPv4SocketAddress.
|
overridevirtual |
Convert to a string object.
Implements ts::StringifyInterface.
Reimplemented in ts::IPv4SocketAddress.
|
inline |
Get the IP address as a 32-bit integer value in host byte order.
|
inline |
Set the IP address from a 32-bit integer value in host byte order.
[in] | addr | The IP v4 address as an integer in host byte order. |
|
inline |
Set the IP address from another IPv4Address object.
Useful for subclasses.
[in] | addr | Another IP address. |
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).
[in] | b1 | First address byte. |
[in] | b2 | Second address byte. |
[in] | b3 | Third address byte. |
[in] | b4 | Fourth address byte. |
|
inline |
Check if the address is a source specific multicast (SSM) address.
Note: SSM addresses are in the range 232.0.0.0/8.
void ts::IPv4Address::copy | ( | ::sockaddr & | a, |
uint16_t | port | ||
) | const |
Copy the address into a system "struct sockaddr" structure (socket API).
[out] | a | A system "struct sockaddr" structure. |
[in] | port | Port number for the socket address. |
void ts::IPv4Address::copy | ( | ::sockaddr_in & | a, |
uint16_t | port | ||
) | const |
Copy the address into a system "struct sockaddr_in" structure (socket API).
[out] | a | A system "struct sockaddr_in" structure. |
[in] | port | Port number for the socket address. |
|
inline |
Copy the address into a system "struct in_addr" structure (socket API).
[out] | a | A system "struct in_addr" structure. |
bool ts::IPv4Address::match | ( | const IPv4Address & | other | ) | const |
Check if this address "matches" another one.
[in] | other | Another instance to compare. |
|
inline |
Equality operator.
[in] | a | Another instance to compare with. |
|
inline |
Comparison "less than" operator.
It does not really makes sense. Only defined to allow usage in containers.
[in] | other | Other instance to compare. |
|
virtualinherited |
Check if a port is set.
|
virtualinherited |
Get the port if there is one.
The default implementation returns AnyPort.
Reimplemented in ts::IPv4SocketAddress, and ts::IPv6SocketAddress.
|
virtualinherited |
Set the port.
The default implementation does nothing.
[in] | port | The port number as an integer in host byte order. |
Reimplemented in ts::IPv4SocketAddress, and ts::IPv6SocketAddress.
|
virtualinherited |
Clear the port.
The default implementatio sets the port to AnyPort
|
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().
Reimplemented in ts::IPv6Address, and ts::IPv6SocketAddress.
|
static |
Local host address.
Usually resolves to the host name "localhost".