how to read the IP assigned by DHCP???

Hi all!!!

I’m working with the software DIGI ESP for NET+OS for my CONNECTME

How I get the value of IP assigned in my CONNECTME?? , when I configure by DHCP!!


Try API call customizeIamGetIfAddrInfo(). It is described in the API reference manual. The address contained in the structure is a 32-bit integer. If you want the dotted notation, you need to convert it.

I’m working with the software DIGI ESP for NET+OS for my ConnectME with jtag
when I create my project, in parameters of Network , I select " obtain an IP adress automatically (DHCP)"

When start my project, then my ConnectMe is asigned an IP automatically

I need read the value of the IP asigned to my Connect ME.

If I configure my Digi Connect ME with a static IP configuration then I have no problem to read the current IP (CustomizeIamGetStaticConfig and CustomizeGetIP)

But if I have my Digi device configured to obtain the IP parameters from the network (DHCP) then I have problems…

If I call CustomizeIamGetDhcpConfig , as I get the value of IP?

I used the function customizeIamGetIfAddrInfo but
not work

friends of the forum I hope your help!!!


What do you mean by it does not work? Did you get an address of or an error? What interface name did you pass in?

Are you sure the interface is completely up before you call customizeIamGetIfAddrInfo. I was using customizeIamGetIfAddrInfo today in some code that switches between static and DHCP-configured addresses. customizeIamGetIfAddrInfo was able to track the changes. But there was a lag time between the switch and when the interface could return its address.

It also works fine for me…

static NaIamIfAddrInfo_t addrInfo;
struct sockaddr_storage myaddr;
char ipstring[20];

if(customizeIamGetIfAddrInfo(“eth0”, &addrInfo) != NA_IAM_STATUS_SUCCESS)
printf("Error getting IP info!
NAInet_toa(addrInfo.v4Info.ipAddress.addr.ipv4.sin_addr.s_addr, ipstring);
printf("IP Address: %s
", ipstring);
NAInet_toa(addrInfo.v4Info.subnetMask, ipstring);
printf("SubMask: %s
", ipstring);
NAInet_toa(addrInfo.v4Info.defaultGateway.addr.ipv4.sin_addr.s_addr, ipstring);
printf("Gateway: %s
", ipstring);