How to get the IP address of Node to which application instance is associated

4,440 views
Skip to first unread message

mpaul

unread,
Dec 1, 2011, 9:55:31 PM12/1/11
to ns-3-users
Hi All,


Scenario:

Using UdpEchoSerer and UdpEchoClinet application. Client send packet
to server and server send echo message to client. On receiving the
echo packet, client displays the information that "it " has received
packet from server "IP address."

My requirement:

When client displays the sever IP address, I also want the IP address
of client that has received the packet.

Means I want to know the IP address of Node to which UdpEchoClient
application instance is associated.

The code that I tried:

Ptr <Node> PtrNode = this->GetNode();
Ptr<NetDevice> PtrNetDevice = PtrNode->GetDevice(0);
//Address clientAddress = PtrNetDevice->GetAddress();

Code up to this works well and returns the MAC address of Netdevice
of that "Node"

I want the IPv4 Address of node to which this application instance is
associated. I tried the following code.

Ptr<Ipv4> ipv4 = PtrNode->GetObject<Ipv4> ();
IpvInterfaceAddress iaddr = ipv4.GetAddress (1,0); Ipv4Address ipAddr
= iaddr.GetLocal ();

This code returns an error.
1. "Ipv4" is not declared in this scope.
2. in the first code line : template argument is invalid.
3. Ipv4InterfaceAddress is not declared in this scope
4. no matching function for call to ns3::Node::GetObject();

Please help how to get the IP address

Eric Gamess

unread,
Dec 1, 2011, 10:52:28 PM12/1/11
to ns-3-users
Hi mpaul,

> Ptr<Ipv4> ipv4 = PtrNode->GetObject<Ipv4> ();
> IpvInterfaceAddress iaddr = ipv4.GetAddress (1,0); Ipv4Address ipAddr
> = iaddr.GetLocal ();

You have to change two things:

1: It is Ipv4InterfaceAddress, not IpvInterfaceAddress.
2: it is ->, not .

Like:

Ipv4InterfaceAddress iaddr = ipv4->GetAddress(1, 0);

mpsingh

unread,
Dec 2, 2011, 10:55:40 AM12/2/11
to ns-3-...@googlegroups.com
Hi Eric,

Sorry there was typo in email text.

Actually I am using the same code that you suggested.

         Ptr<Ipv4> ipv4 = PtrNode->GetObject<Ipv4> ();
         Ipv4InterfaceAddress iaddr = ipv4->GetAddress (1,0); 
         Ipv4Address ipAddr = iaddr->GetLocal ();

I am getting the same errors, that I mentioned before.

I am writing this code in UdpEchoClient.cc to get the IP address of node on which this application instance is running.

when I use this code in my script file, it works well.


Please help me, what to do.

thanks


Paul


--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
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.




--
M P Singh
+1 613 422 8074
+1 613 600 3029

Eric Gamess

unread,
Dec 2, 2011, 11:22:57 AM12/2/11
to ns-3-users
Paul,

So, it seems to be an include problem.
Try putting the following lines at the beginning of the file:


#include "ns3/network-module.h"
#include "ns3/ipv4.h"

using namespace ns3;

mpsingh

unread,
Dec 2, 2011, 11:33:59 AM12/2/11
to ns-3-...@googlegroups.com
I included these modules and the error is

In file included from ../src/applications/model/udp-echo-client.cc:29:0:
debug/ns3/network-module.h:3:3: error: #error "Do not include ns3 module aggregator headers from other modules; these are meant only for end user scripts."

This did not work.

Thanks

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
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.

LucasBrito

unread,
Jan 13, 2014, 9:33:25 AM1/13/14
to ns-3-...@googlegroups.com
Hi,

Did you solve this problem? I'm with exactly the same problem...

Lucas.

LucasBrito

unread,
Jan 13, 2014, 10:04:16 AM1/13/14
to ns-3-...@googlegroups.com
Hi Paul,

I did make like you, and worked perfectly!

Att, Lucas

Reply all
Reply to author
Forward
0 new messages