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

A basic representation of a MAC address. More...

#include <tsMACAddress.h>

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

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.
 
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.
 

Detailed Description

A basic representation of a MAC address.

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

Constructor & Destructor Documentation

◆ MACAddress() [1/3]

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

Constructor from an integer address.

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

◆ MACAddress() [2/3]

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() [3/3]

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 for an address of that class.

Returns
The maximum binary size 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 (data too short).

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 IPv4Address ip)

Get the multicast MAC address for a given IPv4 address.

Parameters
[in]ipIPv4 multicast address.
Returns
True if the ip is a 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.

◆ 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::IPv4SocketAddress, and ts::IPv6SocketAddress.

◆ 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::IPv4SocketAddress, and ts::IPv6SocketAddress.

◆ 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::IPv6Address, and ts::IPv6SocketAddress.


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