TSDuck v3.46-4930
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::MACAddress Class Reference

#include <tsMACAddress.h>

Inheritance diagram for ts::MACAddress:
Collaboration diagram for ts::MACAddress:

Public Types

using Port = uint16_t

Public Member Functions

 MACAddress ()=default
 MACAddress (const UString &name, Report &report)
 MACAddress (uint64_t addr)
 MACAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6)
uint64_t address () const
virtual size_t binarySize () const override
virtual void clear ()
virtual void clearAddress () override
virtual void clearPort ()
virtual const UChar * familyName () const override
void getAddress (uint8_t &b1, uint8_t &b2, uint8_t &b3, uint8_t &b4, uint8_t &b5, uint8_t &b6) const
virtual size_t getAddress (void *addr, size_t size) const override
virtual bool hasAddress () const override
virtual bool hasPort () const
virtual bool isMulticast () const override
bool operator< (const MACAddress &other) const
bool operator== (const MACAddress &a) const
virtual Port port () const
virtual bool resolve (const UString &name, Report &report) override
virtual bool setAddress (const void *addr, size_t size) override
void setAddress (uint64_t addr)
void setAddress (uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6)
virtual void setPort (Port port)
virtual UString toFullString () const
bool toMulticast (const IPAddress &ip)
virtual UString toString () const override

Static Public Attributes

static constexpr Port AnyPort = 0
static constexpr size_t BITS = 48
static constexpr size_t BYTES = 6
static constexpr uint64_t MASK = 0x0000FFFFFFFFFFFF

Detailed Description

A basic representation of a MAC address.

The string representation is "hh:hh:hh:hh:hh:hh".

Member Typedef Documentation

◆ Port

using ts::AbstractNetworkAddress::Port = uint16_t
inherited

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

Constructor & Destructor Documentation

◆ MACAddress() [1/4]

ts::MACAddress::MACAddress ( )
default

Default constructor

◆ MACAddress() [2/4]

ts::MACAddress::MACAddress ( uint64_t addr)
inline

Constructor from an integer address.

Parameters
[in]addrThe MAC address as a 48-bit integer.

◆ MACAddress() [3/4]

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.

Parameters
[in]b1First address byte.
[in]b2Second address byte.
[in]b3Third address byte.
[in]b4Fourth address byte.
[in]b5Fifth address byte.
[in]b6Sixth address byte.

◆ MACAddress() [4/4]

ts::MACAddress::MACAddress ( const UString & name,
Report & report )
inline

Constructor from a string in "a:b:c:d:e:f" format.

Parameters
[in]nameA string in "a:b:c:d:e:f" format.
[in]reportWhere to report errors.

Member Function Documentation

◆ operator==()

bool ts::MACAddress::operator== ( const MACAddress & a) const
inline

Equality operator.

Parameters
[in]aAnother instance to compare with.
Returns
True if both object contains the same address, false otherwise.

◆ binarySize()

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

Get the maximum binary size in bytes for an address of that class.

Returns
The maximum binary size in bytes for an address of that class.

Implements ts::AbstractNetworkAddress.

◆ familyName()

virtual const UChar * ts::MACAddress::familyName ( ) const
overridevirtual

Get a human-readable family name for an address of that class. This is typically something like "IPv4" or "IPv6".

Returns
A human-readable family name for an address of that class.

Implements ts::AbstractNetworkAddress.

◆ hasAddress()

virtual bool ts::MACAddress::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() [1/2]

virtual size_t ts::MACAddress::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/3]

virtual bool ts::MACAddress::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 (incorrect data size).

Implements ts::AbstractNetworkAddress.

◆ clearAddress()

virtual void ts::MACAddress::clearAddress ( )
overridevirtual

Clear the address field.

Implements ts::AbstractNetworkAddress.

◆ isMulticast()

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

◆ toString()

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

Convert to a string object.

Returns
This object, converted as a string.

Implements ts::StringifyInterface.

◆ address()

uint64_t ts::MACAddress::address ( ) const
inline

Get the MAC address as a 48-bit integer value.

Returns
The MAC address as a 48-bit integer value.

◆ setAddress() [2/3]

void ts::MACAddress::setAddress ( uint64_t addr)
inline

Set the MAC address from a 48-bit integer value.

Parameters
[in]addrThe MAC address as a 48-bit integer value.

◆ setAddress() [3/3]

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.

Parameters
[in]b1First address byte.
[in]b2Second address byte.
[in]b3Third address byte.
[in]b4Fourth address byte.
[in]b5Fifth address byte.
[in]b6Sixth address byte.

◆ getAddress() [2/2]

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.

Parameters
[out]b1First address byte.
[out]b2Second address byte.
[out]b3Third address byte.
[out]b4Fourth address byte.
[out]b5Fifth address byte.
[out]b6Sixth address byte.

◆ toMulticast()

bool ts::MACAddress::toMulticast ( const IPAddress & ip)

Get the multicast MAC address for a given IPv4 address.

Parameters
[in]ipIPv4 multicast address.
Returns
True if the ip is an IPv4 multicast address, false otherwise.

◆ operator<()

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

◆ clear()

virtual void ts::AbstractNetworkAddress::clear ( )
virtualinherited

Clear the object, address and port if there is any.

◆ 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::IPSocketAddress.

◆ 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::IPSocketAddress.

◆ 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::IPAddress, ts::IPAddressMask, and ts::IPSocketAddress.

Member Data Documentation

◆ BITS

size_t ts::MACAddress::BITS = 48
staticconstexpr

Size in bits of a MAC address.

◆ BYTES

size_t ts::MACAddress::BYTES = 6
staticconstexpr

Size in bytes of a MAC address.

◆ MASK

uint64_t ts::MACAddress::MASK = 0x0000FFFFFFFFFFFF
staticconstexpr

Mask of meaningful bits in a MAC address.

◆ AnyPort

Port ts::AbstractNetworkAddress::AnyPort = 0
staticconstexprinherited

Wildcard integer value for "any port" or "no port".


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