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.

AM62A3: The application layer fails to receive UDP broadcast data because the udp port is not monitored

Part Number: AM62A3

Tool/software:

Test environment:
User customized development board
Linux Kernel 6.6
TI SDK 10.1

The server sends an offer message (UDP broadcast data) through Someip SD, and the NIC can receive it, because I can capture it through the tcpdump instruction, but the port is not monitored, so the data is not transmitted to the upper layer, resulting in communication failure, I did the following test to verify, please refer to the following figure

How can the kernel or TCP/IP stack solve this problem?

  • Hello, 

    Can you please describe your test setup? (I.e. Is your custom board directly connected to a link partner or through a switch? Is the link partner a Linux PC, another EVM/board running Linux, or some other device?)

    The server sends an offer message (UDP broadcast data) through Someip SD, and the NIC can receive it, because I can capture it through the tcpdump instruction, but the port is not monitored, so the data is not transmitted to the upper layer, resulting in communication failure

    Can you explain how you are determining the data is not transmitted to the upper layer? What is the communication error message you are seeing? I'm not seeing this information in your screenshot.

    -Daolin

  • #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <arpa/inet.h>
    
    #define BROADCAST_IP "239.127.3.1"  // 广播地址
    #define PORT 30499                     // 发送到的 UDP 端口
    #define MESSAGE "Hello from Ubuntu server"
    #define INTERVAL 1                     // 发送间隔(秒)
    
    int main() {
        int sockfd;
        struct sockaddr_in broadcast_addr;
        int broadcast_enable = 1;
    
        // 创建 UDP 套接字
        if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
            perror("Socket creation failed");
            exit(EXIT_FAILURE);
        }
    
        // 启用广播选项
        if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &broadcast_enable, sizeof(broadcast_enable)) < 0) {
            perror("Error enabling broadcast option");
            close(sockfd);
            exit(EXIT_FAILURE);
        }
    
        // 配置广播地址
        memset(&broadcast_addr, 0, sizeof(broadcast_addr));
        broadcast_addr.sin_family = AF_INET;
        broadcast_addr.sin_addr.s_addr = inet_addr(BROADCAST_IP);  // 使用广播地址
        broadcast_addr.sin_port = htons(PORT);
    
        printf("Sending UDP broadcast to %s:%d...\n", BROADCAST_IP, PORT);
    
        // 循环发送广播数据
        while (1) {
            if (sendto(sockfd, MESSAGE, strlen(MESSAGE), 0, (struct sockaddr *)&broadcast_addr, sizeof(broadcast_addr)) < 0) {
                perror("Send failed");
            } else {
                printf("Broadcast message sent: %s\n", MESSAGE);
            }
            sleep(INTERVAL);
        }
    
        close(sockfd);
        return 0;
    }
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <arpa/inet.h>
    
    #define PORT 30499           // 接收数据的 UDP 端口
    #define BUFFER_SIZE 1024
    #define MULTICAST_GROUP "239.127.3.1"  // 多播组地址
    
    int main() {
        int sockfd;
        struct sockaddr_in server_addr;
        char buffer[BUFFER_SIZE];
        ssize_t recv_len;
    
        // 创建 UDP 套接字
        if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
            perror("Socket creation failed");
            exit(EXIT_FAILURE);
        }
        printf("Socket created successfully.\n");
    
        /*
    	int reuse = 1;
        if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) {
            perror("Setting SO_REUSEADDR failed");
            close(sockfd);
            exit(EXIT_FAILURE);
        }
    	*/
    
        // 绑定地址和端口
        memset(&server_addr, 0, sizeof(server_addr));
        server_addr.sin_family = AF_INET;
        server_addr.sin_addr.s_addr = htonl(INADDR_ANY);  // 接收所有地址的数据
        server_addr.sin_port = htons(PORT);
    
        printf("Attempting to bind to port %d...\n", PORT);
        if (bind(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
            perror("Binding failed");
            close(sockfd);
            exit(EXIT_FAILURE);
        }
        printf("Successfully bound to port %d.\n", PORT);
    
        // 加入多播组
        struct ip_mreq mreq;
        mreq.imr_multiaddr.s_addr = inet_addr(MULTICAST_GROUP);  // 多播组地址
        mreq.imr_interface.s_addr = inet_addr(INADDR_ANY);   // 使用本地任意接口
        if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
            perror("Adding multicast group failed");
            close(sockfd);
            exit(EXIT_FAILURE);
        }
        printf("Joined multicast group %s\n", MULTICAST_GROUP);
    
        printf("Listening for UDP multicast on port %d...\n", PORT);
    
        // 循环接收数据
        while (1) {
            struct sockaddr_in client_addr;
            socklen_t addr_len = sizeof(client_addr);
            printf("Waiting to receive data...\n");
            recv_len = recvfrom(sockfd, buffer, BUFFER_SIZE - 1, 0, (struct sockaddr *)&client_addr, &addr_len);
    
            if (recv_len < 0) {
                perror("Receive failed");
                break;
            } else {
                buffer[recv_len] = '\0';
                printf("Received %zd bytes from %s:%d: %s\n",
                       recv_len, inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port), buffer);
            }
        }
    
        close(sockfd);
        return 0;
    }

    The above is the test program I wrote for verification, the client code udpclient.c is blocked in recvfrom, but through tcpdum -i eth0 udp port 30499, you can see that the board received UDP data broadcast packet, indicating that the data is sent to the network card, but not transmitted to the application layer. Then my board terminal executes the command ip addr add 239.127.3.1/24 dev eth0, the server and client can communicate, of course, I can also modify the above demo code, so that even without executing the above command can also communicate. I want to know where the board network configuration can be implemented like executing the command ip addr add 239.127.3.1/24 dev eth0

  • Hello,

    Your inquiry appears to be more application-specific than a specific issue with the lower-level Ethernet (CPSW) driver. Please note that we do not offer specific support on application-specific inquiries and focus on supporting TI specific drivers. Application-specific issues like creating an application (in your case udpclient.c) to open a port to receive UDP packets are not specific to TI.

    One thing I can suggest is to check if in/proc/net/snmp, the expected UDP packets are incrementing in those statistics.

    -Daolin

  • OK,thanks,I get it