From eda45c3d8727dedec3ed47f79ab762da3349e303 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 17 Apr 2008 16:24:13 -0700 Subject: [PATCH] fix regression introduced by changeset 6244ea5e7831 to fix bug #173 --- src/node/address.cc | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/node/address.cc b/src/node/address.cc index 3566c353c..957f21e01 100644 --- a/src/node/address.cc +++ b/src/node/address.cc @@ -109,13 +109,28 @@ Address::Register (void) 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; + } + if (a.m_len != b.m_len) { return false; } - NS_ASSERT (a.GetLength() == b.GetLength()); 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) } 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++) {