This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

OMAP-L138 LCDK, NDK change UDP port

Hi,i am using CCS 6.1 / NDK 2.25.00.09 / NSP 1.10.03.15. How i can change UDP port in my code below without DaemonFree() ?
This code is working properly and i can change ip address or gateway(using CfgGetEntry(), CfgRemoveEntry(), CfgAddEntry()). But what about UDP port ?

(In NDK configuration autoOpenCloseFD = true;)

/* Init udp daemon */
void netOpenHook()
{
  udpStart = DaemonNew( SOCK_DGRAM, 0, PORT_UDP, recUDP, 1, 16384, 0, 1 );
  sendudp = TaskCreate( tskUdpSend, "SendUDP", OS_TASKPRINORM, 2048, 0, 0, 0 );
}

uint8_t *pDat;

/* Receive frame and put him in circular buffer for parsing */
int recUDP( SOCKET s, UINT32 unused )
{
    int rxSize, i , tmp;

   for(;;)
   {
        tmp = sizeof( sin1 );
        currentSoc = s;
        rxSize = (int)recvncfrom( s, (void **)&pDat, 0, (PSA)&sin1, &tmp, &hBuffer );

        if( rxSize >= 0 )
        {
            for( i = 0; i < rxSize; i++)
                putBuffer(*pDat++);// analyzing data and create answer

            recvncfree( hBuffer );
        }
    }

  fdClose(s);  
   return(0);
}

/* Send UDP */
void tskUdpSend()
{
    while(1)
    {
        Semaphore_pend(semDatagramIsFull, BIOS_WAIT_FOREVER); // wait answer

        sendto( currentSoc, txDatagram , sizeD, 0, (PSA)&sin1, sizeof(sin1) );
        memset(txDatagram, 0, sizeof(txDatagram));
        

    }

}

I am trying use DaemonFree(), but after DaemonFree()->fdCloseSession()->llExit() i turn out in UDP callback and function recvncfrom() always return -1 .

  • Hi Ilya,

    You will not be able to change the UDP port if you are using DaemonNew() / DaemonFree().  You can try creating your recUDP() task from a network IP address hook function.  From that task, you can create the UDP socket.  The IP address hook function is called whenever an IPV4 address is added or removed, so you will need to add some code to ensure that your task is only created once.  An alternative would be to post a semaphore from the IP address hook to wake up your recvUDP() task when the IP address is added.  The reason for doing this in the IP address hook, is to ensure that you have an IP address before opening the sockets.

    See also this post:

    Best regards,

        Janet

  • Thanks! I will try later.