TSDuck v3.40-3963
MPEG Transport Stream Toolkit
|
A basic representation of a MAC address. More...
#include <tsMACAddress.h>
Public Types | |
using | Port = uint16_t |
The concept of port is used by TCP and UDP over IP networks. | |
Public Member Functions | |
MACAddress ()=default | |
Default constructor. | |
MACAddress (const UString &name, Report &report) | |
Constructor from a string in "a:b:c:d:e:f" format. | |
MACAddress (uint64_t addr) | |
Constructor from an integer address. | |
MACAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6) | |
Constructor from 6 bytes. | |
uint64_t | address () const |
Get the MAC address as a 48-bit integer value. | |
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. | |
virtual const UChar * | familyName () const override |
Get a human-readable family name for an address of that class. | |
void | getAddress (uint8_t &b1, uint8_t &b2, uint8_t &b3, uint8_t &b4, uint8_t &b5, uint8_t &b6) const |
Get the MAC address as 6 bytes. | |
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 | operator< (const MACAddress &other) const |
Comparison "less than" operator. | |
bool | operator== (const MACAddress &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. | |
virtual bool | setAddress (const void *addr, size_t size) override |
Set the network address from binary data. | |
void | setAddress (uint64_t addr) |
Set the MAC address from a 48-bit integer value. | |
void | setAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6) |
Set the MAC address from 6 bytes. | |
virtual void | setPort (Port port) |
Set the port. | |
virtual UString | toFullString () const |
Convert to a string object in numeric format without the default compaction. | |
bool | toMulticast (const IPv4Address &ip) |
Get the multicast MAC address for a given IPv4 address. | |
virtual UString | toString () const override |
Convert to a string object. | |
Static Public Attributes | |
static constexpr Port | AnyPort = 0 |
Wildcard integer value for "any port" or "no port". | |
static constexpr size_t | BITS = 48 |
Size in bits of a MAC address. | |
static constexpr size_t | BYTES = 6 |
Size in bytes of a MAC address. | |
static constexpr uint64_t | MASK = 0x0000FFFFFFFFFFFF |
Mask of meaningful bits in a MAC address. | |
A basic representation of a MAC address.
The string representation is "hh:hh:hh:hh:hh:hh".
|
inline |
Constructor from an integer address.
[in] | addr | The MAC address as a 48-bit integer. |
ts::MACAddress::MACAddress | ( | uint8_t | b1, |
uint8_t | b2, | ||
uint8_t | b3, | ||
uint8_t | b4, | ||
uint8_t | b5, | ||
uint8_t | b6 | ||
) |
Constructor from 6 bytes.
[in] | b1 | First address byte. |
[in] | b2 | Second address byte. |
[in] | b3 | Third address byte. |
[in] | b4 | Fourth address byte. |
[in] | b5 | Fifth address byte. |
[in] | b6 | Sixth address byte. |
Constructor from a string in "a:b:c:d:e:f" format.
[in] | name | A string in "a:b:c:d:e:f" format. |
[in] | report | Where to report errors. |
|
inline |
Equality operator.
[in] | a | Another instance to compare with. |
|
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.
|
overridevirtual |
Convert to a string object.
Implements ts::StringifyInterface.
|
inline |
Get the MAC address as a 48-bit integer value.
|
inline |
Set the MAC address from a 48-bit integer value.
[in] | addr | The MAC address as a 48-bit integer value. |
void ts::MACAddress::setAddress | ( | uint8_t | b1, |
uint8_t | b2, | ||
uint8_t | b3, | ||
uint8_t | b4, | ||
uint8_t | b5, | ||
uint8_t | b6 | ||
) |
Set the MAC address from 6 bytes.
[in] | b1 | First address byte. |
[in] | b2 | Second address byte. |
[in] | b3 | Third address byte. |
[in] | b4 | Fourth address byte. |
[in] | b5 | Fifth address byte. |
[in] | b6 | Sixth address byte. |
void ts::MACAddress::getAddress | ( | uint8_t & | b1, |
uint8_t & | b2, | ||
uint8_t & | b3, | ||
uint8_t & | b4, | ||
uint8_t & | b5, | ||
uint8_t & | b6 | ||
) | const |
Get the MAC address as 6 bytes.
[out] | b1 | First address byte. |
[out] | b2 | Second address byte. |
[out] | b3 | Third address byte. |
[out] | b4 | Fourth address byte. |
[out] | b5 | Fifth address byte. |
[out] | b6 | Sixth address byte. |
bool ts::MACAddress::toMulticast | ( | const IPv4Address & | ip | ) |
Get the multicast MAC address for a given IPv4 address.
[in] | ip | IPv4 multicast address. |
|
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.