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.

NDK UDP sendto problem

Hey everybody,

I have a problem in my sendto function from the ti ndk 2.24.


actDataSize = sendto(pObj->sockFd, (void*)dataBuf, dataSize, 0,(struct sockaddr*)&pObj->ipAddrRemote, pObj->ipAddrRemoteLen);

The ipAddrRemoteLen parameter has the value of 16.  When i follow the code to the next file (socket.c). 

After the line /* Verify Address Size */ the programm goto the error stage. And I have no idea why.

int NDK_sendto( SOCKET s, void *pbuf, int size, int flags, PSA pName, int len )
{
    FILEDESC *pfd = (FILEDESC *)s;
    int  error = 0;
    INT32    txsize;

    llEnter();

    /* Lock the fd - type must be SOCK / SOCK6 */
    if ((fdint_lockfd(pfd, HTYPE_SOCK) == SOCKET_ERROR) 
#ifdef _INCLUDE_IPv6_CODE      
       && (fdint_lockfd(pfd, HTYPE_SOCK6) == SOCKET_ERROR)
#endif
       )
    {
        llExit();
        return( SOCKET_ERROR );
    }

    /* Verify Address Size */
    if (((pfd->Type == HTYPE_SOCK) && len != sizeof(SA_IN)) 
#ifdef _INCLUDE_IPv6_CODE      
       || ((pfd->Type == HTYPE_SOCK6) && len != sizeof(SA_IN6))
#endif
       )
    {
        error = EINVAL;
        goto sendto_error;
    }

Benedikt

  • Benedikt,

    The size parameter is used for passing the actual size of the socket address structure that you are passing in (which varies with address family). I think you are passing in the size of the generic "struct sockaddr".

    Which type of socket address struct is "pObj->ipAddrRemote"?

    If it is a struct sockaddr_in (IPv4), then the value passed in for the 'len' parameter of sendto should be "sizeof(struct sockaddr_in)".

    If it is a struct sockaddr_in6 (IPv6), then the value passed in for the 'len' parameter of sendto should be "sizeof(struct sockaddr_in6)".

    Steve
  • Thanks Steve

    pObj->ipAddrRemote is from type struct sockaddr_in. I use only the IPv4 protocol.

    pObj is a pointer to the struct. And because of this i need the address for sizeof. OR?
    pObj->ipAddrRemoteLen = sizeof(&pObj->ipAddr_Remote);
    AND ipAddrRemoteLen is a int.

    Benedikt
  • Benedikt Cyranka said:
    actDataSize = sendto(pObj->sockFd, (void*)dataBuf, dataSize, 0,(struct sockaddr*)&pObj->ipAddrRemote, pObj->ipAddrRemoteLen);

    Can you try changing the above code to have the part in red for a test?

    actDataSize = sendto(pObj->sockFd, (void*)dataBuf, dataSize, 0,(struct sockaddr*)&pObj->ipAddrRemote, sizeof(struct sockaddr));

    Steve

  • I found the problem!
    it was not a problem with the length.


    The problem was in pObj->ipAddrRemote.
    e.g.
    struct sockaddr_in {
    short sin_family; // e.g. AF_INET
    unsigned short sin_port; // e.g. htons(3490)
    struct in_addr sin_addr; // see struct in_addr, below
    char sin_zero[8]; // zero this if you want to
    };

    struct in_addr {
    unsigned long s_addr; // load with inet_aton()
    };

    sin_port has an invalid port number. So the check function are confused and goto an error stage.
    I can't find the problem until today because i didn't recompiled the ndk packet.
    But today i compiled the ndk by my self and with an better debug mode ( processors.wiki.ti.com/.../Rebuilding_The_NDK_Core_Using_Gmake) and now i can watch ever step that the program does.

    So this problem is solved.
    Thanks