mirror of
https://github.com/linux-can/can-utils.git
synced 2026-09-22 08:06:34 +02:00
can-utils: check for return values of if_nametoindex()
if_nametoindex() returns zero and a specific errno in the case the network interface does not exist. The missing check leads to the use of the 'any' CAN device but leaves the user alone as the user gets no error message. Reported-by: Lothar Rubusch <lotophagon@protonmail.com> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
@@ -189,6 +189,10 @@ int main(int argc, char **argv)
|
||||
|
||||
addr.can_family = AF_CAN;
|
||||
addr.can_ifindex = if_nametoindex(argv[optind]);
|
||||
if (!addr.can_ifindex) {
|
||||
perror("if_nametoindex");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
perror("bind");
|
||||
|
||||
Reference in New Issue
Block a user