I saw a similar question but it didn't answer mine.
I'm using canbus
communication in my program with a mask
, here is an example, taken from can-utils:
struct can_filter {
canid_t can_id;
canid_t can_mask;
};
struct can_filter *rfilter;
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FILTER, rfilter, numfilter * sizeof(struct can_filter));
/* try to switch the socket into CAN FD mode */
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
bind(s[i], (struct sockaddr *) &addr, sizeof(addr))
. . .
int ret = select(s[currmax - 1] + 1, &rdfs, NULL, NULL, timeout);
int nbytes = recvmsg(s[i], &msg, 0);
In this example, I set the mask
and than bind
so every time I will receive
a message from the socket
, it will be with the same mask
.
Is it possible to change the mask
after the bind
and before receive
?
Example:
/* try to switch the socket into CAN FD mode */
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
bind(s[i], (struct sockaddr *) &addr, sizeof(addr))
. . .
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FILTER, rfilter, numfilter * sizeof(struct can_filter));
int ret = select(s[currmax - 1] + 1, &rdfs, NULL, NULL, timeout);
int nbytes = recvmsg(s[i], &msg, 0);