extract packet's header

1,497 views
Skip to first unread message

Sara

unread,
Jun 2, 2012, 9:03:17 AM6/2/12
to ns-3-...@googlegroups.com
Dear All,
I made some modification in the UdpHeader.h , that if I have packet P then I can say p.data = "xx.." .
and my question is how can I read this data at the received packet, because the header is part of the packet and this inserted data is part of the header, so to read the data in the header should be possible 
thanks a lot
Regards


phuchong kheawchaoom

unread,
Jun 2, 2012, 9:52:12 AM6/2/12
to ns-3-...@googlegroups.com
I think that the packet can be read by this method but i am not sure.   

uint8_t *buffer = new uint8_t[packet->GetSize()]; 
          pk->CopyData (buffer, packetk->GetSize()); 
                         string data = string((char*)buffer);

Good luck



--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ns-3-users/-/W-kJ3sY2yToJ.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.

Sara

unread,
Jun 2, 2012, 10:32:55 AM6/2/12
to ns-3-...@googlegroups.com
Dear  kheawchaoom,
thanks a lot, but it is not exactly what I need but it could help and I have question please
what do you mean by pk do you mean that I should create new packet called pk or do you mean the same previous packet
another question : can I use your way to enter a string data like name to the source node to the packet
and then at the receiver I make a copy for this data
thank you again
Regards


On Saturday, June 2, 2012 3:52:12 PM UTC+2, phuchong kheawchaoom wrote:
I think that the packet can be read by this method but i am not sure.   

uint8_t *buffer = new uint8_t[packet->GetSize()]; 
          pk->CopyData (buffer, packetk->GetSize()); 
                         string data = string((char*)buffer);

Good luck

phuchong kheawchaoom

unread,
Jun 2, 2012, 11:54:43 AM6/2/12
to ns-3-...@googlegroups.com
sorry for my error.

At sender, you can create a packet by this way. 

 stringstream msgx;
                msgx << " abcdefg or your data " ;
                uint16_t packetSize = 800;
        Ptr<Packet> packet = Create<Packet>((uint8_t*) msgx.str().c_str(), packetSize);

At receiver, you can read the data by this way

  uint8_t *buffer = new uint8_t[packet->GetSize()]; 
        packet->CopyData (buffer, packet->GetSize());
                        string data = string((char*)buffer);
 
I hope it works.
Regards


--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ns-3-users/-/x2DrwWh684wJ.

Sara

unread,
Jun 2, 2012, 1:51:16 PM6/2/12
to ns-3-...@googlegroups.com
thank you very much, it works perfectly 
it was really helpful for me 
Best Regards
Sara


On Saturday, June 2, 2012 5:54:43 PM UTC+2, phuchong kheawchaoom wrote:
sorry for my error.

At sender, you can create a packet by this way. 

 stringstream msgx;
                msgx << " abcdefg or your data " ;
                uint16_t packetSize = 800;
        Ptr<Packet> packet = Create<Packet>((uint8_t*) msgx.str().c_str(), packetSize);

At receiver, you can read the data by this way

  uint8_t *buffer = new uint8_t[packet->GetSize()]; 
        packet->CopyData (buffer, packet->GetSize());
                        string data = string((char*)buffer);
 
I hope it works.
Regards

Sara

unread,
Jun 15, 2012, 7:30:04 PM6/15/12
to ns-3-...@googlegroups.com
Hello  kheawchaoom,
it is me again, your answer last time helped me and I hope you can help me now again
actually I am at the same subject, it took a lot of time
I would like to ask you how can I read the packet from the receiver node
for transmitter i am using Send(packet)
and at the receiver I am using Recv();
as the following code

  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");

  Ptr<Socket> destination = Socket::CreateSocket (c.Get (sinkNode), tid);// where sinkNode is node number 0;
  InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 8);
  destination->Bind (local);

  Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid);
  InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 8);
  source->Connect (remote);

   Ptr<Packet> recPacket = Create<Packet> ();
   Ptr<Packet> Packet1 = Create<Packet> (10);

   source->Send(Packet1);
    recPacket = destination->Recv();
   recPacket->GetSize(); // here is the error 

and at last line it always give an error, because it give a zero received packet 
so can you please tell me what is the wrong, and how can I read the packet from the socket at the node, and then to read the data
I really appreciate your help

Sara

phuchong kheawchaoom

unread,
Jun 16, 2012, 6:42:16 AM6/16/12
to ns-3-...@googlegroups.com
http://www.nsnam.org/doxygen-release/classns3_1_1_socket.html#a97f08aaf37b8fd7d4b5cad4dfdd4022a

Detailed Description

A low-level Socket API based loosely on the BSD Socket API.

A few things to keep in mind about this type of socket:

  • it uses ns-3 API constructs such as class ns3::Address instead of C-style structs
  • in contrast to the original BSD socket API, this API is asynchronous: it does not contain blocking calls. Sending and receiving operations must make use of the callbacks provided.
  • It also uses class ns3::Packet as a fancy byte buffer, allowing data to be passed across the API using an ns-3 Packet instead of a raw data pointer.
  • Not all of the full POSIX sockets API is supported

Other than that, it tries to stick to the BSD API to make it easier for those who know the BSD API to use this API. More details are provided in the ns-3 tutorial.



I do not know it too but I guess that you do not make call a call back in your simulation.




--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ns-3-users/-/MuZhSUkI8x0J.

Poonam Mishra

unread,
Jul 19, 2014, 3:18:42 AM7/19/14
to ns-3-...@googlegroups.com
can u give the full program of this???????????please
i want to stream a rtmp url.............


R.C Duan

unread,
Mar 29, 2017, 6:58:10 AM3/29/17
to ns-3-users
Hi Stephanie,
It looks like I'm facing the same problem. I'm going to modify IP header of packets through a router, but don't know how routers/nodes receive a packet then forward it. So I viewed some source code, only find where TTL minus one is. 
So about your problem, did you figure it out? Maybe your solution would be helpful to me.
thanks a lot.
Regards





在 2012年6月16日星期六 UTC+8上午7:30:04,Stephan写道:

Tommaso Pecorella

unread,
Apr 1, 2017, 7:05:28 PM4/1/17
to ns-3-users
Please read the posting guidelines AND the thread's date.

T.
Reply all
Reply to author
Forward
0 new messages