changeset 878f2f30b12d in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=878f2f30b12d
description:
        base: fix some bugs in EthAddr

        per the IEEE 802 spec:
        1) fixed broadcast() to ensure that all bytes are equal to 0xff.
        2) fixed unicast() to ensure that bit 0 of the first byte is equal to 0
        3) fixed multicast() to ensure that bit 0 of the first byte is equal to 
1, and
           that it is not a broadcast.

        also the constructors in EthAddr are fixed so that all bytes of data are
        initialized.

diffstat:

 src/base/inet.cc |   6 ++++--
 src/base/inet.hh |  15 ++++++++++++---
 2 files changed, 16 insertions(+), 5 deletions(-)

diffs (45 lines):

diff -r 9f5e9bdc2f27 -r 878f2f30b12d src/base/inet.cc
--- a/src/base/inet.cc  Tue Jul 01 11:58:22 2014 -0400
+++ b/src/base/inet.cc  Wed Jul 02 13:19:13 2014 -0400
@@ -62,12 +62,14 @@
 
 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 -r 9f5e9bdc2f27 -r 878f2f30b12d src/base/inet.hh
--- a/src/base/inet.hh  Tue Jul 01 11:58:22 2014 -0400
+++ b/src/base/inet.hh  Wed Jul 02 13:19:13 2014 -0400
@@ -93,9 +93,18 @@
     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
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to