How to get the current node's interface Ipv4Address

37 views
Skip to first unread message

Shanen Leen

unread,
Jun 24, 2017, 4:26:04 AM6/24/17
to ns-3-users
How to get the current node's interface Ipv4Address(My IP Address, Not destination or origin address of the packet received) within the RouteInput() method?

Currently I'm working in aodv-routing-protocol.cc/.h.
I think i can do so with the help of Ptr<const NetDevice> idev parameter. But not sure how.

Tommaso Pecorella

unread,
Jul 17, 2017, 6:40:16 PM7/17/17
to ns-3-users
In Aodv::RoutingProtocol you have a handy m_ipv4. As a consequence, you can just do:

  for (uint32_t i=0; i<m_ipv4->GetNInterfaces(); i++)
   
{
     
for (uint32_t j=0 ; j<m_ipv4->GetNAddresses (i); j++)
       
{
         
Ipv4Address myAddress = m_ipv4->GetAddress (i, j);
       
}
   
}

T.

Reply all
Reply to author
Forward
0 new messages