diff --git a/include/hw_address.h b/include/hw_address.h index 3d315f9..8fd0503 100644 --- a/include/hw_address.h +++ b/include/hw_address.h @@ -69,6 +69,11 @@ public: * elements in this address. */ static const size_t address_size = n; + + /** + * \brief The broadcast address. + */ + static const HWAddress broadcast; /** * \brief Constructor from a const storage_type*. @@ -235,19 +240,26 @@ public: } /** - * \brief Indicates whether this is a broadcast address + * \brief Indicates whether this is a broadcast address. */ bool is_broadcast() const { - return *std::min_element(begin(), end()) == 0xff; + return *this == broadcast; } /** - * \brief Indicates whether this is a multicast address + * \brief Indicates whether this is a multicast address. */ bool is_multicast() const { return (buffer[0] & 0x01); } + /** + * \brief Indicates whether this is an unicast address. + */ + bool is_unicast() const { + return !is_broadcast() && !is_multicast(); + } + /** * \brief Convert this address to a hex-notation std::string address. * @@ -357,6 +369,9 @@ void HWAddress::convert(const std::string &hw_addr, *(output++) = storage_type(); } } + +template +const HWAddress HWAddress::broadcast("ff:ff:ff:ff:ff:ff"); } // namespace Tins #if TINS_IS_CXX11 namespace std diff --git a/include/ip_address.h b/include/ip_address.h index 43f943c..206662a 100644 --- a/include/ip_address.h +++ b/include/ip_address.h @@ -46,7 +46,12 @@ public: * The address size. */ static const size_t address_size = sizeof(uint32_t); - + + /** + * The broadcast address. + */ + static const IPv4Address broadcast; + /** * \brief Constructor taking a const char*. * @@ -149,6 +154,16 @@ public: * 224.0.0.0/4, false otherwise. */ bool is_multicast() const; + + /** + * \brief Returns true if this is an unicast IPv4 address. + */ + bool is_unicast() const; + + /** + * \brief Returns true if this is a broadcast IPv4 address. + */ + bool is_broadcast() const; /** * \brief Writes this address to a std::ostream.