encyclopegia.org

SocketCAN

SocketCAN is a set of open source CAN drivers and a networking stack contributed by Volkswagen Research to the Linux kernel. SocketCAN was formerly known as Low Level CAN Framework (LLCF). Traditional CAN drivers for Linux are based on the model of character devices. Typically they only allow sending to and receiving from the CAN controller. Conventional implementations of this class of device driver only allow a single process to access the device, which means that all other processes are blocked in the meantime. In addition, these drivers typically all differ slightly in the interface presented to the application, stifling portability. The SocketCAN concept on the other hand uses the model of network devices, which allows multiple applications to access one CAN device simultaneously. Also, a single application is able to access multiple CAN networks in parallel. The SocketCAN concept extends the Berkeley sockets API in Linux by introducing a new protocol family, PF_CAN, that coexists with other protocol families, such as PF_INET for the Internet Protocol. The communication with the CAN bus is therefore done analogously to the use of the Internet Protocol via sockets. Fundamental components of SocketCAN are the network device drivers for different CAN controllers and the implementation of the CAN protocol family.…

SocketCAN is a set of open source CAN drivers and a networking stack contributed by Volkswagen Research to the Linux kernel. SocketCAN was formerly known as Low Level CAN Framework (LLCF). Traditional CAN drivers for Linux are based on the model of character devices. Typically they only allow sending to and receiving from the CAN controller. Conventional implementations of this class of device driver only allow a single process to access the device, which means that all other processes are blocked in the meantime. In addition, these drivers typically all differ slightly in the interface presented to the application, stifling portability. The SocketCAN concept on the other hand uses the model of network devices, which allows multiple applications to access one CAN device simultaneously. Also, a single application is able to access multiple CAN networks in parallel. The SocketCAN concept extends the Berkeley sockets API in Linux by introducing a new protocol family, PF_CAN, that coexists with other protocol families, such as PF_INET for the Internet Protocol. The communication with the CAN bus is therefore done analogously to the use of the Internet Protocol via sockets. Fundamental components of SocketCAN are the network device drivers for different CAN controllers and the implementation of the CAN protocol family. The protocol family, PF_CAN, provides the structures to enable different protocols on the bus: Raw sockets for direct CAN communication and transport protocols for point-to-point connections. Moreover the broadcast manager which is part of the CAN protocol family provides functions e.g. for sending CAN messages periodically or realize complex message filters. Since Linux kernel Version 5.10 the protocol family also includes an ISO-TP implementation, CAN_ISOTP. Patches for CAN were added in the 2.6.25 Linux kernel. Meanwhile some controller drivers were added and work is going on to add drivers for a variety of controllers. $ modprobe can_dev $ modprobe can $ modprobe can_raw $ sudo ip link set can0 type can bitrate 500000 $ sudo ip link set up can0 There is also a virtual CAN driver for testing purposes which can be loaded and created in Linux with the commands below. $ modprobe can $ modprobe can_raw $ modprobe vcan $ sudo ip link add dev vcan0 type vcan $ sudo ip link set up vcan0 $ ip link show vcan0 3: vcan0: mtu 16 qdisc noqueue state UNKNOWN link/can The following code snippet is a working example of the SocketCAN API, that sends a packet using the raw interface. It is based on the notes documented in the Linux Kernel. include include include include include include include include include include int main(void) { int s; int nbytes; struct sockaddr_can addr; struct can_frame frame; struct ifreq ifr; const char* ifname = "vcan0"; if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) == -1) { perror("Error while opening socket"); return -1; } strcpy(ifr.ifr_name, ifname); ioctl(s, SIOCGIFINDEX, &ifr); addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; printf("%s at index %d\n", ifname, ifr.ifr_ifindex); if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) == -1) { perror("Error in socket bind"); return -2; } frame.can_id = 0x123; frame.can_dlc = 2; frame.data[0] = 0x11; frame.data[1] = 0x22; nbytes = write(s, &frame, sizeof(struct can_frame)); printf("Wrote %d bytes\n", nbytes); return 0; } The packet can be analyzed on the vcan0 interface using the candump utility which is part of the SocketCAN can-utils package. user@server:~/can-utils $ ./candump vcan0 vcan0 123 [2] 11 22 ==References== ==External links== SocketCAN / Linux CAN project site Userspace Tools for SocketCAN Userspace Library for SocketCAN Linux CAN documentation Linux CAN mailing list Linux CAN mail archive (gmane) Linux CAN mail archive (marc)

References

No reference rows published for this article.

Cite this article

MLA

"SocketCAN." encyclopegia.org, 2025, https://encyclopegia.org/wiki/socketcan. Accessed 24 November 2026.

Chicago

"SocketCAN." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/socketcan.

APA

encyclopegia.org. (2025). SocketCAN. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/socketcan

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Lavon Volski

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1320540622 · 0.5 · snapshot enwiki-001320540622

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.