CAN(4) Device Drivers Manual CAN(4)

CAN
CAN Protocol

#include <sys/socket.h>
#include <netcan/can.h>

int
socket(AF_CAN, SOCK_RAW, CAN_RAW);

CAN is the network layer protocol used on top of CAN bus networks. At this time only the SOCK_RAW socket type is supported. This protocol layer is intended to be compatible with the Linux SocketCAN implementation.

A CAN frame consists 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.

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.

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.

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.

socket(2), canloop(4), netintro(4), canconfig(8), /usr/include/netcan/can.h

SocketCAN - Wikipedia Readme file for the Controller Area Network Protocol Family

The CAN protocol appeared in NetBSD 8.0.

CANFD and error frames are not implemented.
May 18, 2017 NetBSD 9.4