The raw CAN bus

In a Linux-based system, we can use the SocketCAN implementation to manage these devices and then exchange data between them. It uses the Berkeley socket API and the Linux network stack (and raw sockets) to implement CAN device drivers as network interfaces to allow programmers familiar with network programming to easily learn how to use CAN sockets.

Note

See the Documentation/networking/can.txt file in the kernel's repository for more information.

Here is a simplified example in C language regarding how to open a SocketCAN socket:

int s; char *ifname; struct sockaddr_can addr; struct can_frame frame; struct ifreq ifr; int ret; /* Open the PF_CAN socket */ s = socket(PF_CAN, SOCK_RAW, CAN_RAW); if (s < 0) { perror("Error while opening ...

Get GNU/Linux Rapid Embedded Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.