extract the IP

47 views
Skip to first unread message

Raea

unread,
Jun 16, 2012, 6:01:16 PM6/16/12
to ns-3-...@googlegroups.com
Hello Group,
I would like to ask how can I get the IPv4 of the source from the received packet at the socket

thanks 

Fabian

unread,
Jun 18, 2012, 7:49:42 AM6/18/12
to ns-3-...@googlegroups.com
This should do it (it is the ReceivePacket which you can find in several examples, e.g. wifi-simple-adhoc).

void ReceivePacket (Ptr<Socket> socket)
{
  Address addr;
  socket->GetSockName (addr);
  Ptr<Packet> pkt = socket->RecvFrom(addr);
  InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (addr);
  Ipv4Address sourceIp = iaddr.GetIpv4();

Raea

unread,
Jun 18, 2012, 5:30:10 PM6/18/12
to ns-3-...@googlegroups.com
hello 
thanks for reply but it did not work it give always 0.0.0.0  but this is not correct because the IP for the socket should be the same as the IP of the node
if I am right 
but I solve the problem by adding an IPheader and this header have the IP of the socket and at the receiver I can extract this header and see the IP

correct me please, I am not good at the network layer, specially at NS3
Best Regards
Raea 
Reply all
Reply to author
Forward
0 new messages