Search code examples
linuxcan-bussocketcan

vcan0 interface linux communication


Linux is supporting virtual can interface. it was enabled by:

modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ifconfig vcan0 up

While using cam-utils such as camsniffer and cansend

cansend vcan0 321#1212
cansniffer vcan0

I could able to see can packets; but only within same host. I tried Ubuntu VirtualBox machine. Both guest and host OS are interconnected using host-only adapter vboxnet0.

Also tried SocketCAN socket(PF_CAN, SOCK_RAW, CAN_RAW) but not able to receive on other machine(works within same machine) While trying with broadcast manager socket(PF_CAN, SOCK_DGRAM, CAN_BCM) on executing stderr says `operation not supported

Simply, could one send and receive CAN packets between Linux hosts? Doesn't matter its Virtual Machine (vboxnet0) or physically connected (Ethernet).

Note: I used Ubuntu 16.04 and 12.04 as Host and Guest OS respectively.


Solution

  • CAN uses its own physial bus. The vcan devices are designed for testing software that communicates over the bus without requiring an actual physical connection, they're not actually supplied by the hypervisor, but are a part of SocketCAN.

    By the looks of it, you're attempting to establish a Virtual CAN bus in Virtualbox, connecting multiple machines together as though they all had CAN controllers and were connected to a physical bus. I've looked, but it appears that such functionality doesn't exist, and beyond writing an extension for VirtualBox, is probably not likely to.

    Is there a specific reason you're looking to use CAN? Trying to pull data from an ECU or communicate with embedded hardware that has a CAN controller? As far as desktop pc communication, ethernet is much more convenient, faster,a nd well supported.