PacketSocketAddress serialization code was buggy.
--- a/src/node/address.cc Wed Aug 01 09:15:48 2007 +0200
+++ b/src/node/address.cc Wed Aug 01 10:29:03 2007 +0200
@@ -52,29 +52,32 @@
NS_ASSERT (m_len <= MAX_SIZE);
return m_len;
}
-void
+uint32_t
Address::CopyTo (uint8_t buffer[MAX_SIZE]) const
{
NS_ASSERT (m_len <= MAX_SIZE);
memcpy (buffer, m_data, m_len);
+ return m_len;
}
-void
+uint32_t
Address::CopyAllTo (uint8_t *buffer, uint8_t len) const
{
NS_ASSERT (len >= m_len + 2);
buffer[0] = m_type;
buffer[1] = m_len;
memcpy (buffer + 2, m_data, m_len);
+ return m_len + 2;
}
-void
+uint32_t
Address::CopyFrom (const uint8_t *buffer, uint8_t len)
{
NS_ASSERT (len <= MAX_SIZE);
memcpy (m_data, buffer, len);
m_len = len;
+ return m_len;
}
-void
+uint32_t
Address::CopyAllFrom (const uint8_t *buffer, uint8_t len)
{
NS_ASSERT (len >= 2);
@@ -82,6 +85,7 @@
m_len = buffer[1];
NS_ASSERT (len >= m_len + 2);
memcpy (m_data, buffer + 2, m_len);
+ return m_len + 2;
}
bool
Address::CheckCompatible (uint8_t type, uint8_t len) const
@@ -89,6 +93,11 @@
NS_ASSERT (len <= MAX_SIZE);
return m_len == len && (m_type == type || m_type == 0);
}
+bool
+Address::IsMatchingType (uint8_t type) const
+{
+ return m_type == type;
+}
uint8_t
Address::Register (void)
--- a/src/node/address.h Wed Aug 01 09:15:48 2007 +0200
+++ b/src/node/address.h Wed Aug 01 10:29:03 2007 +0200
@@ -100,29 +100,33 @@
uint8_t GetLength (void) const;
/**
* \param buffer buffer to copy the address bytes to.
+ * \returns the number of bytes copied.
*/
- void CopyTo (uint8_t buffer[MAX_SIZE]) const;
+ uint32_t CopyTo (uint8_t buffer[MAX_SIZE]) const;
/**
* \param buffer buffer to copy the whole address data structure to
* \param len the size of the buffer
+ * \returns the number of bytes copied.
*/
- void CopyAllTo (uint8_t *buffer, uint8_t len) const;
+ uint32_t CopyAllTo (uint8_t *buffer, uint8_t len) const;
/**
* \param buffer pointer to a buffer of bytes which contain
* a serialized representation of the address in network
* byte order.
* \param len length of buffer
+ * \returns the number of bytes copied.
*
* Copy the input buffer to the internal buffer of this address
* instance.
*/
- void CopyFrom (const uint8_t *buffer, uint8_t len);
+ uint32_t CopyFrom (const uint8_t *buffer, uint8_t len);
/**
* \param buffer pointer to a buffer of bytes which contain
* a copy of all the members of this Address class.
* \param len the length of the buffer
+ * \returns the number of bytes copied.
*/
- void CopyAllFrom (const uint8_t *buffer, uint8_t len);
+ uint32_t CopyAllFrom (const uint8_t *buffer, uint8_t len);
/**
* \param type a type id as returned by Address::Register
* \param len the length associated to this type id.
@@ -132,6 +136,17 @@
*/
bool CheckCompatible (uint8_t type, uint8_t len) const;
/**
+ * \param type a type id as returned by Address::Register
+ * \returns true if the type of the address stored internally
+ * is compatible with the requested type, false otherwise.
+ *
+ * This method checks that the types are _exactly_ equal.
+ * This method is really used only by the PacketSocketAddress
+ * and there is little point in using it otherwise so,
+ * you have been warned: DO NOT USE THIS METHOD.
+ */
+ bool IsMatchingType (uint8_t type) const;
+ /**
* Allocate a new type id for a new type of address.
* \returns a new type id.
*/
--- a/src/node/packet-socket-address.cc Wed Aug 01 09:15:48 2007 +0200
+++ b/src/node/packet-socket-address.cc Wed Aug 01 10:29:03 2007 +0200
@@ -79,8 +79,8 @@
buffer[3] = (m_device >> 16) & 0xff;
buffer[4] = (m_device >> 8) & 0xff;
buffer[5] = (m_device >> 0) & 0xff;
- m_address.CopyAllTo (buffer + 6, Address::MAX_SIZE - 6);
- return Address (GetType (), buffer, GetSize ());
+ uint32_t copied = m_address.CopyAllTo (buffer + 6, Address::MAX_SIZE - 6);
+ return Address (GetType (), buffer, 6 + copied);
}
PacketSocketAddress
PacketSocketAddress::ConvertFrom (const Address &address)
@@ -108,7 +108,7 @@
bool
PacketSocketAddress::IsMatchingType (const Address &address)
{
- return address.CheckCompatible (GetType (), GetSize ());
+ return address.IsMatchingType (GetType ());
}
uint8_t
PacketSocketAddress::GetType (void)
@@ -116,10 +116,5 @@
static uint8_t type = Address::Register ();
return type;
}
-uint8_t
-PacketSocketAddress::GetSize (void)
-{
- return 2 + sizeof (NetDevice *) + 1 + 1 + 8;
-}
} // namespace ns3
--- a/src/node/packet-socket-address.h Wed Aug 01 09:15:48 2007 +0200
+++ b/src/node/packet-socket-address.h Wed Aug 01 10:29:03 2007 +0200
@@ -68,7 +68,6 @@
static bool IsMatchingType (const Address &address);
private:
static uint8_t GetType (void);
- static uint8_t GetSize (void);
uint16_t m_protocol;
uint32_t m_device;
Address m_address;