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, <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 <bst@pengutronix.de>
pull/65/head
Bastian Stender 2018-01-19 15:30:29 +01:00
parent 6133ac94f0
commit cf039f14fb
1 changed files with 3 additions and 0 deletions

3
jacd.c
View File

@ -22,6 +22,7 @@
#include <error.h> #include <error.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <net/if.h>
#include <linux/can.h> #include <linux/can.h>
#include <linux/can/j1939.h> #include <linux/can/j1939.h>
@ -196,6 +197,7 @@ static int open_socket(const char *device, uint64_t name)
.addr = J1939_IDLE_ADDR, .addr = J1939_IDLE_ADDR,
.pgn = 0x0ee00, .pgn = 0x0ee00,
}, },
.can_ifindex = if_nametoindex(s.intf),
}; };
if (s.verbose) if (s.verbose)
@ -260,6 +262,7 @@ static int claim_address(int sock, uint64_t name, int sa)
.addr = sa, .addr = sa,
.pgn = 0x0ee00, .pgn = 0x0ee00,
}, },
.can_ifindex = if_nametoindex(s.intf),
}; };
if (s.verbose) if (s.verbose)