CAN(4)
π CAN(4) β CAN Protocol π
okay bestie, welcome to the Kernel Interfaces Manual page for CAN(4) β yes, the CAN Protocol. we're gonna get you comfy with raw CAN sockets, and no cap, it's giving network layer realness. π
β¨ NAME β¨
CAN β CAN Protocol. that's the name, that's the vibe, periodt.
β¨ SYNOPSIS β¨
to open a raw CAN socket you literally do this:
#include <sys/socket.h>
#include <netcan/can.h>
int
socket(AF_CAN, SOCK_RAW, CAN_RAW);
π DESCRIPTION π
CAN is the network layer protocol used on top of CAN bus networks. at this time only the SOCK_RAW socket type is supported β that's the only flavor on the menu rn. this protocol layer is intended to be compatible with the Linux SocketCAN implementation. iykyk. π¦
π ADDRESSING π
a CAN frame is made of a 11 bits (standard frame format) or 29 bits (extended frame format) identifier, followed by up to 8 data bytes. the interpretation of the identifier is application-dependent β the CAN standard itself doesn't define an addressing. so yeah, it's a choose-your-own-adventure situation, not a built-in address book. π
the CAN layer uses a 32bits identifier. the 3 upper bits are used as control flags. the extended frame format is selected by setting the CAN_EFF_FLAG control bit. slay.
the socket address is defined as:
struct sockaddr_can {
u_int8_t can_len;
sa_family_t can_family;
int can_ifindex;
union {
/* transport protocol class address information */
struct { canid_t rx_id, tx_id; } tp;
/* reserved for future CAN protocols address information */
} can_addr;
};
for CAN raw sockets, the 32bits identifier is part of the message data. the can_addr field of the sockaddr structure is not used. so don't go looking for it there, bestie. π
π¦ MESSAGE π¦
raw CAN sockets use fixed-length messages defined as follow:
struct can_frame {
canid_t can_id; /* ID + EFF/RTR/ERR flags */
uint8_t can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
uint8_t __pad;
uint8_t __res0;
uint8_t __res1;
uint8_t data[CAN_MAX_DLEN] __aligned(8);
};
the lower 11 bits (for standard frames) or 29 bits (for extended frames) are used as the on-wire identifier. the CAN_EFF_FLAG bit is set in can_id for extended frames. the CAN_RTR_FLAG bit is set in can_id for remote transmission request frames. iconic flag behavior, honestly. β
π SEE ALSO π
socket(2)canloop(4)netintro(4)canconfig(8)/usr/include/netcan/can.h- SocketCAN - Wikipedia: https://en.wikipedia.org/wiki/SocketCAN
- Readme file for the Controller Area Network Protocol Family: https://www.kernel.org/doc/Documentation/networking/can.txt
β HISTORY β
the CAN protocol appeared in NetBSD 8.0. a whole era. π
π BUGS π
CANFD and error frames are not implemented. so if you were looking for those, not today, bestie. π
mwah π this page is from Debian, dated May 18, 2017, and it's the CAN(4) manual β take care, bestie! π«Ά
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2017 Manuel Bouyer
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms