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