1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Added HWAddress and IPv4Address::is_unicast and a static const member 'broadcast' for both classes.

This commit is contained in:
Matias Fontanini
2013-10-06 22:56:00 -03:00
parent bcfe26175a
commit 58e2c93e30
2 changed files with 34 additions and 4 deletions

View File

@@ -69,6 +69,11 @@ public:
* elements in this address.
*/
static const size_t address_size = n;
/**
* \brief The broadcast address.
*/
static const HWAddress<n, Storage> 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<n, Storage>::convert(const std::string &hw_addr,
*(output++) = storage_type();
}
}
template<size_t n, typename Storage>
const HWAddress<n, Storage> HWAddress<n, Storage>::broadcast("ff:ff:ff:ff:ff:ff");
} // namespace Tins
#if TINS_IS_CXX11
namespace std

View File

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