+ if (canfd) {
+ int enable_canfd = 1;
+
+ /* check if the frame fits into the CAN netdevice */
+ if (ioctl(s, SIOCGIFMTU, &ifr) < 0) {
+ perror("SIOCGIFMTU");
+ return 1;
+ }
+
+ if (ifr.ifr_mtu != CANFD_MTU) {
+ printf("CAN interface ist not CAN FD capable - sorry.\n");
+ return 1;
+ }
+
+ /* interface is ok - try to switch the socket into CAN FD mode */
+ if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &enable_canfd, sizeof(enable_canfd))){
+ printf("error when enabling CAN FD support\n");
+ return 1;
+ }
+
+ /* ensure discrete CAN FD length values 0..8, 12, 16, 20, 24, 32, 64 */
+ frame.len = can_dlc2len(can_len2dlc(frame.len));
+ } else {
+ /* sanitize CAN 2.0 frame length */
+ if (frame.len > 8)
+ frame.len = 8;
+ }
+