Massimo,
This problem has come up before. It appears to be a requirement for the user to prevent socket() from being called prior to the IP address being obtained.
There is a callback function that the user can configure which will be called when an IP addressed is obtained.
The recommended approach to using this callback is as follows:
Add the following to your config file:
var Global = xdc.useModule('ti.ndk.config.Global');
Global.networkIPAddrHook = '&netIPAddrHook';
And add something like this in your C code:
/*
* ======== netIPAddrHook ========
* Called when an IP address is added/removed from the system.
*/
void netIPAddrHook(IPN IPAddr, uint IfIdx, uint fAdd)
{
struct sockaddr_in ipv4addr;
struct sockaddr_in6 ipv6addr;
int currPos = 0;
/* if IP address is being added, then post a semaphore to unblock your user task */
if (fAdd) {
Semaphore_post(networkSem);
}
else {
// IP address is being removed from system …
}
}
/* User's task */
Void networkTask()
{
Semaphore_pend(networkSem);
socket(...);
}
I hope this helps.
Alan