0

I am attempting to read/write to multiple CAN Bus sockets on a device out of the same thread. However, I am only getting RX messages when I write to the boards that are supposed to be on can1 when I write to can0's file descriptor.

I am thinking it is due to how the interface indices are bound. The ifr_ifindex is 0 for both sockets I have opened.

ioctl(s, SIOCGIFINDEX, &ifr);

addr.can_ifindex = ifr.ifr_ifindex;

bind(s, (struct sockaddr*)&addr, sizeof(addr));

What is the proper procedure for handling multiple CAN sockets when determining or setting the interface index using ioctl?

CapnCook
  • 13
  • 1
  • 3
  • You may want to use `wireshark` to see what's coming in. I've used `SIOCGIFINDEX`, but only with `PF_PACKET`. See my answer: https://stackoverflow.com/questions/54056426/af-packet-and-ethernet/54057044#54057044 It may or may not be applicable. I think we may need to see more of your code. In particular, how do you enumerate the CAN devices? How does each CAN device get a separate IP address? How are you dealing with the CAN bus ids? – Craig Estey Jan 06 '21 at 20:55
  • I simply run something similar to the examples from this link for setting up the sockets for each CAN bus interface. https://www.kernel.org/doc/html/latest/networking/can.html passing "can0" and "can1" for the ifr_name. I believe I found the problem, outdated and confusing documentation. can1 in the documentation refers to can1 on the device and can2 in the documentation refers to can0 on the device. – CapnCook Jan 07 '21 at 20:29

0 Answers0