unable to get IP address of a node

19 views
Skip to first unread message

nipa patani

unread,
Feb 21, 2017, 5:00:20 AM2/21/17
to ns-3-users
Hey,
I gone through many documentation but unable to get IP address.
Suggest me what changes can be done in my .cc file to get IP address of each node on a received packet.



Thanks.
pm-ex3.cc

Konstantinos

unread,
Feb 21, 2017, 5:25:00 AM2/21/17
to ns-3-users
Hi Nipa,

As I mentioned less than 24h, have a look at the PacketSink and specifically how it handles received packets.
This is also the place that triggers your trace source that you use for your ReceivePacket().

174  NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds ()
175  << "s packet sink received "
176  << packet->GetSize () << " bytes from "
178  << " port " << InetSocketAddress::ConvertFrom (from).GetPort ()
179  << " total Rx " << m_totalRx << " bytes");
180  }

In your scenario you have 

void ReceivedPacket(Ptr<const Packet> packet ,const Address &value)

which is triggered by this trace source 

190  m_rxTrace (packet, from);

Hence, your 'value' variable is the 'from' variable in the trace.

Yiannis

unread,
Feb 21, 2017, 5:39:24 AM2/21/17
to ns-3-users
Hi Nipa,

Are you sure that your code compiles? From a brief look at the ReceivedPacket function, I doubt it.
The trace you use is triggered in PacketSink::HandleRead (Ptr<Socket> socket) and it returns the address
of the originator. You can also see how this address is converted to IPv4 in that function (you know the transmitter and the recipient that
this traffic is destined to). You could also get the address of the recipient by changing the way you use the trace.
Reply all
Reply to author
Forward
0 new messages