From 7786a55ec4762b4f8325764684c19f6fa6d7acdb Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Ramonet Date: Thu, 16 Mar 2023 11:51:48 +0900 Subject: [PATCH] network: Add Mac16Address constructor --- src/network/utils/mac16-address.cc | 6 ++++++ src/network/utils/mac16-address.h | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/network/utils/mac16-address.cc b/src/network/utils/mac16-address.cc index 0c4bb8453..76f373711 100644 --- a/src/network/utils/mac16-address.cc +++ b/src/network/utils/mac16-address.cc @@ -104,6 +104,12 @@ Mac16Address::Mac16Address(const char* str) NS_ASSERT(i == 2); } +Mac16Address::Mac16Address(uint16_t addr) +{ + m_address[1] = addr & 0xFF; + m_address[0] = (addr >> 8) & 0xFF; +} + void Mac16Address::CopyFrom(const uint8_t buffer[2]) { diff --git a/src/network/utils/mac16-address.h b/src/network/utils/mac16-address.h index bac6701f1..0d497727e 100644 --- a/src/network/utils/mac16-address.h +++ b/src/network/utils/mac16-address.h @@ -50,24 +50,34 @@ class Mac16Address */ Mac16Address(const char* str); + /** + * \param addr The 16 bit integer used to create a Mac16Address object. + * + * Create a Mac16Address from an 16 bit integer. + */ + Mac16Address(uint16_t addr); + /** * \param buffer address in network order * * Copy the input address to our internal buffer. */ void CopyFrom(const uint8_t buffer[2]); + /** * \param buffer address in network order * * Copy the internal address to the input buffer. */ void CopyTo(uint8_t buffer[2]) const; + /** * \returns a new Address instance * * Convert an instance of this class to a polymorphic Address instance. */ operator Address() const; + /** * \param address a polymorphic address * \returns a new Mac16Address from the polymorphic address @@ -77,6 +87,7 @@ class Mac16Address * Mac16Address. */ static Mac16Address ConvertFrom(const Address& address); + /** * \returns a new Address instance * @@ -89,6 +100,7 @@ class Mac16Address * \returns true if the address matches, false otherwise. */ static bool IsMatchingType(const Address& address); + /** * Allocate a new Mac16Address. * \returns newly allocated mac16Address