extra Address API to be used by packet socket address
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 31 Jul 2007 11:42:10 +0200
changeset 1184 1da473c2225c
parent 1183 d5d714a585b0
child 1185 eac7427958e9
extra Address API to be used by packet socket address
src/node/address.cc
src/node/address.h
--- a/src/node/address.cc	Tue Jul 31 11:33:44 2007 +0200
+++ b/src/node/address.cc	Tue Jul 31 11:42:10 2007 +0200
@@ -53,15 +53,34 @@
   memcpy (buffer, m_data, m_len);
 }
 void 
-Address::CopyFrom (uint8_t *buffer, uint8_t len)
+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);
+}
+
+void 
+Address::CopyFrom (const uint8_t *buffer, uint8_t len)
 {
   NS_ASSERT (len <= MAX_SIZE);
   memcpy (m_data, buffer, len);
   m_len = len;
 }
+void
+Address::CopyAllFrom (const uint8_t *buffer, uint8_t len)
+{
+  NS_ASSERT (len >= 2);
+  m_type = buffer[0];
+  m_len = buffer[1];
+  NS_ASSERT (len >= m_len + 2);
+  memcpy (m_data, buffer + 2, m_len);
+}
 bool 
 Address::CheckCompatible (uint8_t type, uint8_t len) const
 {
+  NS_ASSERT (len <= MAX_SIZE);
   return m_len == len && (m_type == type || m_type == 0);
 }
 
--- a/src/node/address.h	Tue Jul 31 11:33:44 2007 +0200
+++ b/src/node/address.h	Tue Jul 31 11:42:10 2007 +0200
@@ -95,6 +95,11 @@
    */
   void 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
+   */
+  void 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.
@@ -103,7 +108,13 @@
    * Copy the input buffer to the internal buffer of this address 
    * instance.
    */
-  void CopyFrom (uint8_t *buffer, uint8_t len);
+  void 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
+   */
+  void 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.