Supplying the ifname correctly and removing the now obsolete check of the length of the ifname. Code taken from cansend.c
parent
5aa72c5e9e
commit
171050e2a4
16
cangen.c
16
cangen.c
|
|
@ -596,24 +596,24 @@ int main(int argc, char **argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(argv[optind]) >= IFNAMSIZ) {
|
|
||||||
printf("Name of CAN device '%s' is too long!\n\n", argv[optind]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
perror("socket");
|
perror("socket");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr.can_family = AF_CAN;
|
strncpy(ifr.ifr_name, argv[optind], IFNAMSIZ - 1);
|
||||||
addr.can_ifindex = if_nametoindex(argv[optind]);
|
ifr.ifr_name[IFNAMSIZ - 1] = '\0';
|
||||||
if (!addr.can_ifindex) {
|
ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name);
|
||||||
|
if (!ifr.ifr_ifindex) {
|
||||||
perror("if_nametoindex");
|
perror("if_nametoindex");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.can_family = AF_CAN;
|
||||||
|
addr.can_ifindex = ifr.ifr_ifindex;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* disable default receive filter on this RAW socket
|
* disable default receive filter on this RAW socket
|
||||||
* This is obsolete as we do not read from the socket at all, but for
|
* This is obsolete as we do not read from the socket at all, but for
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue