+ {
+ int idx;
+
+ for (idx = 0; idx < CAN_TX_COUNT; idx++) {
+ struct ert_can_tx_config *cfg = &can_config.tx_config[idx];
+ const char *ifname = can_config.channel_ifname[cfg->channel];
+ int fd;
+ struct sockaddr_can addr;
+ struct ifreq ifr;
+
+ fd = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+ if (fd == -1) {
+ printf("CAN socket create error.\n");
+ exit(1);
+ }
+ if(fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
+ printf("CAN socket set O_NONBLOCK error.\n");
+ exit(1);
+ }
+ memset(&addr, 0, sizeof(addr));
+ addr.can_family = AF_CAN;
+ strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
+ printf("CAN socket ioctl SIOCGIFINDEX error.\n");
+ exit(1);
+ }
+ addr.can_ifindex = ifr.ifr_ifindex;
+
+ /* disable default receive filter on this RAW socket */
+ setsockopt(fd, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
+
+ if (bind(fd, (struct sockaddr *)(void*)&addr, sizeof(addr)) < 0) {
+ printf("CAN socket bind error.\n");
+ exit(1);
+ }
+ printf("rx opening %s\n", ifname);
+ can_tx_handles[idx] = fd;
+ }
+
+ for (idx = 0; idx < CAN_RX_COUNT; idx++) {
+ struct ert_can_rx_config *cfg = &can_config.rx_config[idx];
+ const char *ifname = can_config.channel_ifname[cfg->channel];
+ int fd;
+ struct sockaddr_can addr;
+ struct ifreq ifr;
+ struct can_filter sc_filter;
+
+ fd = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+ if (fd == -1) {
+ printf("CAN socket create error.\n");
+ exit(1);
+ }
+ if(fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
+ printf("CAN socket set O_NONBLOCK error.\n");
+ exit(1);
+ }
+ memset(&addr, 0, sizeof(addr));
+ addr.can_family = AF_CAN;
+ strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
+ printf("CAN socket ioctl SIOCGIFINDEX error.\n");
+ exit(1);
+ }
+ addr.can_ifindex = ifr.ifr_ifindex;
+
+ /* disable default receive filter on this RAW socket */
+ setsockopt(fd, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);