Tool/software:
Hello,
I am using NDK 2.26.00.08 on AM572x. It is on RTOS environment
The issue: Broadcast replies exhaust network buffers, and seems to have the entire network stuck. not sure how to increase pktNumFrameBufs (or alternative tuning method)
The goal is to receive a broadcast and send one in return.
I will share a snippet of how I init and how I send.
As long as the send function is commented - everything works fine. Once I send over 9k worth of data (in 1024x9 or 512x18 or 1400x7...). It seems like the network stack (tcp / ip or other wise) crashed. Accessing the network from another thread will crash the app.
I think this is a configuration issue - but I haven't found the "magic bullet" so far...
static int initBroadcastSocket(SOCKET* sock_out) {
struct sockaddr_in addr;
int optval = 1;
SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock == INVALID_SOCKET) {
IP_PRINT("IP scanner - socket failed\n");
return -1;
}
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval));
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(MULTICASTPORT_S);
addr.sin_addr.s_addr = htonl(INADDR_ANY);
if (OSAL_SOCKET_UDP_bind(sock, &addr, sizeof(addr)) < 0) {
IP_PRINT("IP scanner - bind failed\n");
OSAL_SOCKET_close(sock);
return -1;
}
*sock_out = sock;
return 0;
}
struct in_addr ip_addr = client_addr->sin_addr;
struct in_addr subnet_mask;
subnet_mask.s_addr = htonl(0xFFFFFF00);
struct in_addr broadcast_addr;
broadcast_addr.s_addr = ip_addr.s_addr | ~subnet_mask.s_addr;
struct sockaddr_in reply_addr = {0};
reply_addr.sin_family = AF_INET;
reply_addr.sin_port = htons(request->response_port);
reply_addr.sin_addr = broadcast_addr;
int sent = sendto(sock, json_buffer, sizeof(json_buffer), 0, &reply_addr, sizeof(reply_addr));
As you can see the json_buffer is just a random json that works, and there is a client that receives it.
On the same system I also had a Linux running with the same version of code (adapted to Linux) and that didn't happen.
I will also mention that the app is running a tcp stack without any problems.