I am trying to determine the buffer usage for my CAN interface on linux.
At the level of the interface, I know of two ways to get statistics:
- From
/proc/net/can/stats
ip -details -statistics link show can0
The first one gives me the number of transmitted/received frames. The second one gives the number of transmitted/received bytes and packets, as well as the number of dropped packets and overruns. Unfortunately neither of these shows the current number of frames/bytes in the buffer.
Note: I know that we can set the txqueuelen (ifconfig can0 txqueuelen <len>
), and setting it too low triggers a write: No buffer space available
when it fills up. However I still can't get the number of frames in the queue at any time.
At the socket level (the socket was opened like this: socket(PF_CAN, SOCK_RAW, CAN_RAW)
), I've tried to query the input/output queue size (as can be done on an internet socket):
int queued_in = -1;
ioctl(sockfd, SIOCINQ, &queued_in);
int queued_out = -1;
ioctl(sockfd, SIOCOUTQ, &queued_out);
But the value remains -1 for both variables so it wasn't written to. What am I doing wrong here?