Dear fellow ns3 users,
I am using the UdpEchoClient and UdpEchoServer applications and wanted to modify the NS_LOG_INFOs slightly, so that instead of “At time t, a packet with x bytes was send/received from/to y” it prints the details of the IP header (e.g. source and destination IP) as well
So I added the following lines to the send and receive method of my client, thinking they should do the trick (based on https://www.nsnam.org/wiki/HOWTO_extract_the_IP_src/dst_address_from_a_packet )
Ptr<Packet> copy = p->Copy ();
Ipv4Header iph;
copy->PeekHeader (iph);
NS_LOG_INFO ("This is the IP header:" << iph);
If I run myfirst.cc using this slightly modified UdpEcho client and server, the header that is printed does not provide anything useful:
I tried doing the same with the original packet (instead of using the copy) and tried PeekHeader instead of Remove, but the result was always the same. Can someone explain why the header looks like this?
From this post https://groups.google.com/forum/#!topic/ns-3-users/EtiGaGvh3YQ I found that this address is shown if the address is not initialized.
But why should the packet not be initialized in my case? The packets travel successfully from client to server, how should that be possible if they were empty. I did not change anything else in the code of the UpdEcho applications, and I know if I create pcap files, the packets I see are correct.
I am a beginner with ns3 and I feel like I must have misunderstood something here, and even though I have worked through the tutorial in detail and have searched the ns3 forum for a while now, I can’t resolve the issue on my own. So if anyone could explain my mistake to me, or at least point me to the right direction in order to understand I would be very grateful.
I considered using Ns3::Packet::Print(std::istream &os) const instead, but it only prints “Payload (size=1024)” and I am not sure if this method can even provide source and destination IP.
Best Regards