1

I am trying to transfer raw ethernet packets from a linux machine to a microcontroller. I have to use raw packets because the micro sends raw frames and it doesnt have any tcp/ip stack.

fd = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW);
sendto(fd, sendbuf, 64, 0, (struct sockaddr*)&socket_address, sizeof(struct sockaddr_ll))

While I can transmit and receive all frames correctly, I am unable to do it real-time. For example, I have a packet on the linux machine which should be sent out every 20ms. What I observe is that while I transmit a packet on an average of 20ms, I dont see it every 20ms. This I think is because the processor is trying to buffer a few msgs before sending out. I changed the buffers like so -

int buff = 1;

(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buff, sizeof(int))

and still dont see any effect. Is there a way to flush out the transmit buffer of the raw socket as soon as there is information in it instead of it waiting for a few msgs to buffer up? Or is my understanding of the delay wrong?

NanoNi
  • 315
  • 4
  • 16
  • The processor does not buffer anything when doing raw sockets. I would guess that it is a scheduler problem instead, i.e. your code does not actually send a packet every 20ms since it does not even run every 20ms. – Steffen Ullrich Jan 20 '20 at 16:59
  • I thought so too, but then the RX msgs into the Linux are coming in at constant rate. The same linux application is listening to the packets as well. The packet capture runs in a separate thread and `pcap_loop` calls a function to process incoming traffic. – NanoNi Jan 20 '20 at 18:47

0 Answers0