#include <sys/mman.h>
#include <arpa/inet.h>
+#ifndef SO_BUSY_POLL
+#define SO_BUSY_POLL 46
+#endif
+
#define FRAME_SIZE 256
#define BLOCK_SIZE 4096
#define BLOCK_NR 2
enum { IN_READ, IN_RECVMMSG, IN_MMAP, IN_MMAPBUSY } in_method = IN_READ;
enum { WRITE, OUT_MMAP } out_method = WRITE;
bool quiet = false;
+int busy_poll_us = 0;
enum in2out {
STORE_ONLY,
s = CHECK(socket(PF_CAN, SOCK_RAW, CAN_RAW));
+ if (busy_poll_us) {
+ CHECK(setsockopt(s, SOL_SOCKET, SO_BUSY_POLL,
+ &busy_poll_us, sizeof(busy_poll_us)));
+ }
+
strncpy(ifr.ifr_name, devin, sizeof(ifr.ifr_name));
if (-1 == ioctl(s, SIOCGIFINDEX, &ifr)) {
perror(devin);
s = CHECK(socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)));
+ if (busy_poll_us) {
+ CHECK(setsockopt(s, SOL_SOCKET, SO_BUSY_POLL,
+ &busy_poll_us, sizeof(busy_poll_us)));
+ }
+
int val = TPACKET_V2;
CHECK(setsockopt(s, SOL_PACKET, PACKET_VERSION, &val, sizeof(val)));
socklen_t len = sizeof(ctx->hdrlen);
{
int opt;
- while ((opt = getopt(argc, argv, "qr:t:")) != -1) {
+ while ((opt = getopt(argc, argv, "b:qr:t:")) != -1) {
switch (opt) {
+ case 'b':
+ busy_poll_us = atoi(optarg);
+ break;
case 'q':
quiet = true;
break;