bug 86: add missing functions to manipulate Mac48Address
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 11 Oct 2007 13:11:45 +0200
changeset 1707 64531b6e76f1
parent 1706 0df67ef4eb96
child 1708 b1ea1131c106
child 1953 5c7eb973beb2
bug 86: add missing functions to manipulate Mac48Address
src/node/mac48-address.cc
src/node/mac48-address.h
--- a/src/node/mac48-address.cc	Thu Oct 11 13:02:47 2007 +0200
+++ b/src/node/mac48-address.cc	Thu Oct 11 13:11:45 2007 +0200
@@ -133,19 +133,48 @@
   return type;
 }
 
+bool
+Mac48Address::IsBroadcast (void) const
+{
+  return *this == GetBroadcast ();
+}
+bool 
+Mac48Address::IsMulticast (void) const
+{
+  return (m_address[0] & 0x01) == 0x01;
+}
+Mac48Address
+Mac48Address::GetBroadcast (void)
+{
+  static Mac48Address broadcast = Mac48Address ("ff:ff:ff:ff:ff:ff");
+  return broadcast;
+}
 bool operator == (const Mac48Address &a, const Mac48Address &b)
 {
-  uint8_t ada[6];
-  uint8_t adb[6];
-  a.CopyTo (ada);
-  b.CopyTo (adb);
-  return memcmp (ada, adb, 6) == 0;
+  return memcmp (a.m_address, b.m_address, 6) == 0;
 }
 bool operator != (const Mac48Address &a, const Mac48Address &b)
 {
   return ! (a == b);
 }
 
+bool operator < (const Mac48Address &a, const Mac48Address &b)
+{
+  for (uint8_t i = 0; i < 6; i++) 
+    {
+      if (a.m_address[i] < b.m_address[i]) 
+        {
+          return true;
+        } 
+      else if (a.m_address[i] > b.m_address[i]) 
+        {
+          return false;
+        }
+    }
+  return false;
+}
+
+
 std::ostream& operator<< (std::ostream& os, const Mac48Address & address)
 {
   uint8_t ad[6];
--- a/src/node/mac48-address.h	Thu Oct 11 13:02:47 2007 +0200
+++ b/src/node/mac48-address.h	Thu Oct 11 13:11:45 2007 +0200
@@ -79,6 +79,20 @@
    * Allocate a new Mac48Address.
    */
   static Mac48Address Allocate (void);
+
+  /**
+   * \returns true if this is a broadcast address, false otherwise.
+   */
+  bool IsBroadcast (void) const;
+  /**
+   * \returns true if this is a multicast address, false otherwise.
+   */
+  bool IsMulticast (void) const;
+
+  /**
+   * \returns the broadcast address
+   */
+  static Mac48Address GetBroadcast (void);
 private:
   /**
    * \returns a new Address instance
@@ -87,11 +101,15 @@
    */
   Address ConvertTo (void) const;
   static uint8_t GetType (void);
+  friend bool operator < (const Mac48Address &a, const Mac48Address &b);
+  friend bool operator == (const Mac48Address &a, const Mac48Address &b);
+
   uint8_t m_address[6];
 };
 
 bool operator == (const Mac48Address &a, const Mac48Address &b);
 bool operator != (const Mac48Address &a, const Mac48Address &b);
+bool operator < (const Mac48Address &a, const Mac48Address &b);
 std::ostream& operator<< (std::ostream& os, const Mac48Address & address);
 
 } // namespace ns3