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.

AM5748: IPV6 sendto_error in sendto function

Genius 13655 points
Part Number: AM5748


Hello,

Customer used TMDSIDK574,bios_6_76_03_01,ndk_3_61_01_01,pdk_am57xx_1_0_17.

He wanted to realize IPV4 and IPV6 on TI-RTOS, but it can't work, he could not find the IPV6 address and where to configure the static IPV6 address. 

Below is his UDP IPv6 code:

Void sock_udp_ipv6(UArg arg0, UArg arg1)
{
sleep(5);
Task_Params params;
Error_Block eb;
SOCKET sock;
int dev_index = 1;
int status;
struct addrinfo hints;
struct addrinfo *results1 = NULL;
int value;
char port[8];
IP6N srcaddress;
static char src[] = "fe80::a00:9ff:fedc:aaaa";
if(IPv6StringToIPAddress((char *)&src[0],(IP6N*)&srcaddress)==-1)
{
UART_printf("\error.\n");
}
IPv6Init();
IPv6AddAddress(1,srcaddress,64,INFINITE_LT ,INFINITE_LT ,0);

fdOpenSession (TaskSelf ());
#if 1
if ((sock = socket (AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET)
{
UART_printf("\n sssss.\n");
return;
}

static char dst[] = "fe80::a00:9ff:fedc:abcd";
struct sockaddr_in6 stSockAdr;

stSockAdr.sin6_family = AF_INET6;
stSockAdr.sin6_port = NDK_htons(8899);
// inet_ntop(AF_INET6, (char *)&dst[0], &stSockAdr.sin6_addr, sizeof(stSockAdr.sin6_addr));
if(IPv6StringToIPAddress((char *)&dst[0],(IP6N*)&stSockAdr.sin6_addr)==-1)
{
UART_printf("\error.\n");
}

struct timeval to;
to.tv_sec = 3;
to.tv_usec = 0;
if(setsockopt( sock, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ))== SOCKET_ERROR){
UART_printf("\n er.\n");
}
if(setsockopt( sock, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ))== SOCKET_ERROR){
UART_printf("\n er.\n");
}

int slen = sizeof(stSockAdr);

int result = 0,z = -5;
char buffer[5] = "hello";
while(1){
result = sendto(sock,buffer,sizeof(buffer),0,(struct sockaddr *)&stSockAdr,slen);
z= fdError();
UART_printf("write %d bytes\n", result);
UART_printf("z=%d bytes\n", z);

}
#endif
// Close the file session
fdCloseSession(TaskSelf());
}

But when debugging sendto function, the code entered

NETIF_DEVICE* NIMUFindByIndex (uint32_t index)
{
NETIF_DEVICE* ptr_device;

/* Get the head of the list. */
ptr_device = (NETIF_DEVICE *)list_get_head ((NDK_LIST_NODE**)&nimu_mcb.devices);
while (ptr_device != NULL)
{
/* Did we get the match? */
if (ptr_device->index == index)
return ptr_device;

/* Go to the next element. */
ptr_device = (NETIF_DEVICE*)list_get_next ((NDK_LIST_NODE*)ptr_device);
}

/* No matching entry found. */
return NULL;
}


Everytime it returns NULL which caused sendto_error in sendto function :

sendto_error:
/* Unlock the fd with error */
fdint_unlockfd(pfd, error);

llExit();

return (SOCKET_ERROR);

It can't send data, the fdError() return value is 22. 

Thanks.
Rgds
Shine

  • Error code 22 means invalid argument. Most like stSockAdr contains invalid info.

    To use IPv6 in NDK, there are extra steps required.

    You can search e2e forum for IPv6 related question to find the reference how to enable IPv6 in NDK.