1.1 --- a/src/node/address.cc Thu Oct 02 17:30:38 2008 +0100
1.2 +++ b/src/node/address.cc Thu Oct 02 15:22:17 2008 -0700
1.3 @@ -1,3 +1,23 @@
1.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
1.5 +/*
1.6 + * Copyright (c) 2007 INRIA
1.7 + *
1.8 + * This program is free software; you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License version 2 as
1.10 + * published by the Free Software Foundation;
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License
1.18 + * along with this program; if not, write to the Free Software
1.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.20 + *
1.21 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
1.22 + */
1.23 +
1.24 #include "ns3/assert.h"
1.25 #include "address.h"
1.26 #include <string.h>
1.27 @@ -10,7 +30,7 @@
1.28 : m_type (0),
1.29 m_len (0)
1.30 {
1.31 - memset (m_data, 0, m_len);
1.32 + // Buffer left uninitialized
1.33 }
1.34
1.35 Address::Address (uint8_t type, const uint8_t *buffer, uint8_t len)
1.36 @@ -18,7 +38,6 @@
1.37 m_len (len)
1.38 {
1.39 NS_ASSERT (m_len <= MAX_SIZE);
1.40 - memset (m_data, 0, m_len);
1.41 memcpy (m_data, buffer, m_len);
1.42 }
1.43 Address::Address (const Address & address)
1.44 @@ -26,7 +45,6 @@
1.45 m_len (address.m_len)
1.46 {
1.47 NS_ASSERT (m_len <= MAX_SIZE);
1.48 - memset (m_data, 0, m_len);
1.49 memcpy (m_data, address.m_data, m_len);
1.50 }
1.51 Address &
1.52 @@ -36,7 +54,6 @@
1.53 m_type = address.m_type;
1.54 m_len = address.m_len;
1.55 NS_ASSERT (m_len <= MAX_SIZE);
1.56 - memset (m_data, 0, m_len);
1.57 memcpy (m_data, address.m_data, m_len);
1.58 return *this;
1.59 }
1.60 @@ -78,12 +95,13 @@
1.61 m_len = len;
1.62 return m_len;
1.63 }
1.64 -uint32_t
1.65 + uint32_t
1.66 Address::CopyAllFrom (const uint8_t *buffer, uint8_t len)
1.67 {
1.68 NS_ASSERT (len >= 2);
1.69 m_type = buffer[0];
1.70 m_len = buffer[1];
1.71 +
1.72 NS_ASSERT (len >= m_len + 2);
1.73 memcpy (m_data, buffer + 2, m_len);
1.74 return m_len + 2;
2.1 --- a/src/node/address.h Thu Oct 02 17:30:38 2008 +0100
2.2 +++ b/src/node/address.h Thu Oct 02 15:22:17 2008 -0700
2.3 @@ -1,3 +1,23 @@
2.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2.5 +/*
2.6 + * Copyright (c) 2007 INRIA
2.7 + *
2.8 + * This program is free software; you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License version 2 as
2.10 + * published by the Free Software Foundation;
2.11 + *
2.12 + * This program is distributed in the hope that it will be useful,
2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.15 + * GNU General Public License for more details.
2.16 + *
2.17 + * You should have received a copy of the GNU General Public License
2.18 + * along with this program; if not, write to the Free Software
2.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2.20 + *
2.21 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
2.22 + */
2.23 +
2.24 #ifndef ADDRESS_H
2.25 #define ADDRESS_H
2.26
2.27 @@ -115,6 +135,11 @@
2.28 * \param buffer buffer to copy the whole address data structure to
2.29 * \param len the size of the buffer
2.30 * \returns the number of bytes copied.
2.31 + *
2.32 + * Copies the type to buffer[0], the length of the address internal buffer
2.33 + * to buffer[1] and copies the internal buffer starting at buffer[2]. len
2.34 + * must be at least the size of the internal buffer plus a byte for the type
2.35 + * and a byte for the length.
2.36 */
2.37 uint32_t CopyAllTo (uint8_t *buffer, uint8_t len) const;
2.38 /**
2.39 @@ -124,8 +149,8 @@
2.40 * \param len length of buffer
2.41 * \returns the number of bytes copied.
2.42 *
2.43 - * Copy the input buffer to the internal buffer of this address
2.44 - * instance.
2.45 + * Copy the address bytes from buffer into to the internal buffer of this
2.46 + * address instance.
2.47 */
2.48 uint32_t CopyFrom (const uint8_t *buffer, uint8_t len);
2.49 /**
2.50 @@ -133,6 +158,10 @@
2.51 * a copy of all the members of this Address class.
2.52 * \param len the length of the buffer
2.53 * \returns the number of bytes copied.
2.54 + *
2.55 + * The inverse of CopyAllTo().
2.56 + *
2.57 + * \see CopyAllTo
2.58 */
2.59 uint32_t CopyAllFrom (const uint8_t *buffer, uint8_t len);
2.60 /**