From cf039f14fb4083c35937a191f800198eefd0b5b4 Mon Sep 17 00:00:00 2001 From: Bastian Stender Date: Fri, 19 Jan 2018 15:30:29 +0100 Subject: [PATCH] jacd: provide interface index while opening socket and address claiming This is a direct consequence of not allowing bind to any device ("3cb6a1204598 j1939: socket: bind() cleanups"), i.e. can_ifindex == 0. This means before this change jacd would receive from any interface that was opened by another program. Without this patch jacd fails with: acd: bind(): No such device A more verbose call shows the missing interface: $ jacd -v 1122334455667788 jacd: ready for can0:1122334455667788 - socket(PF_CAN, SOCK_DGRAM, CAN_J1939); - setsockopt(, SOL_SOCKET, SO_BINDTODEVICE, can0, 4); - setsockopt(, SOL_CAN_J1939, SO_J1939_FILTER, , 84); - setsockopt(, SOL_CAN_J1939, SO_J1939_RECV_OWN, 1, 4); - bind(, :fe,0ee00,1122334455667788, 24); jacd: bind(): No such device Signed-off-by: Bastian Stender --- jacd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jacd.c b/jacd.c index 416928d..bac4060 100644 --- a/jacd.c +++ b/jacd.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -196,6 +197,7 @@ static int open_socket(const char *device, uint64_t name) .addr = J1939_IDLE_ADDR, .pgn = 0x0ee00, }, + .can_ifindex = if_nametoindex(s.intf), }; if (s.verbose) @@ -260,6 +262,7 @@ static int claim_address(int sock, uint64_t name, int sa) .addr = sa, .pgn = 0x0ee00, }, + .can_ifindex = if_nametoindex(s.intf), }; if (s.verbose)