# How to get the current IP-Address/Mask/Gateway in

**URL:** <https://forums.digi.com/t/how-to-get-the-current-ip-address-mask-gateway-in/3922>\
**Category:** NET+OS\
**Tags:** read-ip\
**Created:** [July 21, 2006, 9:37am UTC](https://forums.digi.com/t/how-to-get-the-current-ip-address-mask-gateway-in/3922 "2006-07-21T09:37:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/digi/original/1X/11da31a6a1fbcd03ef21d3f785c317c824009ae2.png) [@system](https://forums.digi.com/u/system)\
**Post date:** [July 21, 2006, 9:37am UTC](https://forums.digi.com/t/how-to-get-the-current-ip-address-mask-gateway-in/3922/1 "2006-07-21T09:37:33Z")

</div>

If I configure my Digi Connect ME (JTAG or -C Device) with a static IP configuration then I have no problem to read the current IP settings [customizeAceGetConfig(…), customizeAceGetStaticConfig(…)].

But if I have my Digi device configured to obtain the IP parameters from the network (DHCP) then I have some problems… If I call customizeAceGetDhcpConfig(…) the parameter suggested\_ip\_address is zero.

In this forum I found the function NAIpAddress() which gives me the obtained IP-Address. But how can I get des SubnetMask and the Gateway-Address?

Thanks  
Michael

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/digi/original/1X/11da31a6a1fbcd03ef21d3f785c317c824009ae2.png) [@system](https://forums.digi.com/u/system)\
**Post date:** [July 24, 2006, 1:14pm UTC](https://forums.digi.com/t/how-to-get-the-current-ip-address-mask-gateway-in/3922/2 "2006-07-24T13:14:43Z")

</div>

I found the solution for my problem…

I studied the function NAIpAddress() which contains the following code (nainet.c):

* * *

unsigned long NAIpAddress (void)  
{

```
netdev *ndp;

unsigned long iplong = 0;
if ( (ndp = ll_dev_2_ndp("eth0")) != (netdev *)0 )
{
	iplong = ndp-&gt;nd_ipas[0].nd_ipaddr;
}
return (ntohl(iplong));

```

}

* * *

While looking for nd\_ipaddr I found the struct _nd\_ipa_ in netdev.h:

* * *

typedef struct _nd\_ipa_ {  
u32 nd\_ipaddr;  
u32 nd\_ipmask;  
u32 nd\_ipbcast;  
u16 nd\_ipflags;  
int nd\_secidx;  
void \*ip\_circ;  
void \*nd\_parent;  
struct _nd\_ipa_ \*next;

}nd\_ipaddr, \*nd\_ipaddr\_pt;

* * *

My code for the IP-Address and the Subnetmask looks like this:

netdev \*ndp;  
unsigned long ipAddress, subnetMask

ndp = (netdev\*)ll\_dev\_2\_ndp(“eth0”);  
ipAddress = ntohl( ndp-\>nd\_ipas[0].nd\_ipaddr );

ndp = (netdev\*)ll\_dev\_2\_ndp(“eth0”);  
subnetMask = ntohl( ndp-\>nd\_ipas[0].nd\_ipmask );

Michael

btw:  
you have to include netdev.h

Jul 25, 2006 11:20 AM  
The procedure above does not work properly! The returned ipAddress is correct, but the SubnetMask is wrong.  
Use the the function customizeAceGetInterfaceAddrInfo(…) instead.
