fix regression introduced by changeset 6244ea5e7831 to fix bug #173
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu Apr 17 16:24:13 2008 -0700 (22 months ago)
changeset 2922916de65f67bf
parent 2918 6244ea5e7831
child 2923 dbbe74916235
fix regression introduced by changeset 6244ea5e7831 to fix bug #173
src/node/address.cc
     1.1 --- a/src/node/address.cc	Wed Apr 16 18:37:20 2008 +0100
     1.2 +++ b/src/node/address.cc	Thu Apr 17 16:24:13 2008 -0700
     1.3 @@ -109,13 +109,28 @@
     1.4  
     1.5  ATTRIBUTE_HELPER_CPP (Address);
     1.6  
     1.7 +
     1.8  bool operator == (const Address &a, const Address &b)
     1.9  {
    1.10 -  if (a.m_type != b.m_type)
    1.11 +  /* Two addresses can be equal even if their types are 
    1.12 +   * different if one of the two types is zero. a type of 
    1.13 +   * zero identifies an Address which might contain meaningful 
    1.14 +   * payload but for which the type field could not be set because
    1.15 +   * we did not know it. This can typically happen in the ARP
    1.16 +   * layer where we receive an address from an ArpHeader but
    1.17 +   * we do not know its type: we really want to be able to
    1.18 +   * compare addresses without knowing their real type.
    1.19 +   */
    1.20 +  if (a.m_type != b.m_type &&
    1.21 +      a.m_type != 0 && 
    1.22 +      b.m_type != 0)
    1.23      {
    1.24        return false;
    1.25      }
    1.26 -  NS_ASSERT (a.GetLength() == b.GetLength());  
    1.27 +  if (a.m_len != b.m_len)
    1.28 +    {
    1.29 +      return false;
    1.30 +    }
    1.31    return memcmp (a.m_data, b.m_data, a.m_len) == 0;
    1.32  }
    1.33  bool operator != (const Address &a, const Address &b)
    1.34 @@ -124,9 +139,16 @@
    1.35  }
    1.36  bool operator < (const Address &a, const Address &b)
    1.37  {
    1.38 -  NS_ASSERT (a.m_type == b.m_type  || 
    1.39 -	     a.m_type == 0 || 
    1.40 -	     b.m_type == 0);
    1.41 +  // XXX: it is not clear to me how to order based on type.
    1.42 +  // so, we do not compare the types here but we should.
    1.43 +  if (a.m_len < b.m_len)
    1.44 +    {
    1.45 +      return true;
    1.46 +    }
    1.47 +  else if (a.m_len > b.m_len)
    1.48 +    {
    1.49 +      return false;
    1.50 +    }
    1.51    NS_ASSERT (a.GetLength() == b.GetLength());
    1.52    for (uint8_t i = 0; i < a.GetLength(); i++) 
    1.53      {