How to obtain IP Address of current node using inet?

1,317 views
Skip to first unread message

omnetuser99

unread,
Nov 2, 2012, 5:55:36 AM11/2/12
to omn...@googlegroups.com
Hi,

I have a network with source node A connected to an intermediate node B and destination node C connected to intermediate node B.

I want to put a command in c++ code which gives me IPv4 address of the current node where the packet is being processed. For example, if the packet is at node A, it should give me IP of node A and if at B, it should give IP address of node B.

I am doing this in inet framework.

Thank you.

omnetuser99

unread,
Nov 2, 2012, 6:05:24 AM11/2/12
to omn...@googlegroups.com
P.S. There should be only one dynamic command for knowing the IP address of current node irrespective of the node name.

Andreas Benzing

unread,
Nov 2, 2012, 6:51:09 AM11/2/12
to omn...@googlegroups.com
Hey,

I'm using the code below which takes the address of interface 1 because 0 is set up to be the loopback interface.

IInterfaceTable* ift = InterfaceTableAccess().get();
IPAddress localIP;

if (ift->getInterface(1)->ipv4Data() != NULL) {
    localIP = ift->getInterface(1)->ipv4Data()->getIPAddress();
}

On Friday, November 2, 2012 10:55:36 AM UTC+1, omnetuser99 wrote:
Message has been deleted

Alfonso Ariza Quintana

unread,
Nov 2, 2012, 5:45:47 PM11/2/12
to omn...@googlegroups.com

 IPvXAddress addr = IPvXAddressResolver().resolve("node");



Date: Fri, 2 Nov 2012 06:04:14 -0700
From: muhamm...@gmail.com
To: omn...@googlegroups.com
Subject: [Omnetpp-l] Re: How to obtain IP Address of current node using inet?

This line is giving error localIP = ift->getInterface(1)->ipv4Data()->getIPAddress(); saying invalid use of 'structIPv4InterfaceData'. I have declared local IP as IPv4Address localIP; not just IPAddress.
--
--
Sent from the OMNeT++ mailing list. To configure your membership,
visit http://groups.google.com/group/omnetpp
 
 
 

nilou...@gmail.com

unread,
Jun 15, 2015, 2:34:53 PM6/15/15
to omn...@googlegroups.com, aari...@hotmail.com
how can i obtain host name from ipAddress?
thank you

Alfonso Ariza Quintana

unread,
Jun 16, 2015, 3:24:24 AM6/16/15
to omn...@googlegroups.com

 

IPvXAddressResolver().findHostWithAddress(IPvXAddress(addr))->getName();

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/omnetpp.
For more options, visit https://groups.google.com/d/optout.

nilou attar

unread,
Jun 19, 2015, 2:38:00 AM6/19/15
to omn...@googlegroups.com
Thank you but this code has bug. Do you know there is any way to solve it?

--
You received this message because you are subscribed to a topic in the Google Groups "OMNeT++ Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/omnetpp/wAAW5IIsEk4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to omnetpp+u...@googlegroups.com.

Alfonso Ariza Quintana

unread,
Jun 21, 2015, 5:30:17 AM6/21/15
to omn...@googlegroups.com
You need to check if the address is found

cModule *mod = IPvXAddressResolver().findHostWithAddress(IPvXAddress(addr))->getName();
if (mod != NULL) mod->getName();
// address found



Date: Fri, 19 Jun 2015 11:07:55 +0430
Subject: Re: [Omnetpp-l] Re: How to obtain IP Address of current node using inet?
From: nilou...@gmail.com
To: omn...@googlegroups.com

Alfonso Ariza Quintana

unread,
Jun 21, 2015, 5:30:53 AM6/21/15
to omn...@googlegroups.com
Sorry a mistake

cModule *mod = IPvXAddressResolver().findHostWithAddress(IPvXAddress(addr));

if (mod != NULL) mod->getName();
// address found





From: aari...@hotmail.com
To: omn...@googlegroups.com
Subject: RE: [Omnetpp-l] Re: How to obtain IP Address of current node using inet?
Date: Sun, 21 Jun 2015 11:30:11 +0200

Shaikha Al-Khuder

unread,
Jun 26, 2015, 7:15:15 AM6/26/15
to omn...@googlegroups.com, aari...@hotmail.com
It shows that the command is undeclared..
"use of undeclared identifier 'IPv4AddressResolver'"

Did I miss to include a certain header file?

Alfonso Ariza Quintana

unread,
Jun 26, 2015, 7:40:29 AM6/26/15
to omn...@googlegroups.com

It is IPvXAddressResolver not 'IPv4AddressResolver'

 

De: omn...@googlegroups.com [mailto:omn...@googlegroups.com] En nombre de Shaikha Al-Khuder


Enviado el: viernes, 26 de junio de 2015 13:15
Para: omn...@googlegroups.com
CC: aari...@hotmail.com

--

Adriana V R

unread,
Apr 15, 2016, 10:12:32 AM4/15/16
to OMNeT++ Users, aari...@hotmail.com
When I try to use the IPvXAddressResolver() the following message shows up: IPvXAddressResolver was not declared in this scope

Code: IPv4Address addr = IPvXAddressResolver().resolve("wiredHost1");

Alfonso Ariza Quintana

unread,
Apr 15, 2016, 12:11:15 PM4/15/16
to omn...@googlegroups.com

If you are using the latest inet or inetmanet version the class name is L3AddressResolver

Reply all
Reply to author
Forward
0 new messages