From: Oliver Hartkopp Date: Mon, 18 Jun 2007 19:59:20 +0000 (+0000) Subject: Disabled obsolte receive filter. Added error checking for SIOCGIFINDEX. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/sojka/can-utils.git/commitdiff_plain/e49fb4c1346e1ca976e1577675f05bae2988c208 Disabled obsolte receive filter. Added error checking for SIOCGIFINDEX. --- diff --git a/cansend.c b/cansend.c index dd9d73e..623eb86 100644 --- a/cansend.c +++ b/cansend.c @@ -92,12 +92,21 @@ int main(int argc, char **argv) return 1; } - strcpy(ifr.ifr_name, argv[1]); - ioctl(s, SIOCGIFINDEX, &ifr); - addr.can_family = AF_CAN; + + strcpy(ifr.ifr_name, argv[1]); + if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { + perror("SIOCGIFINDEX"); + return 1; + } addr.can_ifindex = ifr.ifr_ifindex; + /* disable default receive filter on this RAW socket */ + /* This is obsolete as we do not read from the socket at all, but for */ + /* this reason we can remove the receive list in the Kernel to save a */ + /* little (really a very little!) CPU usage. */ + setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0); + if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("bind"); return 1;