After sending the message, I am waiting for MSG_CONFIRM.
How to correctly receive MSG_FLAGS?
I don't understand why temp
is always equal -1
.
struct msghdr msg;
struct sockaddr_can addr;
struct can_frame frame;
struct ifreq ifr
setsockopt(s, SOL_CAN_RAW, CAN_RAW_ERR_FILTER, &(int){ 1 }, sizeof(int));
setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &(int){ 1 }, sizeof(int));
setsockopt(s, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, &(int){ 1 }, sizeof(int));
strcpy(ifr.ifr_name, ifname);
ioctl(s, SIOCGIFINDEX, &ifr);
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
write(s, &frame, sizeof(struct can_frame));
temp = recvmsg(s, &msg, MSG_CONFIRM);
printf("%02X \n", temp);
printf("%02X \n", errno);
if (msg.msg_flags==MSG_CONFIRM){
printf("MSG_CONFIRM"); }
MSG_CONFIRM
is set byrecvmsg()
inmsg.msg_flags
if the CAN frame is a send confirmation, but you cannot pass the flag torecvmsg()
.Unfortunately this makes handling send confirmations a bit complex. After
write()
, you may first receive CAN frames from other nodes, which you have to handle or buffer, before you receive theMSG_CONFIRM
frame corresponding towrite()
. You cannot userecvmsg()
to just wait for the confirmation and keep the other frames in the kernel buffer,