Quantcast
Channel: Embedded Software (Read Only)
Viewing all articles
Browse latest Browse all 25965

Forum Post: RE: NDK 2.23: new socket without having a valid IP address

$
0
0

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


Viewing all articles
Browse latest Browse all 25965

Trending Articles