diff --git a/src/applications/v4ping/v4ping.cc b/src/applications/v4ping/v4ping.cc index 9ad780b06..035d4744f 100644 --- a/src/applications/v4ping/v4ping.cc +++ b/src/applications/v4ping/v4ping.cc @@ -87,10 +87,11 @@ V4Ping::Receive (Ptr socket) if (echo.GetSequenceNumber () == (m_seq - 1) && echo.GetIdentifier () == 0) { - Ptr data = echo.GetData (); - if (data->GetSize () == 16) + uint8_t data[16]; + uint32_t dataSize = echo.GetData (data); + if (dataSize == 16) { - uint32_t *buf = (uint32_t *)data->PeekData (); + uint32_t *buf = (uint32_t *)data; if (buf[0] == GetNode ()->GetId () && buf[1] == GetApplicationId ()) { diff --git a/src/internet-stack/icmpv4.cc b/src/internet-stack/icmpv4.cc index b0b2cfec9..53fcffea6 100644 --- a/src/internet-stack/icmpv4.cc +++ b/src/internet-stack/icmpv4.cc @@ -108,7 +108,9 @@ Icmpv4Echo::SetSequenceNumber (uint16_t seq) void Icmpv4Echo::SetData (Ptr data) { - m_data = data->Copy (); + uint32_t size = (data->GetSize ()>16)?16:data->GetSize(); + data->CopyData (m_data, size); + m_dataSize = size; } uint16_t Icmpv4Echo::GetIdentifier (void) const @@ -120,10 +122,11 @@ Icmpv4Echo::GetSequenceNumber (void) const { return m_sequence; } -Ptr -Icmpv4Echo::GetData (void) const +uint32_t +Icmpv4Echo::GetData (uint8_t data[16]) const { - return m_data->Copy (); + memcpy (data, m_data, m_dataSize); + return m_dataSize; } @@ -139,8 +142,14 @@ Icmpv4Echo::GetTypeId (void) Icmpv4Echo::Icmpv4Echo () : m_identifier (0), m_sequence (0), - m_data (0) -{} + m_dataSize (0) +{ + // make sure that thing is initialized to get initialized bytes + for (uint8_t j = 0; j < 16; j++) + { + m_data[j] = 0; + } +} Icmpv4Echo::~Icmpv4Echo () {} TypeId @@ -151,14 +160,14 @@ Icmpv4Echo::GetInstanceTypeId (void) const uint32_t Icmpv4Echo::GetSerializedSize (void) const { - return 4 + m_data->GetSize (); + return 4 + m_dataSize; } void Icmpv4Echo::Serialize (Buffer::Iterator start) const { start.WriteHtonU16 (m_identifier); start.WriteHtonU16 (m_sequence); - start.Write (m_data->PeekData (), m_data->GetSize ()); + start.Write (m_data, m_dataSize); } uint32_t Icmpv4Echo::Deserialize (Buffer::Iterator start) @@ -166,11 +175,8 @@ Icmpv4Echo::Deserialize (Buffer::Iterator start) m_identifier = start.ReadNtohU16 (); m_sequence = start.ReadNtohU16 (); NS_ASSERT (start.GetSize () >= 4); - uint32_t size = start.GetSize () - 4; - uint8_t *buffer = new uint8_t[size] (); - start.Read (buffer, size); - m_data = Create (buffer, size); - delete[] buffer; + m_dataSize = start.GetSize () - 4; + start.Read (m_data, m_dataSize); return start.GetSize (); } void diff --git a/src/internet-stack/icmpv4.h b/src/internet-stack/icmpv4.h index f8d224e51..ba69ff7ec 100644 --- a/src/internet-stack/icmpv4.h +++ b/src/internet-stack/icmpv4.h @@ -50,7 +50,7 @@ public: void SetData (Ptr data); uint16_t GetIdentifier (void) const; uint16_t GetSequenceNumber (void) const; - Ptr GetData (void) const; + uint32_t GetData (uint8_t payload[16]) const; static TypeId GetTypeId (void); @@ -64,7 +64,8 @@ public: private: uint16_t m_identifier; uint16_t m_sequence; - Ptr m_data; + uint8_t m_data[16]; + uint32_t m_dataSize; }; class Icmpv4DestinationUnreachable : public Header