Mehic.info

Add and read content to Packet payload in NS3

To add content to packet payload you can use following commands:

std::ostringstream msg; msg << "Hello World!" << '\0';
Ptr<Packet> packet = Create<Packet> ((uint8_t*) msg.str().c_str(), msg.str().length());

To read content from packet payload:

uint8_t *buffer = new uint8_t[packet->GetSize ()];
packet->CopyData(buffer, packet->GetSize ());
std::string s = std::string((char*)buffer);