Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket

This commit is contained in:
Hajime Tazaki committed 2010-06-04 07:05:22 +09:00
1 parent adee6a1399
commit f90f72425b
3 files changed
+15 -2

No files matched your search

+5 -1
View File
@@ -1,3 +1,4 @@
#include <netinet/in.h>
#include "ipv4-raw-socket-impl.h"
#include "ipv4-l3-protocol.h"
#include "icmpv4.h"
@@ -238,7 +239,10 @@ Ipv4RawSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
if (data.packet->GetSize () > maxSize)
{
Ptr<Packet> first = data.packet->CreateFragment (0, maxSize);
data.packet->RemoveAtStart (maxSize);
if (!(flags & MSG_PEEK))
{
data.packet->RemoveAtStart (maxSize);
}
m_recv.push_front (data);
return first;
}
+5
View File
@@ -42,6 +42,7 @@
#include <string>
#include <limits>
#include <netinet/in.h>
namespace ns3 {
static void
@@ -104,6 +105,8 @@ void Ipv4RawSocketImplTest::ReceivePkt (Ptr<Socket> socket)
{
uint32_t availableData;
availableData = socket->GetRxAvailable ();
m_receivedPacket = socket->Recv (2, MSG_PEEK);
NS_ASSERT (m_receivedPacket->GetSize () == 2);
m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max(), 0);
NS_ASSERT (availableData == m_receivedPacket->GetSize ());
}
@@ -112,6 +115,8 @@ void Ipv4RawSocketImplTest::ReceivePkt2 (Ptr<Socket> socket)
{
uint32_t availableData;
availableData = socket->GetRxAvailable ();
m_receivedPacket2 = socket->Recv (2, MSG_PEEK);
NS_ASSERT (m_receivedPacket2->GetSize () == 2);
m_receivedPacket2 = socket->Recv (std::numeric_limits<uint32_t>::max(), 0);
NS_ASSERT (availableData == m_receivedPacket2->GetSize ());
}
+5 -1
View File
@@ -18,6 +18,7 @@
* Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
*/
#include <netinet/in.h>
#include "ns3/inet6-socket-address.h"
#include "ns3/node.h"
#include "ns3/packet.h"
@@ -264,7 +265,10 @@ Ptr<Packet> Ipv6RawSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, Addre
if (data.packet->GetSize () > maxSize)
{
Ptr<Packet> first = data.packet->CreateFragment (0, maxSize);
data.packet->RemoveAtStart (maxSize);
if (!(flags & MSG_PEEK))
{
data.packet->RemoveAtStart (maxSize);
}
m_data.push_front (data);
return first;
}