![]() |
TSDuck v3.46-4930
MPEG Transport Stream Toolkit
|
#include <tsIPSocketAddress.h>


Public Types | |
| using | Port = uint16_t |
Public Member Functions | |
| IPSocketAddress ()=default | |
| IPSocketAddress (const ::in6_addr &a, Port port) | |
| IPSocketAddress (const ::in_addr &a, Port port) | |
| IPSocketAddress (const ::sockaddr &a) | |
| IPSocketAddress (const ::sockaddr_in &a) | |
| IPSocketAddress (const ::sockaddr_in6 &a) | |
| IPSocketAddress (const ::sockaddr_storage &a) | |
| IPSocketAddress (const ByteBlock &bb, Port port) | |
| IPSocketAddress (const IPAddress &addr, Port port) | |
| IPSocketAddress (const UString &name, Report &report, IP preferred=IP::Any) | |
| IPSocketAddress (const void *addr, size_t size, Port port) | |
| IPSocketAddress (uint16_t h1, uint16_t h2, uint16_t h3, uint16_t h4, uint16_t h5, uint16_t h6, uint16_t h7, uint16_t h8, Port port) | |
| IPSocketAddress (uint32_t addr, Port port) | |
| IPSocketAddress (uint64_t net, uint64_t ifid, Port port) | |
| IPSocketAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, Port port) | |
| uint32_t | address4 () const |
| ByteBlock | address6 () const |
| virtual size_t | binarySize () const override |
| virtual void | clear () |
| virtual void | clearAddress () override |
| virtual void | clearPort () |
| bool | convert (IP gen) |
| virtual const UChar * | familyName () const override |
| IP | generation () const |
| size_t | get (::sockaddr_storage &a) const |
| bool | get4 (::sockaddr_in &a) const |
| bool | get6 (::sockaddr_in6 &a) const |
| size_t | getAddress (::sockaddr_storage &a, Port port) const |
| virtual size_t | getAddress (void *addr, size_t size) const override |
| bool | getAddress4 (::in_addr &a) const |
| bool | getAddress4 (::sockaddr_in &a, Port port) const |
| bool | getAddress6 (::in6_addr &a) const |
| bool | getAddress6 (::sockaddr_in6 &a, Port port) const |
| virtual bool | hasAddress () const override |
| virtual bool | hasPort () const |
| uint16_t | hexlet6 (size_t i) const |
| uint64_t | interfaceIdentifier6 () const |
| bool | isIPv4Mapped () const |
| bool | isLinkLocal () const |
| virtual bool | isMulticast () const override |
| bool | isSSM () const |
| bool | match (const IPAddress &other) const |
| bool | match (const IPSocketAddress &other) const |
| uint64_t | networkPrefix6 () const |
| bool | operator< (const IPAddress &other) const |
| bool | operator< (const IPSocketAddress &other) const |
| bool | operator== (const IPAddress &other) const |
| bool | operator== (const IPSocketAddress &other) const |
| virtual Port | port () const override |
| virtual bool | resolve (const UString &name, Report &report) override |
| virtual bool | resolve (const UString &name, Report &report, IP preferred) override |
| bool | sameMulticast6 (const IPAddress &mc) const |
| uint8_t | scopeMulticast6 () const |
| bool | set (const ::sockaddr &a) |
| bool | set (const ::sockaddr_in &a) |
| bool | set (const ::sockaddr_in6 &a) |
| bool | set (const ::sockaddr_storage &a) |
| bool | setAddress (const ::sockaddr &a) |
| bool | setAddress (const ::sockaddr_in &a) |
| bool | setAddress (const ::sockaddr_in6 &a) |
| bool | setAddress (const ::sockaddr_storage &a) |
| bool | setAddress (const ByteBlock &bb) |
| void | setAddress (const IPAddress &other) |
| virtual bool | setAddress (const void *addr, size_t size) override |
| void | setAddress4 (const ::in_addr &a) |
| void | setAddress4 (uint32_t addr) |
| void | setAddress4 (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) |
| void | setAddress6 (const ::in6_addr &a) |
| void | setAddress6 (uint16_t h1, uint16_t h2, uint16_t h3, uint16_t h4, uint16_t h5, uint16_t h6, uint16_t h7, uint16_t h8) |
| void | setAddress6 (uint64_t net, uint64_t ifid) |
| void | setDefault (const IPSocketAddress &other) |
| virtual void | setPort (Port port) override |
| virtual UString | toFullString () const override |
| virtual UString | toString () const override |
Static Public Member Functions | |
| static size_t | AddressBits (IP gen) |
| static const IPAddress & | AnyAddress (IP gen) |
| static const IPSocketAddress & | AnySocketAddress (IP gen) |
| static const IPAddress & | LocalHost (IP gen) |
| static void | RemovePort (UString &name) |
| static bool | ResolveAllAddresses (IPAddressVector &addresses, const UString &name, Report &report, IP gen=IP::Any) |
Static Public Attributes | |
| static const IPAddress | AnyAddress4 |
| Wildcard value for "any IPv4 address". | |
| static const IPAddress | AnyAddress6 |
| Wildcard value for "any IPv6 address". | |
| static constexpr Port | AnyPort = 0 |
| static const IPSocketAddress | AnySocketAddress4 |
| Wildcard socket address, unspecified IPv4 address and port. | |
| static const IPSocketAddress | AnySocketAddress6 |
| Wildcard socket address, unspecified IPv6 address and port. | |
| static constexpr size_t | BITS4 = 32 |
| Size in bits of an IPv4 address. | |
| static constexpr size_t | BITS6 = 128 |
| Size in bits of an IPv6 address. | |
| static constexpr size_t | BYTES4 = 4 |
| Size in bytes of an IPv4 address. | |
| static constexpr size_t | BYTES6 = 16 |
| Size in bytes of an IPv6 address. | |
| static const IPAddress | LocalHost4 |
| Local host IPv4 address ("localhost"). | |
| static const IPAddress | LocalHost6 |
| Local host IPv6 address (::1, "localhost"). | |
Generic socket address class (IPv4 or IPv6 address & port).
The string representation is "addr[:port]" or "[addr:]port".
In this class, methods which apply to only one generation, IPv4 or IPv6, have a name ending in 4 or 6, respectively. Some constructors implicitly build one generation of address, IPv4 or IPv6, but their names remain IPAddress() without trailing 4 or 6 by design of C++.
|
inherited |
The concept of port is used by TCP and UDP over IP networks.
|
default |
Default constructor The default initial value is AnySocketAddress4.
Generic constructor from an address and port.
| [in] | addr | Address. |
| [in] | port | Port number as an integer in host byte order. |
|
inline |
Generic constructor from an address in binary format.
| [in] | addr | Address of the memory area containing the address in binary format. |
| [in] | size | Size of the memory area. If the size is 4, this is an IPv4 address. If the size is 16, this is an IPv6 address. For all other sizes, the address is AnyAddress4. |
| [in] | port | Optional port number as an integer in host byte order. |
Generic constructor from an address in binary format.
| [in] | bb | Byte block containing the address in binary format. If the size is 4, this is an IPv4 address. If the size is 16, this is an IPv6 address. For all other sizes, the address is AnyAddress4. |
| [in] | port | Optional port number as an integer in host byte order. |
|
inline |
IPv4 constructor from an integer IPv4 address.
| [in] | addr | The IP v4 address as an integer in host byte order. |
| [in] | port | Optional port number as an integer in host byte order. |
|
inline |
IPv4 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. |
| [in] | port | Optional port number as an integer in host byte order. |
|
inline |
IPv6 constructor of an IPv6 address from 8 hexlets.
| [in] | h1 | First address hexlet. |
| [in] | h2 | 2nd address hexlet. |
| [in] | h3 | 3rd address hexlet. |
| [in] | h4 | 4th address hexlet. |
| [in] | h5 | 5th address hexlet. |
| [in] | h6 | 6th address hexlet. |
| [in] | h7 | 7th address hexlet. |
| [in] | h8 | 8th address hexlet. |
| [in] | port | Optional port number as an integer in host byte order. |
|
inline |
IPv6 constructor of an IPv6 address from network prefix and interface identifier.
| [in] | net | Network prefix. |
| [in] | ifid | Interface identifier. |
| [in] | port | Optional port number as an integer in host byte order. |
| ts::IPSocketAddress::IPSocketAddress | ( | const ::sockaddr & | a | ) |
Generic constructor from a system "struct sockaddr" structure (IPv4 or IPv6).
| [in] | a | A system "struct sockaddr" structure. Note: the structure "sockaddr" is deprecated because it cannot hold an IPv6 socket address. The structure "sockaddr_storage" should be used instead. |
|
inline |
Generic constructor from a system "struct sockaddr_storage" structure (IPv4 or IPv6).
| [in] | a | A system "struct sockaddr_storage" structure. |
|
inline |
IPv4 constructor from a system "struct in_addr" structure (IPv4 socket API).
| [in] | a | A system "struct in_addr" structure. |
| [in] | port | Optional port number as an integer in host byte order. |
|
inline |
IPv4 constructor from a system "struct sockaddr_in" structure (IPv4 socket API).
| [in] | a | A system "struct sockaddr_in" structure. |
|
inline |
IPv6 constructor from a system "struct in6_addr" structure (IPv6 socket API).
| [in] | a | A system "struct in6_addr" structure. |
| [in] | port | Optional port number as an integer in host byte order. |
|
inline |
IPv6 constructor from a system "struct sockaddr_in6" structure (IPv6 socket API).
| [in] | a | A system "struct sockaddr_in6" structure. |
|
inline |
Constructor from a string, host name or integer format. If name cannot be resolved, the address is set to AnyAddress4.
| [in] | name | A string containing either a host name or a numerical representation of the address. |
| [in] | report | Where to report errors. |
| [in] | preferred | Preferred IP generation of the returned address. Return the first availabale address by default. |
|
inlinestatic |
|
overridevirtual |
Get the port if there is one. The default implementation returns AnyPort.
Reimplemented from ts::AbstractNetworkAddress.
|
overridevirtual |
Set the port. The default implementation does nothing.
| [in] | port | The port number as an integer in host byte order. |
Reimplemented from 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. |
Reimplemented from ts::IPAddress.
|
overridevirtual |
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 from ts::IPAddress.
|
overridevirtual |
Convert to a string object.
Reimplemented from ts::IPAddress.
|
static |
Remove the port number from a "addr[:port]" or "[addr:]port" string.
| [in,out] | name | A string where the port number is removed. |
| bool ts::IPSocketAddress::set | ( | const ::sockaddr & | a | ) |
Set the IP address and port from a system "struct sockaddr" structure (IPv4 or IPv6).
| [in] | a | A system "struct sockaddr" structure. Note: the structure "sockaddr" is deprecated because it cannot hold an IPv6 socket address. The structure "sockaddr_storage" should be used instead. |
|
inline |
Set the IP address and port from a system "struct sockaddr_storage" structure (IPv4 or IPv6).
| [in] | a | A system "struct sockaddr_storage" structure. |
|
inline |
Set the IPv4 address and port from a system "struct sockaddr_in" structure.
| [in] | a | A system "struct sockaddr_in" structure. |
|
inline |
Set the IPv6 address and port from a system "struct sockaddr_in6" structure.
| [in] | a | A system "struct sockaddr_in6" structure. |
|
inline |
Get the address and port into a system "struct sockaddr_storage" structure. Note: the structure "sockaddr" is deprecated because it cannot hold an IPv6 socket address. The structure "sockaddr_storage" should be used instead.
| [out] | a | A system "struct sockaddr_storage" structure. This type of structure is large enough to hold a structure sockaddr_in or sockaddr_in6. |
|
inline |
Get the IPv4 address and port into a system "struct sockaddr_in" structure.
| [out] | a | A system "struct sockaddr_in" structure. |
|
inline |
Get the IPv6 address and port into a system "struct sockaddr_in6" structure.
| [out] | a | A system "struct sockaddr_in6" structure. |
| bool ts::IPSocketAddress::match | ( | const IPSocketAddress & | other | ) | const |
Check if this socket address "matches" another one.
| [in] | other | Another instance to compare. |
| void ts::IPSocketAddress::setDefault | ( | const IPSocketAddress & | other | ) |
Set missing address and/or port from a default socket address.
| [in] | other | Another instance to get default address and/or port. |
|
overridevirtual |
Decode a string containing a socket address in family-specific format.
| [in] | name | A string containing either a host name or a numerical representation of the address and a port. |
| [in] | report | Where to report errors. |
| [in] | preferred | Preferred IP generation of the returned address. Return the first availabale address by default. If no address of that generation is available, return one from the other generation if available. |
Reimplemented from ts::IPAddress.
|
inline |
Equality operator.
| [in] | other | Another instance to compare with. |
| bool ts::IPSocketAddress::operator< | ( | const IPSocketAddress & | 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. |
|
inlinestaticinherited |
|
inherited |
Equality operator.
| [in] | other | Another instance to compare with. |
|
inherited |
Comparison "less than" operator. It does not really makes sense. Only defined to allow usage in containers.
| [in] | other | Other instance to compare. |
|
inherited |
Check if this address "matches" another one.
| [in] | other | Another instance to compare. |
|
inlineinherited |
|
inherited |
Check if the address is an IPv6 address which is mapped to an IPv4 one.
|
inherited |
Convert an IP address to another generation, when possible.
| [in] | gen | New IP generation to apply. If gen is IP::Any or the same as the current generation, return true. A conversion from IPv4 to IPv6 always works (IPv4-mapped address). The conversion of an IPv6 address into IPv4 is only possible if it is an IPv4-mapped address. For convenience, the IPv4 and IPv6 ampty and loopback addresses are converted to each other. |
|
overridevirtualinherited |
Get the maximum binary size in bytes for an address of that class.
Implements ts::AbstractNetworkAddress.
|
overridevirtualinherited |
Get a human-readable family name for an address of that class. This is typically something like "IPv4" or "IPv6".
Implements ts::AbstractNetworkAddress.
|
overridevirtualinherited |
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.
|
inherited |
Copy the address into a system "struct sockaddr_storage" structure (socket API). Note: the structure "sockaddr" is deprecated because it cannot hold an IPv6 socket address. The structure "sockaddr_storage" should be used instead.
| [out] | a | A system "struct sockaddr_storage" structure. This type of structure is large enough to hold a structure sockaddr_in or sockaddr_in6. |
| [in] | port | Port number for the socket address. |
|
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.
|
inherited |
|
inlineinherited |
Set the IP address from an address in binary format. Useful for subclasses to assign the address part only.
| [in] | bb | Byte block containing the address in binary format. If the size is 4, this is an IPv4 address. If the size is 16, this is an IPv6 address. For all other sizes, the address is AnyAddress4. |
|
inherited |
Set the IP address from a system "struct sockaddr" structure (IPv4 or IPv6).
| [in] | a | A system "struct sockaddr" structure. Note: the structure "sockaddr" is deprecated because it cannot hold an IPv6 socket address. The structure "sockaddr_storage" should be used instead. |
|
inlineinherited |
Set the IP address from a system "struct sockaddr_storage" structure (IPv4 or IPv6).
| [in] | a | A system "struct sockaddr_storage" structure. |
|
inlineinherited |
Set the IPv4 address from a system "struct sockaddr_in" structure.
| [in] | a | A system "struct sockaddr_in" structure. |
|
inlineinherited |
Set the IPv6 address from a system "struct sockaddr_in6" structure.
| [in] | a | A system "struct sockaddr_in6" structure. |
|
overridevirtualinherited |
Clear the address field.
Implements ts::AbstractNetworkAddress.
|
overridevirtualinherited |
Check if the address is a multicast address.
Implements ts::AbstractNetworkAddress.
|
inherited |
Check if the address is a source specific multicast (SSM) address.
|
inherited |
Check if two IPv6 multicast addresses are identical, excluding the "scope" bits. If this address or mc are socket addresses, they must also have the same port.
| [in] | mc | Another IPv6 multicast address. |
|
inherited |
Get the IPv6 multicast "scope" bits of this address.
|
inherited |
Check if the address is a link-local address, typically an auto-configured address.
|
inlineinherited |
Get the IPv4 address as a 32-bit integer value in host byte order.
|
inherited |
Get the IPv6 address as a byte block.
|
inherited |
Get the IPv6 network prefix (64 most significant bits) of the IPv6 address.
|
inherited |
Get the IPv6 interface identifier (64 least significant bits) of the IPv6 address.
|
inherited |
Get one of the 16-bit hexlets in the IPv6 address.
| [in] | i | Hexlet index, from 0 to 7. |
|
inherited |
|
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. |
|
inherited |
Set the IPv4 address from a system "struct in_addr" structure.
| [in] | a | A system "struct in_addr" structure. |
|
inherited |
Set the IP address from an IPv6 address as 8 hexlets.
| [in] | h1 | First address hexlet. |
| [in] | h2 | 2nd address hexlet. |
| [in] | h3 | 3rd address hexlet. |
| [in] | h4 | 4th address hexlet. |
| [in] | h5 | 5th address hexlet. |
| [in] | h6 | 6th address hexlet. |
| [in] | h7 | 7th address hexlet. |
| [in] | h8 | 8th address hexlet. |
|
inherited |
Set the IP address from an IPv6 address as network prefix and interface identifier.
| [in] | net | Network prefix. |
| [in] | ifid | Interface identifier. |
|
inherited |
Set the IPv6 address from a system "struct in6_addr" structure.
| [in] | a | A system "struct in6_addr" structure. |
|
inherited |
Copy the IPv4 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 |
Copy the IPv4 address into a system "struct in_addr" structure (socket API).
| [out] | a | A system "struct in_addr" structure. |
|
inherited |
Copy the IPv6 address into a system "struct sockaddr_in6" structure (socket API).
| [out] | a | A system "struct sockaddr_in6" structure. |
| [in] | port | Port number for the socket address. |
|
inherited |
Copy the IPv6 address into a system "struct in6_addr" structure (socket API).
| [out] | a | A system "struct in6_addr" structure. |
|
staticinherited |
Decode a host name and get all possible addresses for that host.
| [out] | addresses | List of possible addresses for name. If name is a valid numerical addresse, only this one is returned. |
| [in] | name | A string containing either a host name or a numerical representation of the address. |
| [in,out] | report | Where to report errors. |
| [in] | gen | IP generation of the returned address. Can be used to restrict the result to IPv4 or IPv6 addresses. Return all by default. |
|
virtualinherited |
Clear the object, address and port if there is any.
|
virtualinherited |
Check if a port is set.
|
virtualinherited |
Clear the port. The default implementatio sets the port to AnyPort
|
staticconstexprinherited |
Wildcard integer value for "any port" or "no port".