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.

AM5728: IPv6 UDP does not bind to socket

Part Number: AM5728

hello

I have a problem with sending data via IPv6 in AM572x EVM.

I want to send data packets with size greater than 64KB, so I have used the IPv6.

the code I written is as follows :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>


struct sockaddr_in6 udp_server_addr, udp_client_addr;
socklen_t addr_size;
int sockfd;

unsigned char TXbuf[200000];
int TXLen = 200000;

int main(int argc, char *argv[])
{
sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
if(sockfd<=0) { printf("socket error !\n"); return 0; }

udp_client_addr.sin6_family = AF_INET6;
udp_client_addr.sin6_port = htons(4001); // client port
inet_pton(AF_INET6, "fe80::0000:0000:fe0f:4bff:feab:9b38", &udp_client_addr.sin6_addr);

if (bind(sockfd, (struct sockaddr*) &udp_client_addr, sizeof(udp_client_addr)) == 0) {
    printf("Binded Correctly\n");
}
else{
    printf("Unable to bind\n");
    close(sockfd);
    return 0;
}


udp_server_addr.sin6_family = AF_INET6;
udp_server_addr.sin6_port = htons(5001); // server port
inet_pton(AF_INET6, "fe80::0000:0000:fe0f:4bff:feab:9b39", &udp_server_addr.sin6_addr);

addr_size = sizeof udp_server_addr;

int i = 0;
for(i=0; i<TXLen; i++){
    TXbuf[i] = 0xAA;
}

while(1){
    int ret = sendto(sockfd, TXbuf, TXLen, 0, (struct sockaddr *)&udp_server_addr, addr_size); //send the data to server

    if(ret == 0){
        printf("Unable to send\n");
        break;
    }
}

close(sockfd); 

return 0;
}

when I compile and run the object file, the message "Unable to bind" is shown.  that is, the socket can not bind to the network card.

note that the ping command is running fine as follows:

root@am57xx-evm:~# ping fe80::0000:0000:fe0f:4bff:feab:9b39 -6
PING fe80::0000:0000:fe0f:4bff:feab:9b39 (fe80::fe0f:4bff:feab:9b39): 56 data bytes
64 bytes from fe80::fe0f:4bff:feab:9b39: seq=0 ttl=128 time=0.355 ms
64 bytes from fe80::fe0f:4bff:feab:9b39: seq=1 ttl=128 time=0.414 ms
64 bytes from fe80::fe0f:4bff:feab:9b39: seq=2 ttl=128 time=0.408 ms
64 bytes from fe80::fe0f:4bff:feab:9b39: seq=3 ttl=128 time=0.386 ms
64 bytes from fe80::fe0f:4bff:feab:9b39: seq=4 ttl=128 time=0.390 ms
^C
--- fe80::0000:0000:fe0f:4bff:feab:9b39 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 0.355/0.390/0.414 ms
root@am57xx-evm:~#

also when I use IPv4, the binding and sending data works fine. the following code has been written for IPv4 UDP sending :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>


struct sockaddr_in udp_server_addr, udp_client_addr;
socklen_t addr_size;
int sockfd;

unsigned char TXbuf[50000];
int TXLen = 50000;

int main(int argc, char *argv[])
{
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if(sockfd<=0) { printf("socket error !\n"); return 0; }

udp_client_addr.sin_family = AF_INET;
udp_client_addr.sin_port = htons(4001); // client port
inet_pton(AF_INET, "192.168.100.10", &udp_client_addr.sin_addr);

if (bind(sockfd, (struct sockaddr*) &udp_client_addr, sizeof(udp_client_addr)) == 0) {
    printf("Binded Correctly\n");
}
else{
    printf("Unable to bind\n");
    close(sockfd); //close socket file-descriptor
    return 0;
}


udp_server_addr.sin_family = AF_INET;
udp_server_addr.sin_port = htons(5001); // server port
inet_pton(AF_INET, "192.168.100.11", &udp_server_addr.sin_addr);

addr_size = sizeof udp_server_addr;

int i = 0;
for(i=0; i<TXLen; i++){
    TXbuf[i] = 0xAA;
}

while(1){

    int ret = sendto(sockfd, TXbuf, TXLen, 0, (struct sockaddr *)&udp_server_addr, addr_size); //send the data to server

    if(ret == 0){
        printf("Unable to send\n");
        break;
    }
else{
    printf("sending OK\n");
}
}

close(sockfd); //close socket file-descriptor

return 0;
}

now, I do'nt know what should I do?  why does not it bind to network card when using IPv6?

any help would be appreciated,

Ali