diff --git a/src/common/packet.cc b/src/common/packet.cc index f2ba95ea8..a5f5e3993 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -296,6 +296,19 @@ Packet::PeekData (void) const return m_buffer.PeekData (); } +uint32_t +Packet::CopyData (uint8_t *buffer, uint32_t size) const +{ + Buffer::Iterator i = m_buffer.Begin (); + uint32_t cur = 0; + while (!i.IsEnd () && cur < size) + { + buffer[cur] = i.ReadU8 (); + cur++; + } + return cur; +} + uint32_t Packet::GetUid (void) const { diff --git a/src/common/packet.h b/src/common/packet.h index 454da94b6..9b0aba9e9 100644 --- a/src/common/packet.h +++ b/src/common/packet.h @@ -280,6 +280,16 @@ public: */ uint8_t const *PeekData (void) const; + /** + * \param buffer a pointer to a byte buffer where the packet data + * should be copied. + * \param size the size of the byte buffer. + * \returns the number of bytes read from the packet + * + * No more than \b size bytes will be copied by this function. + */ + uint32_t CopyData (uint8_t *buffer, uint32_t size) const; + /** * A packet is allocated a new uid when it is created * empty or with zero-filled payload. @@ -437,6 +447,7 @@ std::ostream& operator<< (std::ostream& os, const Packet &packet); * - ns3::Packet::CreateFragment * - ns3::Packet::RemoveAtStart * - ns3::Packet::RemoveAtEnd + * - ns3::Packet::CopyData * * Dirty operations will always be slower than non-dirty operations, * sometimes by several orders of magnitude. However, even the