diff --git a/src/node/address.cc b/src/node/address.cc index 74993a0b4..33104083d 100644 --- a/src/node/address.cc +++ b/src/node/address.cc @@ -52,29 +52,32 @@ Address::GetLength (void) const 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 @@ Address::CopyAllFrom (const uint8_t *buffer, uint8_t len) 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 @@ Address::CheckCompatible (uint8_t type, uint8_t len) const 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) diff --git a/src/node/address.h b/src/node/address.h index 25bb282fe..0d3b0da83 100644 --- a/src/node/address.h +++ b/src/node/address.h @@ -100,29 +100,33 @@ public: 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. @@ -131,6 +135,17 @@ public: * is compatible with the requested type, false otherwise. */ 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. diff --git a/src/node/packet-socket-address.cc b/src/node/packet-socket-address.cc index ac5bded70..2c5fcb7b8 100644 --- a/src/node/packet-socket-address.cc +++ b/src/node/packet-socket-address.cc @@ -79,8 +79,8 @@ PacketSocketAddress::ConvertTo (void) const 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 @@ PacketSocketAddress::ConvertFrom (const Address &address) bool PacketSocketAddress::IsMatchingType (const Address &address) { - return address.CheckCompatible (GetType (), GetSize ()); + return address.IsMatchingType (GetType ()); } uint8_t PacketSocketAddress::GetType (void) @@ -116,10 +116,5 @@ PacketSocketAddress::GetType (void) static uint8_t type = Address::Register (); return type; } -uint8_t -PacketSocketAddress::GetSize (void) -{ - return 2 + sizeof (NetDevice *) + 1 + 1 + 8; -} } // namespace ns3 diff --git a/src/node/packet-socket-address.h b/src/node/packet-socket-address.h index 1e903d181..ca138ad43 100644 --- a/src/node/packet-socket-address.h +++ b/src/node/packet-socket-address.h @@ -68,7 +68,6 @@ class PacketSocketAddress 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;