Is there a simple way to find which IP address is being used, regardless of whether it is static, DHCP'd or AutoIP'd, I just want some function that will return the IP address being used (as it appears in IPSetup or AutoUpdate)
this is my initialisation, I do not time out on getting DHCP'd on powerup, I want to handle situation where the ethernet is not necessarily connected at powerup, but should be able to be connected / disconnected to either a network (DHCP) or a laptop (AutoIP) at any time
Code: Select all
InitializeStack();
if (EthernetIP == 0)
{
DhcpObject * pDhcpObj = new DhcpObject();
pDhcpObj->StartDHCP();
}
OSChangePrio(MY_MAIN_PRIO);
EnableAutoUpdate();
EnableSmartTraps();
EnableTaskMonitor();
I have come up with a function that I think will do what I want
Code: Select all
IPADDR GetCurrentIP(void)
{
// search through interface blocks in sequence until a non-zero IP is found, return the non-zero IP, or return 0 if cannot find any non-zero IP
IPADDR ip=0;
int i=0;
while( !ip && (i=GetnextInterface(i)) ) // GetFirstInterface() is the same as GetnextInterface(0)
{
ip = InterfaceIP(i);
}
return ip;
}