how to get Node from Ipv4 Address

1,672 views
Skip to first unread message

mpaul

unread,
Sep 21, 2011, 4:58:33 PM9/21/11
to ns-3-users
Hi all,

How to get the Node from the Ipv4 address

InetSocketAddress::ConvertFrom (from).GetIpv4 ());

The above code returns the IPv4 address.how to know the node to which
it is associated.

thanks

manjinder

Lalith Suresh

unread,
Sep 22, 2011, 6:44:24 PM9/22/11
to ns-3-...@googlegroups.com
An IP address is a property of a network interface and not of a node. Try to the find the device which holds that IP address, and then do ->GetDevice ()->GetNode() to get the node.
 
thanks

manjinder

--
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.




--
Lalith Suresh

mpsingh

unread,
Sep 22, 2011, 11:16:55 PM9/22/11
to ns-3-...@googlegroups.com
Thanks for the help

could you please give more extended code to get the Node. I tried, what you explained, but did not get the node.

I have Ipv4Address and need to know to netDevice  and further to which Node it is associated.

regards

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

Lalith Suresh

unread,
Sep 23, 2011, 6:17:50 AM9/23/11
to ns-3-...@googlegroups.com
On Fri, Sep 23, 2011 at 5:16 AM, mpsingh <mpa...@gmail.com> wrote:
> Thanks for the help
>
> could you please give more extended code to get the Node. I tried, what you
> explained, but did not get the node.
>
> I have Ipv4Address and need to know to netDevice  and further to which Node
> it is associated.
>

(disclaimer: I'm saying this out of memory)

In your simulation script, you probably have an
Ipv4InterfaceContainer. You can iterate through it to get (Ptr<Ipv4>,
interface_index) tuples. With the first entity in the tuple (I'll call
it ipv4), do:

if (ipv4->GetInterfaceForAddress (whatever_address_you_want) != -1)
Ptr<node> node_pointer_you_are_looking_for = ipv4->GetObject<Node> ()

But in any case, it's easiest (and fun) to go through the respective
.h files to figure out the APIs. You can also see the doxygen docs.

Raea

unread,
Jun 17, 2012, 6:36:16 AM6/17/12
to ns-3-...@googlegroups.com
Hello All,
I have question somehow related to the previous discussion, I have a received packet and I would like to know the IPv4 of the  node that sent this packet

so anybody can help me please


>>> For more options, visit this group at
>>> http://groups.google.com/group/ns-3-users?hl=en.
>>>
>>
>>
>>
>> --
>> Lalith Suresh
>> www.lalith.in
>>
>> --
>> 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


>> 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
>
> --
> 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


> For more options, visit this group at
> http://groups.google.com/group/ns-3-users?hl=en.
>

--
Lalith Suresh
www.lalith.in

Konstantinos

unread,
Jun 17, 2012, 6:48:23 AM6/17/12
to ns-3-...@googlegroups.com
ΗΙ

On Sunday, 17 June 2012 11:36:16 UTC+1, Raea wrote:
Hello All,
I have question somehow related to the previous discussion, I have a received packet and I would like to know the IPv4 of the  node that sent this packet


At which level (application, network, MAC) is this received packet? Because simply the IP address of the received packet is available at the IP header.
If you want to know at the application layer, then a solution whould be to tag the packet with the IP header.

Raea

unread,
Jun 17, 2012, 7:59:22 AM6/17/12
to ns-3-...@googlegroups.com
hello  Konstantinos,
thanks for reply and the clarification, actually I am not quite sure but I think I am at the application layer because I can read the data included in the packet
I am using this way, using Rece() as in the following 

void ReceivePacket (Ptr<Socket> socket)

{
  Ptr<Packet> packet;
  double rxBytes = 0;
  while (packet = socket->Recv ())
    {
    rxBytes += packet->GetSize ();
        
    }   

if I was correct and I am at the application layer, so I think first of all I have to define a header and the tag it to the packet, like this 
UdpHeader udpHeader;
 udpPacket->AddHeader(udpHeader);

and at the function of the ReceivePacket I have to remove the header but what it next, supposing I am correct at the beginning 
thaks a lot
Raea
Reply all
Reply to author
Forward
0 new messages