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.

TDA2EX17EVM: IPv6 UDP sendto function failure on TDA2ex

Part Number: TDA2EX17EVM

Hello Everyone,

I am working with TDA2ex and trying to assign IPv6 address to it and develop UDP client on it to communicate with IPV6 UDP server.

I have made changes as suggested in this post and i am able to get local link address and i can ping it from my PC. Now when i go to create IPv6 UDP
socket i can create it but when i call sendto function it returns -1 and i came to know its because of errno 22 which is invalid argument.

https://e2e.ti.com/support/arm/automotive_processors/f/1021/t/673201?tisearch=e2e-sitesearch&keymatch=IPV6%20retrieve

I have verified sin6_family , sin6_port and sin6_addr have correct values of server.

I have referred UDPEchoIPV6 example in TI RTOS package and i came to know for sendto function we are passing sockaddr_storage structure and not sockaddr_in6
that's why i made relavant changes in my application but still it returns 22.

What could be the wrong arguments , i have following queries :

1) With local link address , do i need to initialize scope_id member of sockaddr_in6 for sendto function ?

2) I referred UDPEchoIPV6 example code but it is for UDP IPV6 server , do we have any sample code UDP IPv6 client ?

Thanks for any suggestions.

  • Hi Kapil,

    Which version of the NDK are you using?

    Todd
  • Hi Kapil,

    Kapil Mehta said:

    1) With local link address , do i need to initialize scope_id member of sockaddr_in6 for sendto function ?

    No you don't have to initialize this.

    Kapil Mehta said:

    2) I referred UDPEchoIPV6 example code but it is for UDP IPV6 server , do we have any sample code UDP IPv6 client ?

    Currently we don't provide any UDP IPv6 client examples.

    Could you post your code where you are opening the socket and calling sendto() so that I can look it over?

    Thanks,
    Gerardo

  • Hello Todd,

    I am using ndk_2_24_02_31.
  • Hello Gerardo,
    Herewith i am sharing two interfaces for creating socket and sending data over sockets. I will be calling create and then write interface.
    Return value from sendto is 22. I have verified inet_pton returns success and verified proper port and address are filled in in6_addr structure.
    
    
    #define SERVER "ff14::1:a"
    #define SERVER_PORT 500002
    
    
    typedef struct Socket_NwkInterface {
        Network_SockObj ntwrkObj;
        struct sockaddr_in6 IPv6serverInfo;
    } SocketNetInterface;
    
    inline SocketNetInterface *Get_SocketNetInstance() {
    
      static SocketNetInterface SocketNetObj;
    
      return &SocketNetObj;
    }
    
    Int32 Network_CreateUDPIPv6() 
    {
        Int32 ret       = -1;
    
    #if ( defined(NDK_PROC_TO_USE_IPU1_0) && defined(BUILD_M4_0) ) || \
        ( defined(NDK_PROC_TO_USE_IPU1_1) && defined(BUILD_M4_1) ) || \
        ( defined(NDK_PROC_TO_USE_IPU2)   && defined(BUILD_M4_2) ) || \
        ( defined(NDK_PROC_TO_USE_A15_0)  && defined(BUILD_A15) )
    
        Int32 slen = 0;
        SocketNetInterface *Obj = Get_SocketNetInstance();
        slen = sizeof(Obj->IPv6serverInfo);
        char str [46];
      
        Network_sessionOpen(NULL);
    
        if( (Obj->ntwrkObj.sockFd=socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) < 0) 
        {
            Vps_printf("socket returned <0");
            ret = NETWORK_ERROR;
        }
       else 
       {
           memset((char *) &Obj->IPv6serverInfo, 0, slen);
           Obj->IPv6serverInfo.sin6_family = AF_INET6;
           Obj->IPv6serverInfo.sin6_port   = htons(SERVER_PORT);
           if(inet_pton(AF_INET6, SERVER ,(struct in_addr *) &Obj->IPv6serverInfo.sin6_addr)  < 0 ){
               Vps_printf("inet_pton failed");
           }; 
           inet_ntop(AF_INET6,&Obj->IPv6serverInfo.sin6_addr, str, 46);
           Vps_printf("%s\n", str);
           ret = 0 ;
        }
    
    #endif
     return ret;
    }
    
    Int32 Network_WriteUDPIPv6(char* buf)
    {
        Int32 ret =-1;
    #if ( defined(NDK_PROC_TO_USE_IPU1_0) && defined(BUILD_M4_0) ) || \
        ( defined(NDK_PROC_TO_USE_IPU1_1) && defined(BUILD_M4_1) ) || \
        ( defined(NDK_PROC_TO_USE_IPU2)   && defined(BUILD_M4_2) ) || \
        ( defined(NDK_PROC_TO_USE_A15_0)  && defined(BUILD_A15) )
    
        SocketNetInterface*Obj = Get_SocketNetInstance();
        UInt32 slen = sizeof(Obj->IPv6serverInfo);
        fdOpenSession( TaskSelf() );
        ret = sendto(Obj->ntwrkObj.sockFd, buf,  32, 0 , (struct sockaddr *) &Obj->IPv6serverInfo, slen);
        if(ret < 0 ){
        ret = fdError();
        Vps_printf("write UDPIPv6 ret = %d",ret);
        }
        else
          ret = 0;
        return ret;
    }
    
    Thanks for any suggestions.

  • Hello Gerardo,
    Herewith i am sharing two interfaces for creating socket and sending data over sockets. I am calling create and then write interface.
    Return value from sendto is 22. I have verified inet_pton returns success and verified proper port and address are filled in in6_addr structure.

  • Hi Kapil,

    Couple things, the port number you are using is too high, this should be a 16 bit number and the number you are using is greater than that. Also, are you calling connect() before your call to sendto(), so that your socket is in the connected state?

    BR,
    Gerardo
  • Hello Gerardo,

    Sorry by mistake i put ,

    #define SERVER_PORT 500002

    but it is actually 

    #define SERVER_PORT 50002 ,  which should be valid port value.

    and regarding connect , i believe being UDP it is optional , I should not need it if i am using sendto .Please correct me if i am wrong.

  • Hi Kapil,

    Actually yes you are correct there. One thing I wanted to try, could you try decompressing your IP address and see if that changes anything.

    Thanks,
    Gerardo
  • Hello Gerardo,

    Ok i have actually tried with another dummy address i.e. abcd:abcd:abcf:dfed:123e:12de:12fc:12ed and it didn´t work and gave -1 from sendto with same errno i.e. 22

    Though this address didn´t exist but i believe it is not necessary in case of UDP. I have tested the same interfaces on PC and it works.

    Thanks,
    Kapil Mehta
  • Hello Gerardo,

    I think the problem was with the way i am filling sockadd_in6 structure, i used getaddinfo function to fill the structures and it is working fine now.

    Thanks for your help.