Skip to content

Commit

Permalink
initialize struct ifreq ifr #19
Browse files Browse the repository at this point in the history
  • Loading branch information
driftregion committed Oct 21, 2023
1 parent ba10d9c commit fb40149
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions iso14229.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,27 +220,27 @@ static ssize_t tp_send(UDSTpHandle_t *hdl, const void *buf, size_t count, UDSTpA
#if UDS_TP == UDS_TP_ISOTP_SOCKET
static int LinuxSockBind(const char *if_name, uint32_t rxid, uint32_t txid) {
int fd = 0;
if ((fd = socket(AF_CAN, SOCK_DGRAM | SOCK_NONBLOCK, CAN_ISOTP)) < 0) {
perror("Socket");
return -1;
}

struct ifreq ifr = {0};
struct sockaddr_can addr = {0};
struct can_isotp_fc_options fcopts = {
.bs = 0x10,
.stmin = 3,
.wftmax = 0,
};

if ((fd = socket(AF_CAN, SOCK_DGRAM | SOCK_NONBLOCK, CAN_ISOTP)) < 0) {
perror("Socket");
return -1;
}

if (setsockopt(fd, SOL_CAN_ISOTP, CAN_ISOTP_RECV_FC, &fcopts, sizeof(fcopts)) < 0) {
perror("setsockopt");
return -1;
}

struct ifreq ifr;
strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name));
strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name) - 1);
ioctl(fd, SIOCGIFINDEX, &ifr);

struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_family = AF_CAN;
addr.can_addr.tp.rx_id = rxid;
addr.can_addr.tp.tx_id = txid;
Expand Down

0 comments on commit fb40149

Please sign in to comment.