Merge pull request #244 from marckleinebudde/canfdtest-check-device

canfdtest: bail out if trying to use non-existing CAN interface
pull/243/head
Marc Kleine-Budde 2020-09-29 09:14:29 +02:00 committed by GitHub
commit 485d813545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -422,6 +422,11 @@ int main(int argc, char *argv[])
addr.can_family = family;
addr.can_ifindex = if_nametoindex(intf_name);
if (!addr.can_ifindex) {
perror("if_nametoindex");
close(sockfd);
return 1;
}
if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("bind");