--- a/src/applications/ping6/ping6.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/applications/ping6/ping6.cc Tue Aug 10 23:13:56 2010 -0400
@@ -239,7 +239,10 @@
packet->RemoveHeader (hdr);
- switch (*packet->PeekData ())
+ uint8_t type;
+ packet->CopyData (&type, sizeof(type));
+
+ switch (type)
{
case Icmpv6Header::ICMPV6_ECHO_REPLY:
packet->RemoveHeader (reply);
--- a/src/applications/radvd/radvd.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/applications/radvd/radvd.cc Tue Aug 10 23:13:56 2010 -0400
@@ -247,7 +247,10 @@
Time t;
packet->RemoveHeader (hdr);
- switch (*packet->PeekData ())
+ uint8_t type;
+ packet->CopyData (&type, sizeof(type));
+
+ switch (type)
{
case Icmpv6Header::ICMPV6_ND_ROUTER_SOLICITATION:
packet->RemoveHeader (rsHdr);
--- a/src/common/packet.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/common/packet.cc Tue Aug 10 23:13:56 2010 -0400
@@ -1134,8 +1134,13 @@
NS_TEST_EXPECT_MSG_EQ (packet->GetSize (), 11, "trivial");
- std::string msg = std::string (reinterpret_cast<const char *>(packet->PeekData ()),
+ uint8_t *buf = new uint8_t[packet->GetSize ()];
+ packet->CopyData (buf, packet->GetSize ());
+
+ std::string msg = std::string (reinterpret_cast<const char *>(buf),
packet->GetSize ());
+ delete [] buf;
+
NS_TEST_EXPECT_MSG_EQ (msg, "hello world", "trivial");
@@ -1294,8 +1299,10 @@
CHECK (tmp, 1, E (20, 2, 1002));
tmp->RemoveAtStart (1);
CHECK (tmp, 1, E (20, 1, 1001));
+#if 0
tmp->PeekData ();
CHECK (tmp, 1, E (20, 1, 1001));
+#endif
}
return GetErrorStatus ();
--- a/src/internet-stack/icmpv6-header.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/internet-stack/icmpv6-header.cc Tue Aug 10 23:13:56 2010 -0400
@@ -983,7 +983,6 @@
void Icmpv6DestinationUnreachable::Serialize (Buffer::Iterator start) const
{
- const uint8_t *packet = m_packet->PeekData ();
uint16_t checksum = 0;
Buffer::Iterator i = start;
@@ -992,7 +991,11 @@
i.WriteHtonU16 (0);
i.WriteHtonU32 (0);
- i.Write (packet, m_packet->GetSize ());
+ uint32_t size = m_packet->GetSize ();
+ uint8_t *buf = new uint8_t[size];
+ m_packet->CopyData (buf, size);
+ i.Write (buf, size);
+ delete[] buf;
i = start;
checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
@@ -1078,7 +1081,6 @@
void Icmpv6TooBig::Serialize (Buffer::Iterator start) const
{
- const uint8_t *packet = m_packet->PeekData ();
uint16_t checksum = 0;
Buffer::Iterator i = start;
@@ -1087,7 +1089,11 @@
i.WriteHtonU16 (0);
i.WriteHtonU32 (GetMtu ());
- i.Write (packet, m_packet->GetSize ());
+ uint32_t size = m_packet->GetSize ();
+ uint8_t *buf = new uint8_t[size];
+ m_packet->CopyData (buf, size);
+ i.Write (buf, size);
+ delete[] buf;
i = start;
checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
@@ -1162,7 +1168,6 @@
void Icmpv6TimeExceeded::Serialize (Buffer::Iterator start) const
{
- const uint8_t *packet = m_packet->PeekData ();
uint16_t checksum = 0;
Buffer::Iterator i = start;
@@ -1171,7 +1176,11 @@
i.WriteHtonU16 (0);
i.WriteHtonU32 (0);
- i.Write (packet, m_packet->GetSize ());
+ uint32_t size = m_packet->GetSize ();
+ uint8_t *buf = new uint8_t[size];
+ m_packet->CopyData (buf, size);
+ i.Write (buf, size);
+ delete[] buf;
i = start;
checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
@@ -1257,7 +1266,6 @@
void Icmpv6ParameterError::Serialize (Buffer::Iterator start) const
{
- const uint8_t *packet = m_packet->PeekData ();
uint16_t checksum = 0;
Buffer::Iterator i = start;
@@ -1266,7 +1274,11 @@
i.WriteHtonU16 (0);
i.WriteHtonU32 (GetPtr ());
- i.Write (packet, m_packet->GetSize ());
+ uint32_t size = m_packet->GetSize ();
+ uint8_t *buf = new uint8_t[size];
+ m_packet->CopyData (buf, size);
+ i.Write (buf, size);
+ delete[] buf;
i = start;
checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
@@ -1749,7 +1761,11 @@
i.WriteU16 (0);
i.WriteU32 (0);
- i.Write (m_packet->PeekData (), m_packet->GetSize ());
+ uint32_t size = m_packet->GetSize ();
+ uint8_t *buf = new uint8_t[size];
+ m_packet->CopyData (buf, size);
+ i.Write (buf, size);
+ delete[] buf;
}
uint32_t Icmpv6OptionRedirected::Deserialize (Buffer::Iterator start)
--- a/src/internet-stack/icmpv6-l4-protocol.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/internet-stack/icmpv6-l4-protocol.cc Tue Aug 10 23:13:56 2010 -0400
@@ -180,7 +180,11 @@
Ptr<Packet> p = packet->Copy ();
Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6> ();
- switch (*p->PeekData ()) /* very ugly! try to find something better in the future */
+ /* very ugly! try to find something better in the future */
+ uint8_t type;
+ p->CopyData (&type, sizeof(type));
+
+ switch (type)
{
case Icmpv6Header::ICMPV6_ND_ROUTER_SOLICITATION:
if (ipv6->IsForwarding (ipv6->GetInterfaceForDevice (interface->GetDevice ())))
@@ -217,7 +221,7 @@
case Icmpv6Header::ICMPV6_ERROR_PARAMETER_ERROR:
break;
default:
- NS_LOG_LOGIC ("Unknown ICMPv6 message type=" << (uint8_t)*p->PeekData ());
+ NS_LOG_LOGIC ("Unknown ICMPv6 message type=" << type);
break;
}
@@ -372,7 +376,10 @@
{
/* XXX search all options following the RS header */
/* test if the next option is SourceLinkLayerAddress */
- if (*packet->PeekData () != Icmpv6Header::ICMPV6_OPT_LINK_LAYER_SOURCE)
+ uint8_t type;
+ packet->CopyData (&type, sizeof(type));
+
+ if (type != Icmpv6Header::ICMPV6_OPT_LINK_LAYER_SOURCE)
{
return;
}
@@ -440,7 +447,10 @@
if (src != Ipv6Address::GetAny ())
{
- if (*packet->PeekData () != Icmpv6Header::ICMPV6_OPT_LINK_LAYER_SOURCE)
+ uint8_t type;
+ packet->CopyData (&type, sizeof(type));
+
+ if (type != Icmpv6Header::ICMPV6_OPT_LINK_LAYER_SOURCE)
{
return;
}
@@ -570,7 +580,10 @@
/* XXX search all options following the NA header */
/* Get LLA */
- if (*packet->PeekData () != Icmpv6Header::ICMPV6_OPT_LINK_LAYER_TARGET)
+ uint8_t type;
+ packet->CopyData (&type, sizeof(type));
+
+ if (type != Icmpv6Header::ICMPV6_OPT_LINK_LAYER_TARGET)
{
return;
}
@@ -667,7 +680,9 @@
p->RemoveHeader (redirectionHeader);
/* little ugly try to find a better way */
- if (*p->PeekData () == Icmpv6Header::ICMPV6_OPT_LINK_LAYER_TARGET)
+ uint8_t type;
+ p->CopyData (&type, sizeof(type));
+ if (type == Icmpv6Header::ICMPV6_OPT_LINK_LAYER_TARGET)
{
hasLla = true;
p->RemoveHeader (llOptionHeader);
--- a/src/internet-stack/ipv6-extension.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/internet-stack/ipv6-extension.cc Tue Aug 10 23:13:56 2010 -0400
@@ -97,7 +97,10 @@
Ptr<Ipv6Option> ipv6Option;
uint8_t processedSize = 0;
- const uint8_t *data = p->PeekData ();
+ uint32_t size = p->GetSize();
+ uint8_t *data = new uint8_t[size];
+ p->CopyData (data, size);
+
uint8_t optionType = 0;
uint8_t optionLength = 0;
@@ -161,6 +164,8 @@
p->RemoveAtStart (optionLength);
}
+ delete [] data;
+
return processedSize;
}
@@ -378,9 +383,12 @@
uint8_t nextHeader = ipv6Header.GetNextHeader ();
uint8_t ipv6HeaderSize = ipv6Header.GetSerializedSize ();
+ uint8_t type;
+ p->CopyData (&type, sizeof(type));
+
bool moreHeader = true;
if (!(nextHeader == Ipv6Header::IPV6_EXT_HOP_BY_HOP || nextHeader == Ipv6Header::IPV6_EXT_ROUTING
- || (nextHeader == Ipv6Header::IPV6_EXT_DESTINATION && *p->PeekData () == Ipv6Header::IPV6_EXT_ROUTING)))
+ || (nextHeader == Ipv6Header::IPV6_EXT_DESTINATION && type == Ipv6Header::IPV6_EXT_ROUTING)))
{
moreHeader = false;
ipv6Header.SetNextHeader (Ipv6Header::IPV6_EXT_FRAGMENTATION);
@@ -403,8 +411,11 @@
nextHeader = hopbyhopHeader->GetNextHeader ();
extensionHeaderLength = hopbyhopHeader->GetLength ();
+ uint8_t type;
+ p->CopyData (&type, sizeof(type));
+
if (!(nextHeader == Ipv6Header::IPV6_EXT_HOP_BY_HOP || nextHeader == Ipv6Header::IPV6_EXT_ROUTING
- || (nextHeader == Ipv6Header::IPV6_EXT_DESTINATION && *p->PeekData () == Ipv6Header::IPV6_EXT_ROUTING)))
+ || (nextHeader == Ipv6Header::IPV6_EXT_DESTINATION && type == Ipv6Header::IPV6_EXT_ROUTING)))
{
moreHeader = false;
hopbyhopHeader->SetNextHeader (Ipv6Header::IPV6_EXT_FRAGMENTATION);
@@ -415,7 +426,9 @@
}
else if (nextHeader == Ipv6Header::IPV6_EXT_ROUTING)
{
- uint8_t numberAddress = (*(p->PeekData () + 1)) / 2;
+ uint8_t buf[2];
+ p->CopyData (buf, sizeof(buf));
+ uint8_t numberAddress = buf[1] / 2;
Ipv6ExtensionLooseRoutingHeader *routingHeader = new Ipv6ExtensionLooseRoutingHeader ();
routingHeader->SetNumberAddress (numberAddress);
p->RemoveHeader (*routingHeader);
@@ -423,8 +436,10 @@
nextHeader = routingHeader->GetNextHeader ();
extensionHeaderLength = routingHeader->GetLength ();
+ uint8_t type;
+ p->CopyData (&type, sizeof(type));
if (!(nextHeader == Ipv6Header::IPV6_EXT_HOP_BY_HOP || nextHeader == Ipv6Header::IPV6_EXT_ROUTING
- || (nextHeader == Ipv6Header::IPV6_EXT_DESTINATION && *p->PeekData () == Ipv6Header::IPV6_EXT_ROUTING)))
+ || (nextHeader == Ipv6Header::IPV6_EXT_DESTINATION && type == Ipv6Header::IPV6_EXT_ROUTING)))
{
moreHeader = false;
routingHeader->SetNextHeader (Ipv6Header::IPV6_EXT_FRAGMENTATION);
@@ -441,8 +456,10 @@
nextHeader = destinationHeader->GetNextHeader ();
extensionHeaderLength = destinationHeader->GetLength ();
+ uint8_t type;
+ p->CopyData (&type, sizeof(type));
if (!(nextHeader == Ipv6Header::IPV6_EXT_HOP_BY_HOP || nextHeader == Ipv6Header::IPV6_EXT_ROUTING
- || (nextHeader == Ipv6Header::IPV6_EXT_DESTINATION && *p->PeekData () == Ipv6Header::IPV6_EXT_ROUTING)))
+ || (nextHeader == Ipv6Header::IPV6_EXT_DESTINATION && type == Ipv6Header::IPV6_EXT_ROUTING)))
{
moreHeader = false;
destinationHeader->SetNextHeader (Ipv6Header::IPV6_EXT_FRAGMENTATION);
@@ -637,12 +654,13 @@
Ptr<Packet> p = packet->Copy ();
p->RemoveAtStart (offset);
- const uint8_t *buff = packet->PeekData ();
+ uint8_t buf[4];
+ packet->CopyData(buf, sizeof(buf));
- uint8_t routingNextHeader = *buff;
- uint8_t routingLength = *(buff + 1);
- uint8_t routingTypeRouting = *(buff + 2);
- uint8_t routingSegmentsLeft = *(buff + 3);
+ uint8_t routingNextHeader = buf[0];
+ uint8_t routingLength = buf[1];
+ uint8_t routingTypeRouting = buf[2];
+ uint8_t routingSegmentsLeft = buf[3];
if (nextHeader)
{
@@ -786,7 +804,9 @@
ipv6header.Deserialize (it);
// Get the number of routers' address field
- uint8_t numberAddress = (*(p->PeekData () + 1)) / 2;
+ uint8_t buf[2];
+ p->CopyData (buf, sizeof(buf));
+ uint8_t numberAddress = buf[1] / 2;
Ipv6ExtensionLooseRoutingHeader routingHeader;
routingHeader.SetNumberAddress (numberAddress);
p->RemoveHeader (routingHeader);
--- a/src/internet-stack/ipv6-l3-protocol.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/internet-stack/ipv6-l3-protocol.cc Tue Aug 10 23:13:56 2010 -0400
@@ -954,10 +954,10 @@
/* process hop-by-hop extension first if exists */
if (nextHeader == Ipv6Header::IPV6_EXT_HOP_BY_HOP)
{
- const uint8_t *buff = p->PeekData ();
-
- nextHeader = *buff;
- nextHeaderPosition = *(buff + 1);
+ uint8_t buf[2];
+ p->CopyData(buf, sizeof(buf));
+ nextHeader = buf[0];
+ nextHeaderPosition = buf[1];
}
/* process all the extensions found and the layer 4 protocol */
--- a/src/internet-stack/ipv6-raw-socket-impl.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/internet-stack/ipv6-raw-socket-impl.cc Tue Aug 10 23:13:56 2010 -0400
@@ -224,7 +224,9 @@
/* calculate checksum here for ICMPv6 echo request (sent by ping6)
* as we cannot determine source IPv6 address at application level
*/
- if (*p->PeekData () == Icmpv6Header::ICMPV6_ECHO_REQUEST)
+ uint8_t type;
+ p->CopyData (&type, sizeof(type));
+ if (type == Icmpv6Header::ICMPV6_ECHO_REQUEST)
{
Icmpv6Echo hdr (1);
p->RemoveHeader (hdr);
--- a/src/internet-stack/nsc-tcp-l4-protocol.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/internet-stack/nsc-tcp-l4-protocol.cc Tue Aug 10 23:13:56 2010 -0400
@@ -325,10 +325,14 @@
packet->AddHeader(ipHeader);
packetSize = packet->GetSize();
- const uint8_t *data = const_cast<uint8_t *>(packet->PeekData());
+ uint8_t *buf = new uint8_t[packetSize];
+ packet->CopyData (buf, packetSize);
+ const uint8_t *data = const_cast<uint8_t *>(buf);
// deliver complete packet to the NSC network stack
m_nscStack->if_receive_packet(0, data, packetSize);
+ delete[] buf;
+
wakeup ();
return Ipv4L4Protocol::RX_OK;
}
--- a/src/internet-stack/nsc-tcp-socket-impl.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/internet-stack/nsc-tcp-socket-impl.cc Tue Aug 10 23:13:56 2010 -0400
@@ -622,7 +622,12 @@
NS_ASSERT (size > 0);
m_errno = ERROR_NOTERROR;
- ret = m_nscTcpSocket->send_data((const char *)p->PeekData (), size);
+
+ uint8_t *buf = new uint8_t[size];
+ p->CopyData (buf, size);
+ ret = m_nscTcpSocket->send_data((const char *)buf, size);
+ delete[] buf;
+
if (ret <= 0)
{
break;
--- a/src/test/ns3tcp/ns3tcp-interop-test-suite.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/test/ns3tcp/ns3tcp-interop-test-suite.cc Tue Aug 10 23:13:56 2010 -0400
@@ -153,10 +153,16 @@
//
Time tNow = Simulator::Now ();
int64_t tMicroSeconds = tNow.GetMicroSeconds ();
+
+ uint32_t size = p->GetSize ();
+ uint8_t *buf = new uint8_t[size];
+ p->CopyData (buf, size);
+
m_pcapFile.Write (uint32_t (tMicroSeconds / 1000000),
uint32_t (tMicroSeconds % 1000000),
- p->PeekData(),
- p->GetSize ());
+ buf,
+ size);
+ delete [] buf;
}
else
{
@@ -168,10 +174,13 @@
uint32_t tsSec, tsUsec, inclLen, origLen, readLen;
m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen);
- uint8_t const *actual = p->PeekData();
+ uint8_t *actual = new uint8_t[readLen];
+ p->CopyData (actual, readLen);
uint32_t result = memcmp(actual, expected, readLen);
+ delete [] actual;
+
//
// Avoid streams of errors -- only report the first.
//
--- a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Tue Aug 10 22:33:13 2010 -0400
+++ b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Tue Aug 10 23:13:56 2010 -0400
@@ -127,10 +127,16 @@
//
Time tNow = Simulator::Now ();
int64_t tMicroSeconds = tNow.GetMicroSeconds ();
+
+ uint32_t size = p->GetSize ();
+ uint8_t *buf = new uint8_t[size];
+ p->CopyData (buf, size);
+
m_pcapFile.Write (uint32_t (tMicroSeconds / 1000000),
uint32_t (tMicroSeconds % 1000000),
- p->PeekData(),
- p->GetSize ());
+ buf,
+ size);
+ delete [] buf;
}
else
{
@@ -142,10 +148,13 @@
uint32_t tsSec, tsUsec, inclLen, origLen, readLen;
m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen);
- uint8_t const *actual = p->PeekData();
+ uint8_t *actual = new uint8_t[readLen];
+ p->CopyData (actual, readLen);
uint32_t result = memcmp(actual, expected, readLen);
+ delete [] actual;
+
//
// Avoid streams of errors -- only report the first.
//
@@ -303,10 +312,14 @@
//
Time tNow = Simulator::Now ();
int64_t tMicroSeconds = tNow.GetMicroSeconds ();
+ uint32_t size = p->GetSize ();
+ uint8_t *buf = new uint8_t[size];
+ p->CopyData (buf, size);
+
m_pcapFile.Write (uint32_t (tMicroSeconds / 1000000),
uint32_t (tMicroSeconds % 1000000),
- p->PeekData(),
- p->GetSize ());
+ buf,
+ size);
}
else
{
@@ -318,10 +331,13 @@
uint32_t tsSec, tsUsec, inclLen, origLen, readLen;
m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen);
- uint8_t const *actual = p->PeekData();
+ uint8_t *actual = new uint8_t[readLen];
+ p->CopyData (actual, readLen);
uint32_t result = memcmp(actual, expected, readLen);
+ delete [] actual;
+
//
// Avoid streams of errors -- only report the first.
//