From b052aa1d88f18706bd80c2dc022121d300362f70 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Wed, 29 May 2013 11:14:36 -0300 Subject: [PATCH] Added HWAddress<>::is_broadcast. --- include/hw_address.h | 7 +++++++ tests/src/hwaddress.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/include/hw_address.h b/include/hw_address.h index 353c07e..cd99054 100644 --- a/include/hw_address.h +++ b/include/hw_address.h @@ -227,6 +227,13 @@ public: return address_size; } + /** + * \brief Indicates whether this is a broadcast address + */ + bool is_broadcast() const { + return *std::min_element(begin(), end()) == 0xff; + } + /** * \brief Convert this address to a hex-notation std::string address. * diff --git a/tests/src/hwaddress.cpp b/tests/src/hwaddress.cpp index 6166011..5b7b112 100644 --- a/tests/src/hwaddress.cpp +++ b/tests/src/hwaddress.cpp @@ -54,6 +54,13 @@ TEST_F(HWAddressTest, CopyConstructor) { EXPECT_EQ(addr1, addr2); } +TEST_F(HWAddressTest, IsBroadcast) { + EXPECT_FALSE(HWAddress<6>("ff:ff:ff:ff:ff:fe").is_broadcast()); + EXPECT_FALSE(HWAddress<6>("00:01:02:03:04:05").is_broadcast()); + EXPECT_TRUE(HWAddress<6>("ff:ff:ff:ff:ff:ff").is_broadcast()); +} + + TEST_F(HWAddressTest, CopyAssignmentOperator) { HWAddress<6> addr1(byte_address), addr2; addr2 = addr1;