AnsweredAssumed Answered


Question asked by vines on Mar 13, 2014
Latest reply on Jun 10, 2015 by arnogir



Is it possible to send UDP packets even if IP is not binded? Sorry if this sounds as a basic question. I am trying out the code below:



    sockaddr_in addrUdp;

    u32 sock,sockUdp;

    u32 error;

    u16 rlen;

    _enet_address enet_address = {0,27,134,1,0,99};


    error = RTCS_create();

    if (error!= RTCS_OK)


    if ((ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, enet_address)) != IPCFG_OK)



    addrUdp.sin_family = AF_INET;

    addrUdp.sin_port = UDP_PORT;//defined port

    addrUdp.sin_addr.s_addr = INADDR_ANY;

    sockUdp = socket(AF_INET, SOCK_DGRAM, 0);

    if (sockUdp== RTCS_SOCKET_ERROR)



    error= bind(sockUdp, &addrUdp, sizeof(addrUdp));

    if (error!= RTCS_OK)





        byte buffer[MAX_MESSAGE];

        sock= RTCS_selectall(-1);

        if (sock== sockUdp)


          byte buffer[MAX_MESSAGE];

          u32 result;

          rlen = sizeof(addrUdp);

          result = recvfrom(sockUdp, buffer, 100, 0, &addrUdp, &rlen);

          if (result != RTCS_ERROR && result > 0 && result <= MAX_MESSAGE)


              //if successfull addrUdp contains the src port and sin_addr to reply. Everything are correct

              error = sendto(sockUdp, buffer, result, 0, &addrUdp, rlen);






I can receive the packets from my SW tool. However, when I try to send it out, it is having an error.When I debug the code I found out that it is having an error in function SOCK_DGRAM_sendto in file sdgram.c.

Error is 0x00001510 after returning from this line error = RTCSCMD_issue(parms, UDP_send);

When I search the error it is defined as RTCSERR_IP_UNREACH.


If I add an IP bind e.g.

ipcfg_bind_staticip(ENET_DEVICE, &ip)

Everything works. However,my device by default is factory reset to IP, subnet and gateway. Thus, trying to bind will have an error. Configuring of IP is done via UDP.


I am using a switch that connects my PC and the device only.I am using wireshark to see if there is packet being transmitted from my device. There was none captured.


On the side note, I have a competitor product with the same setup as above (switch and my PC with competitor SW). Their device replies even if all are default values. I can see from wireshark source. Thus, from a technical point I know it is possible. I just don't know how to do it on MQX.


Now back to my question is it possible to send UDP packets without IP binding? Do I need to set any other options in mqx?  Is there any setting in rtcs project to enable this? Or user_config.h? I played around these settings on user_config.h but to no avail


all either 1/0 does not work






Any help will be greatly appreciated.


Thank you very much!