summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/base/inet.cc6
-rw-r--r--src/base/inet.hh15
2 files changed, 16 insertions, 5 deletions
diff --git a/src/base/inet.cc b/src/base/inet.cc
index e18858f3c..bdd1b57ad 100644
--- a/src/base/inet.cc
+++ b/src/base/inet.cc
@@ -62,12 +62,14 @@ EthAddr::EthAddr()
EthAddr::EthAddr(const uint8_t ea[ETH_ADDR_LEN])
{
- *data = *ea;
+ for (int i = 0; i < ETH_ADDR_LEN; ++i)
+ data[i] = ea[i];
}
EthAddr::EthAddr(const eth_addr &ea)
{
- *data = *ea.data;
+ for (int i = 0; i < ETH_ADDR_LEN; ++i)
+ data[i] = ea.data[i];
}
EthAddr::EthAddr(const std::string &addr)
diff --git a/src/base/inet.hh b/src/base/inet.hh
index afa6c402a..5130a072c 100644
--- a/src/base/inet.hh
+++ b/src/base/inet.hh
@@ -93,9 +93,18 @@ struct EthAddr : protected eth_addr
uint8_t *bytes() { return &data[0]; }
const uint8_t *addr() const { return &data[0]; }
- bool unicast() const { return data[0] == 0x00; }
- bool multicast() const { return data[0] == 0x01; }
- bool broadcast() const { return data[0] == 0xff; }
+ bool unicast() const { return !(data[0] & 0x01); }
+ bool multicast() const { return !unicast() && !broadcast(); }
+ bool broadcast() const
+ {
+ bool isBroadcast = true;
+ for (int i = 0; i < ETH_ADDR_LEN; ++i) {
+ isBroadcast = isBroadcast && data[i] == 0xff;
+ }
+
+ return isBroadcast;
+ }
+
std::string string() const;
operator uint64_t() const