fix regression introduced by changeset 6244ea5e7831 to fix bug #173
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 17 Apr 2008 16:24:13 -0700
changeset 2922 916de65f67bf
parent 2918 6244ea5e7831
child 2923 dbbe74916235
fix regression introduced by changeset 6244ea5e7831 to fix bug #173
src/node/address.cc
--- a/src/node/address.cc	Wed Apr 16 18:37:20 2008 +0100
+++ b/src/node/address.cc	Thu Apr 17 16:24:13 2008 -0700
@@ -109,13 +109,28 @@
 
 ATTRIBUTE_HELPER_CPP (Address);
 
+
 bool operator == (const Address &a, const Address &b)
 {
-  if (a.m_type != b.m_type)
+  /* Two addresses can be equal even if their types are 
+   * different if one of the two types is zero. a type of 
+   * zero identifies an Address which might contain meaningful 
+   * payload but for which the type field could not be set because
+   * we did not know it. This can typically happen in the ARP
+   * layer where we receive an address from an ArpHeader but
+   * we do not know its type: we really want to be able to
+   * compare addresses without knowing their real type.
+   */
+  if (a.m_type != b.m_type &&
+      a.m_type != 0 && 
+      b.m_type != 0)
     {
       return false;
     }
-  NS_ASSERT (a.GetLength() == b.GetLength());  
+  if (a.m_len != b.m_len)
+    {
+      return false;
+    }
   return memcmp (a.m_data, b.m_data, a.m_len) == 0;
 }
 bool operator != (const Address &a, const Address &b)
@@ -124,9 +139,16 @@
 }
 bool operator < (const Address &a, const Address &b)
 {
-  NS_ASSERT (a.m_type == b.m_type  || 
-	     a.m_type == 0 || 
-	     b.m_type == 0);
+  // XXX: it is not clear to me how to order based on type.
+  // so, we do not compare the types here but we should.
+  if (a.m_len < b.m_len)
+    {
+      return true;
+    }
+  else if (a.m_len > b.m_len)
+    {
+      return false;
+    }
   NS_ASSERT (a.GetLength() == b.GetLength());
   for (uint8_t i = 0; i < a.GetLength(); i++) 
     {