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?