Merge pull request #250 from neheb/clng

clang-tidy fixes
pull/251/head
Marc Kleine-Budde 2020-10-13 08:44:49 +02:00 committed by GitHub
commit 7759b00c58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 478 additions and 483 deletions

View File

@ -42,18 +42,18 @@
*
*/
#include <libgen.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <libgen.h>
#include <unistd.h>
#include <stdlib.h>
#include <locale.h>
#include <net/if.h>
#include <linux/can.h>
#include <linux/can/error.h>
#include <net/if.h>
#include "lib.h"
@ -224,7 +224,7 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
int interface;
static struct timeval tv; /* current frame timestamp */
static struct timeval read_tv; /* frame timestamp from ASC file */
struct canfd_frame cf;
struct canfd_frame cf = {};
unsigned char brs, esi, ctmp;
unsigned int flags;
int dlc, dlen = 0;
@ -241,8 +241,6 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
00 00 00 00 00 00 00 00 00 00 00 00 00 00 59 c0 \
100000 214 223040 80000000 46500250 460a0250 20011736 20010205 */
memset(&cf, 0, sizeof(cf));
/* check for valid line without symbolic name */
if (sscanf(buf, "%lu.%lu %*s %d %2s %s %hhx %hhx %x %d ",
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
@ -335,7 +333,6 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace);
prframe(outfile, &tv, interface, &cf, dlen, extra_info);
fflush(outfile);
return;
/* No support for really strange CANFD ErrorFrames format m( */
}
@ -359,8 +356,7 @@ int get_date(struct timeval *tv, char *date) {
before parsing the real year value (hack) */
if (!strptime(date, "%B %d %I:%M:%S.%Y %p %Y", &tms))
return 1;
else
sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs);
sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs);
}
} else {
@ -377,11 +373,10 @@ int get_date(struct timeval *tv, char *date) {
before parsing the real year value (hack) */
if (!strptime(date, "%B %d %H:%M:%S.%Y %Y", &tms))
return 1;
else
sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs);
sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs);
}
}
//printf("h %d m %d s %d ms %03d d %d m %d y %d\n",
//tms.tm_hour, tms.tm_min, tms.tm_sec, msecs,
//tms.tm_mday, tms.tm_mon+1, tms.tm_year+1900);

View File

@ -108,21 +108,21 @@
*
*/
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <linux/can.h>
#include <linux/can/bcm.h>

View File

@ -18,16 +18,16 @@
#include <errno.h>
#include <getopt.h>
#include <libgen.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <string.h>
#include <linux/types.h>
#include <linux/can/netlink.h>
#include <linux/types.h>
/* imported from kernel */
@ -691,7 +691,8 @@ int main(int argc, char *argv[])
}
for (i = 0; i < ARRAY_SIZE(can_calc_consts); i++) {
if (name && strcmp(can_calc_consts[i].bittiming_const.name, name))
if (name &&
strcmp(can_calc_consts[i].bittiming_const.name, name) != 0)
continue;
found = true;

View File

@ -42,21 +42,21 @@
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <libgen.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <net/if.h>
#include <linux/can.h>
#include <linux/can/raw.h>

View File

@ -42,23 +42,23 @@
*
*/
#include <ctype.h>
#include <errno.h>
#include <libgen.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <libgen.h>
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <net/if.h>
#include <linux/can.h>
#include <linux/can/raw.h>
@ -417,7 +417,7 @@ int main(int argc, char **argv)
printf("using interface name '%s'.\n", ifr.ifr_name);
#endif
if (strcmp(ANYDEV, ifr.ifr_name)) {
if (strcmp(ANYDEV, ifr.ifr_name) != 0) {
if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) {
perror("SIOCGIFINDEX");
exit(1);

View File

@ -17,24 +17,24 @@
* Send feedback to <linux-can@vger.kernel.org>
*/
#include <errno.h>
#include <getopt.h>
#include <libgen.h>
#include <limits.h>
#include <sched.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <libgen.h>
#include <getopt.h>
#include <time.h>
#include <sched.h>
#include <limits.h>
#include <errno.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <linux/can.h>
#include <linux/can/raw.h>
@ -181,20 +181,18 @@ static int send_frame(struct can_frame *frame)
while ((ret = send(sockfd, frame, sizeof(*frame), 0))
!= sizeof(*frame)) {
if (ret < 0) {
if (errno != ENOBUFS) {
perror("send failed");
return -1;
} else {
if (verbose) {
printf("N");
fflush(stdout);
}
}
} else {
if (ret >= 0) {
fprintf(stderr, "send returned %d", ret);
return -1;
}
if (errno != ENOBUFS) {
perror("send failed");
return -1;
}
if (verbose) {
printf("N");
fflush(stdout);
}
}
return 0;
}
@ -332,19 +330,19 @@ static int can_echo_gen(void)
if (recv_tx_pos == inflight_count)
recv_tx_pos = 0;
continue;
} else {
if (!recv_tx[recv_rx_pos]) {
printf("RX before TX!\n");
print_frame(&rx_frame, 0);
running = 0;
}
/* compare with expected */
compare_frame(&tx_frames[recv_rx_pos], &rx_frame, 1);
recv_rx_pos++;
if (recv_rx_pos == inflight_count)
recv_rx_pos = 0;
}
if (!recv_tx[recv_rx_pos]) {
printf("RX before TX!\n");
print_frame(&rx_frame, 0);
running = 0;
}
/* compare with expected */
compare_frame(&tx_frames[recv_rx_pos], &rx_frame, 1);
recv_rx_pos++;
if (recv_rx_pos == inflight_count)
recv_rx_pos = 0;
loops++;
if (test_loops && loops >= test_loops)
break;

View File

@ -45,12 +45,12 @@
*/
#include "canframelen.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
/**
* Functions and types for CRC checks.

View File

@ -42,28 +42,28 @@
*
*/
#include <ctype.h>
#include <errno.h>
#include <libgen.h>
#include <poll.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <poll.h>
#include <ctype.h>
#include <libgen.h>
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <net/if.h>
#include "lib.h"
#include <linux/can.h>
#include <linux/can/raw.h>
#include "lib.h"
#define DEFAULT_GAP 200 /* ms */
#define DEFAULT_BURST_COUNT 1
@ -297,7 +297,7 @@ int main(int argc, char **argv)
}
ts.tv_sec = gap / 1000;
ts.tv_nsec = (long)(((long long)(gap * 1000000)) % 1000000000ll);
ts.tv_nsec = (long)(((long long)(gap * 1000000)) % 1000000000LL);
/* recognize obviously missing commandline option */
if (id_mode == MODE_FIX && frame.can_id > 0x7FF && !extended) {
@ -468,8 +468,8 @@ resend:
if (poll(&fds, 1, polltimeout) < 0) {
perror("poll");
return 1;
} else
goto resend;
}
goto resend;
} else
enobufs_count++;

22
cangw.c
View File

@ -42,17 +42,17 @@
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <net/if.h>
#include <libgen.h>
#include <linux/can/gw.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/can/gw.h>
#include <net/if.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
enum {
UNSPEC,
@ -706,8 +706,8 @@ int main(int argc, char **argv)
struct can_filter filter;
struct sockaddr_nl nladdr;
struct cgw_csum_xor cs_xor;
struct cgw_csum_crc8 cs_crc8;
struct cgw_csum_xor cs_xor = {};
struct cgw_csum_crc8 cs_crc8 = {};
char crc8tab[513] = {0};
struct modattr modmsg[CGW_MOD_FUNCS];
@ -717,8 +717,6 @@ int main(int argc, char **argv)
int i;
memset(&req, 0, sizeof(req));
memset(&cs_xor, 0, sizeof(cs_xor));
memset(&cs_crc8, 0, sizeof(cs_crc8));
while ((opt = getopt(argc, argv, "ADFLs:d:Xteiu:l:f:c:p:x:m:M:?")) != -1) {
switch (opt) {

View File

@ -42,29 +42,29 @@
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <libgen.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <errno.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <linux/sockios.h>
#include <signal.h>
#include <errno.h>
#include "lib.h"
@ -300,15 +300,14 @@ int main(int argc, char **argv)
//printf("accepted\n");
if (!fork())
break;
else
close(accsocket);
close(accsocket);
}
else if (errno != EINTR) {
perror("accept");
exit(1);
}
}
for (i=0; i<currmax; i++) {
#ifdef DEBUG
@ -357,15 +356,14 @@ int main(int argc, char **argv)
addr.can_family = AF_CAN;
if (strcmp(ANYDEV, argv[optind+i])) {
if (strcmp(ANYDEV, argv[optind + i]) != 0) {
strcpy(ifr.ifr_name, argv[optind+i]);
if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) {
perror("SIOCGIFINDEX");
exit(1);
}
addr.can_ifindex = ifr.ifr_ifindex;
}
else
} else
addr.can_ifindex = 0; /* any can interface */
if (bind(s[i], (struct sockaddr *)&addr, sizeof(addr)) < 0) {

View File

@ -42,19 +42,19 @@
*
*/
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <libgen.h>
#include <stdlib.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include "lib.h"
@ -215,7 +215,7 @@ int add_assignment(char *mode, int socket, char *txname, char *rxname,
}
strcpy(asgn[i].rxif, rxname);
if (strcmp(txname, "stdout")) {
if (strcmp(txname, "stdout") != 0) {
strcpy(ifr.ifr_name, txname);
if (ioctl(socket, SIOCGIFINDEX, &ifr) < 0) {
perror("SIOCGIFINDEX");

View File

@ -42,25 +42,25 @@
*
*/
#include <ctype.h>
#include <fcntl.h>
#include <libgen.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <ctype.h>
#include <libgen.h>
#include <time.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <net/if.h>
#include <linux/can.h>
#include <linux/can/raw.h>
@ -333,7 +333,7 @@ int main(int argc, char **argv)
addr.can_family = AF_CAN;
if (strcmp(ANYDEV, argv[optind]))
if (strcmp(ANYDEV, argv[optind]) != 0)
addr.can_ifindex = if_nametoindex(argv[optind]);
else
addr.can_ifindex = 0; /* any can interface */

View File

@ -42,23 +42,23 @@
*
*/
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <libgen.h>
#include <time.h>
#include <strings.h>
#include <time.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "terminal.h"
#include <linux/can.h>
#include <linux/can/raw.h>
#include <linux/sockios.h>
#include "terminal.h"
#define NO_CAN_ID 0xFFFFFFFFU
@ -335,65 +335,66 @@ int main(int argc, char **argv)
if (nbytes < 0) {
perror("read");
return 1;
} else if (nbytes != CAN_MTU && nbytes != CANFD_MTU) {
}
if (nbytes != CAN_MTU && nbytes != CANFD_MTU) {
fprintf(stderr, "read: incomplete CAN frame %zu %d\n", sizeof(frame), nbytes);
return 1;
} else {
}
if (frame.can_id == src && ext && !extany &&
extaddr != frame.data[0])
continue;
if (frame.can_id == src && ext && !extany && extaddr != frame.data[0])
continue;
if (frame.can_id == dst && rx_ext && !rx_extany &&
rx_extaddr != frame.data[0])
continue;
if (frame.can_id == dst && rx_ext && !rx_extany && rx_extaddr != frame.data[0])
continue;
if (color)
printf("%s", (frame.can_id == src) ? FGRED : FGBLUE);
if (color)
printf("%s", (frame.can_id == src)? FGRED:FGBLUE);
if (timestamp) {
ioctl(s, SIOCGSTAMP, &tv);
if (timestamp) {
ioctl(s, SIOCGSTAMP, &tv);
switch (timestamp) {
case 'a': /* absolute with timestamp */
printf("(%lu.%06lu) ", tv.tv_sec, tv.tv_usec);
break;
case 'A': /* absolute with date */
{
struct tm tm;
char timestring[25];
tm = *localtime(&tv.tv_sec);
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
printf("(%s.%06lu) ", timestring, tv.tv_usec);
}
switch (timestamp) {
case 'a': /* absolute with timestamp */
printf("(%lu.%06lu) ", tv.tv_sec, tv.tv_usec);
break;
case 'd': /* delta */
case 'z': /* starting with zero */
{
struct timeval diff;
case 'A': /* absolute with date */
{
struct tm tm;
char timestring[25];
if (last_tv.tv_sec == 0) /* first init */
last_tv = tv;
diff.tv_sec = tv.tv_sec - last_tv.tv_sec;
diff.tv_usec = tv.tv_usec - last_tv.tv_usec;
if (diff.tv_usec < 0)
diff.tv_sec--, diff.tv_usec += 1000000;
if (diff.tv_sec < 0)
diff.tv_sec = diff.tv_usec = 0;
printf("(%lu.%06lu) ", diff.tv_sec, diff.tv_usec);
tm = *localtime(&tv.tv_sec);
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S",
&tm);
printf("(%s.%06lu) ", timestring, tv.tv_usec);
} break;
if (timestamp == 'd')
last_tv = tv; /* update for delta calculation */
}
case 'd': /* delta */
case 'z': /* starting with zero */
{
struct timeval diff;
if (last_tv.tv_sec == 0) /* first init */
last_tv = tv;
diff.tv_sec = tv.tv_sec - last_tv.tv_sec;
diff.tv_usec = tv.tv_usec - last_tv.tv_usec;
if (diff.tv_usec < 0)
diff.tv_sec--, diff.tv_usec += 1000000;
if (diff.tv_sec < 0)
diff.tv_sec = diff.tv_usec = 0;
printf("(%lu.%06lu) ", diff.tv_sec,
diff.tv_usec);
if (timestamp == 'd')
last_tv =
tv; /* update for delta calculation */
} break;
default: /* no timestamp output */
break;
default: /* no timestamp output */
break;
}
}
}
if (frame.can_id & CAN_EFF_FLAG)
printf(" %s %8X", argv[optind], frame.can_id & CAN_EFF_MASK);
@ -410,7 +411,7 @@ int main(int argc, char **argv)
datidx = 0;
n_pci = frame.data[ext];
switch (n_pci & 0xF0) {
case 0x00:
is_ff = 1;
@ -501,7 +502,6 @@ int main(int argc, char **argv)
printf("%s", ATTRESET);
printf("\n");
fflush(stdout);
}
}
close(s);

View File

@ -42,18 +42,18 @@
*
*/
#include <libgen.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <libgen.h>
#include <time.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/can.h>
#include <linux/can/raw.h>
@ -223,19 +223,21 @@ int main(int argc, char **argv)
ret = nbytes;
running = 0;
continue;
} else if (nbytes != CAN_MTU && nbytes != CANFD_MTU) {
}
if (nbytes != CAN_MTU && nbytes != CANFD_MTU) {
fprintf(stderr, "read: incomplete CAN frame %zu %d\n", sizeof(frame), nbytes);
ret = nbytes;
running = 0;
continue;
} else {
if (rcvlen) {
/* make sure to process only the detected PDU CAN frame type */
if (canfd_on && (nbytes != CANFD_MTU))
continue;
if (!canfd_on && (nbytes != CAN_MTU))
continue;
}
}
if (rcvlen) {
/* make sure to process only the detected PDU CAN frame type */
if (canfd_on && (nbytes != CANFD_MTU))
continue;
if (!canfd_on && (nbytes != CAN_MTU))
continue;
}
/* check extended address if provided */
if (ext && extaddr != frame.data[0])
@ -255,7 +257,7 @@ int main(int argc, char **argv)
} else
continue;
}
/* data content starts and index datidx */
datidx = 0;
@ -355,7 +357,7 @@ int main(int argc, char **argv)
if (rcvlen) {
if (rcvlen > fflen)
rcvlen = fflen;
percent = (rcvlen * 100 / fflen);
printf("\r %3lu%% ", percent);
@ -408,7 +410,6 @@ int main(int argc, char **argv)
fflen = rcvlen = 0;
}
fflush(stdout);
}
}
close(s);

View File

@ -42,16 +42,16 @@
*
*/
#include <libgen.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/can.h>
#include <linux/can/isotp.h>

View File

@ -42,16 +42,16 @@
*
*/
#include <libgen.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/can.h>
#include <linux/can/isotp.h>

View File

@ -57,22 +57,22 @@
*
*/
#include <errno.h>
#include <libgen.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <linux/can.h>
#include <linux/can/isotp.h>

View File

@ -42,23 +42,23 @@
*
*/
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <time.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "terminal.h"
#include <linux/can.h>
#include <linux/can/isotp.h>
#include <linux/sockios.h>
#include "terminal.h"
#define NO_CAN_ID 0xFFFFFFFFU

View File

@ -48,21 +48,21 @@
*
*/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/can.h>
#include <linux/can/isotp.h>

View File

@ -10,22 +10,22 @@
* as published by the Free Software Foundation
*/
#include <signal.h>
#include <time.h>
#include <inttypes.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>
#include <err.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <net/if.h>
#include <getopt.h>
#include <linux/can.h>
#include <linux/can/j1939.h>
#include <net/if.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
#include "libj1939.h"
@ -383,10 +383,9 @@ static inline int addr_status_mine(int sa)
{
if (sa == s.current_sa)
return '*';
else if (addr[sa].flags & F_USE)
if (addr[sa].flags & F_USE)
return '+';
else
return '-';
return '-';
}
static void dump_status(void)
@ -472,32 +471,34 @@ int main(int argc, char *argv[])
#endif
/* argument parsing */
while ((opt = getopt_long(argc, argv, optstring, long_opts, NULL)) != -1)
switch (opt) {
case 'v':
++s.verbose;
break;
case 'c':
s.cachefile = optarg;
break;
case 'r':
s.ranges = optarg;
break;
case 'a':
s.current_sa = strtoul(optarg, 0, 0);
break;
case 'p':
switch (opt) {
case 'v':
++s.verbose;
break;
case 'c':
s.cachefile = optarg;
break;
case 'r':
s.ranges = optarg;
break;
case 'a':
s.current_sa = strtoul(optarg, 0, 0);
break;
case 'p':
#ifdef _GNU_SOURCE
if (asprintf(&program_invocation_name, "%s.%s", program_invocation_short_name, optarg) < 0)
err(1, "asprintf(program invocation name)");
if (asprintf(&program_invocation_name, "%s.%s",
program_invocation_short_name, optarg) < 0)
err(1, "asprintf(program invocation name)");
#else
err(0, "compile with -D_GNU_SOURCE to use -p");
err(0, "compile with -D_GNU_SOURCE to use -p");
#endif
break;
default:
fputs(help_msg, stderr);
exit(1);
break;
}
break;
default:
fputs(help_msg, stderr);
exit(1);
break;
}
if (argv[optind])
s.name = strtoull(argv[optind++], 0, 16);
if (argv[optind])

View File

@ -8,16 +8,16 @@
#include <fcntl.h>
#include <inttypes.h>
#include <net/if.h>
#include <poll.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <poll.h>
#include <linux/errqueue.h>
#include <linux/netlink.h>
#include <linux/net_tstamp.h>
#include <linux/netlink.h>
#include <linux/socket.h>
#include "libj1939.h"
@ -212,8 +212,7 @@ static int j1939cat_extract_serr(struct j1939cat_priv *priv)
if (serr->ee_info == SCM_TSTAMP_SCHED)
return -EINTR;
else
return 0;
return 0;
case SO_EE_ORIGIN_LOCAL:
/*
* The serr->ee_origin == SO_EE_ORIGIN_LOCAL is
@ -319,11 +318,10 @@ static int j1939cat_send_loop(struct j1939cat_priv *priv, int out_fd, char *buf,
ret = poll(&fds, 1, priv->polltimeout);
if (ret == -EINTR)
continue;
else if (ret < 0)
if (ret < 0)
return -errno;
else if (!ret)
if (!ret)
return -ETIME;
if (!(fds.revents & events)) {
warn("%s: something else is wrong", __func__);
return -EIO;
@ -333,11 +331,10 @@ static int j1939cat_send_loop(struct j1939cat_priv *priv, int out_fd, char *buf,
ret = j1939cat_recv_err(priv);
if (ret == -EINTR)
continue;
else if (ret)
if (ret)
return ret;
else if ((priv->repeat - 1) == stats->tskey)
if ((priv->repeat - 1) == stats->tskey)
tx_done = true;
}
if (fds.revents & POLLOUT) {
@ -601,53 +598,56 @@ static int j1939cat_parse_args(struct j1939cat_priv *priv, int argc, char *argv[
/* argument parsing */
while ((opt = getopt(argc, argv, optstring)) != -1)
switch (opt) {
case 'i':
priv->infile = open(optarg, O_RDONLY);
if (priv->infile == -1)
err(EXIT_FAILURE, "can't open input file");
priv->todo_filesize = 1;
break;
case 's':
priv->max_transfer = strtoul(optarg, NULL, 0);
if (priv->max_transfer > J1939_MAX_ETP_PACKET_SIZE)
err(EXIT_FAILURE, "used value (%zu) is bigger then allowed maximal size: %u.\n",
priv->max_transfer, J1939_MAX_ETP_PACKET_SIZE);
break;
case 'r':
priv->todo_recv = 1;
break;
case 'p':
priv->todo_prio = strtoul(optarg, NULL, 0);
break;
case 'P':
priv->polltimeout = strtoul(optarg, NULL, 0);
break;
case 'c':
priv->todo_connect = 1;
break;
case 'R':
priv->repeat = strtoul(optarg, NULL, 0);
if (priv->repeat < 1)
err(EXIT_FAILURE, "send/repeat count can't be less then 1\n");
break;
case 'B':
priv->todo_broadcast = 1;
break;
case 'h': /*fallthrough*/
default:
fputs(help_msg, stderr);
return EXIT_FAILURE;
}
switch (opt) {
case 'i':
priv->infile = open(optarg, O_RDONLY);
if (priv->infile == -1)
err(EXIT_FAILURE, "can't open input file");
priv->todo_filesize = 1;
break;
case 's':
priv->max_transfer = strtoul(optarg, NULL, 0);
if (priv->max_transfer > J1939_MAX_ETP_PACKET_SIZE)
err(EXIT_FAILURE,
"used value (%zu) is bigger then allowed maximal size: %u.\n",
priv->max_transfer,
J1939_MAX_ETP_PACKET_SIZE);
break;
case 'r':
priv->todo_recv = 1;
break;
case 'p':
priv->todo_prio = strtoul(optarg, NULL, 0);
break;
case 'P':
priv->polltimeout = strtoul(optarg, NULL, 0);
break;
case 'c':
priv->todo_connect = 1;
break;
case 'R':
priv->repeat = strtoul(optarg, NULL, 0);
if (priv->repeat < 1)
err(EXIT_FAILURE,
"send/repeat count can't be less then 1\n");
break;
case 'B':
priv->todo_broadcast = 1;
break;
case 'h': /*fallthrough*/
default:
fputs(help_msg, stderr);
return EXIT_FAILURE;
}
if (argv[optind]) {
if (strcmp("-", argv[optind]))
if (strcmp("-", argv[optind]) != 0)
libj1939_parse_canaddr(argv[optind], &priv->sockname);
optind++;
}
if (argv[optind]) {
if (strcmp("-", argv[optind])) {
if (strcmp("-", argv[optind]) != 0) {
libj1939_parse_canaddr(argv[optind], &priv->peername);
priv->valid_peername = 1;
}

View File

@ -10,19 +10,19 @@
* as published by the Free Software Foundation
*/
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>
#include <err.h>
#include <sys/socket.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
#include "libj1939.h"
@ -107,30 +107,32 @@ int main(int argc, char **argv)
/* argument parsing */
while ((opt = getopt_long(argc, argv, optstring, long_opts, NULL)) != -1)
switch (opt) {
case 'v':
++s.verbose;
break;
case 'b':
s.pkt_len = strtoul(optarg, 0, 0);
break;
case 'P':
++s.promisc;
break;
case 't':
if (optarg) {
if (!strchr("adzA", optarg[0]))
err(1, "unknown time option '%c'", optarg[0]);
s.time = optarg[0];
} else {
s.time = 'z';
switch (opt) {
case 'v':
++s.verbose;
break;
case 'b':
s.pkt_len = strtoul(optarg, 0, 0);
break;
case 'P':
++s.promisc;
break;
case 't':
if (optarg) {
if (!strchr("adzA", optarg[0]))
err(1, "unknown time option '%c'",
optarg[0]);
s.time = optarg[0];
} else {
s.time = 'z';
}
break;
default:
fputs(help_msg, stderr);
exit(1);
break;
}
break;
default:
fputs(help_msg, stderr);
exit(1);
break;
}
if (argv[optind]) {
optarg = argv[optind];
ret = libj1939_str2addr(optarg, 0, &s.addr);

View File

@ -10,20 +10,20 @@
* as published by the Free Software Foundation
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <err.h>
#include <getopt.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "libj1939.h"
@ -99,27 +99,27 @@ int main(int argc, char **argv)
#endif
/* argument parsing */
while ((opt = getopt_long(argc, argv, optstring, long_opts, NULL)) != -1)
switch (opt) {
case 'v':
++s.verbose;
break;
case 's':
s.pkt_len = strtoul(optarg, 0, 0);
if (!s.pkt_len)
err(1, "packet size of %s", optarg);
break;
case 'p':
s.priority = strtoul(optarg, 0, 0);
s.defined |= DEF_PRIO;
break;
case 'S':
s.sendflags |= MSG_SYN;
break;
default:
fputs(help_msg, stderr);
exit(1);
break;
}
switch (opt) {
case 'v':
++s.verbose;
break;
case 's':
s.pkt_len = strtoul(optarg, 0, 0);
if (!s.pkt_len)
err(1, "packet size of %s", optarg);
break;
case 'p':
s.priority = strtoul(optarg, 0, 0);
s.defined |= DEF_PRIO;
break;
case 'S':
s.sendflags |= MSG_SYN;
break;
default:
fputs(help_msg, stderr);
exit(1);
break;
}
if (argv[optind]) {
optarg = argv[optind++];

6
lib.c
View File

@ -42,13 +42,13 @@
*
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <sys/socket.h> /* for sa_family_t */
#include <linux/can.h>
#include <linux/can/error.h>
#include <sys/socket.h> /* for sa_family_t */
#include "lib.h"
@ -588,7 +588,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c
if (class & mask) {
if (classes)
n += snprintf(buf + n, len - n, "%s", sep);
n += snprintf(buf + n, len - n, "%s", error_classes[i]);
n += snprintf(buf + n, len - n, "%s", error_classes[i]);
if (mask == CAN_ERR_LOSTARB)
n += snprintf_error_lostarb(buf + n, len - n,
cf);

View File

@ -10,16 +10,16 @@
* as published by the Free Software Foundation
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <net/if.h>
@ -64,8 +64,8 @@ static const char *libj1939_ifnam(int ifindex)
*/
libj1939_cleanup();
return libj1939_ifnam(ifindex);
} else
return NULL;
}
return NULL;
}
/* retrieve index */
@ -88,8 +88,8 @@ static int libj1939_ifindex(const char *str)
if (cached) {
libj1939_cleanup();
return libj1939_ifindex(str);
} else
return 0;
}
return 0;
}
void libj1939_parse_canaddr(char *spec, struct sockaddr_can *paddr)

View File

@ -42,15 +42,15 @@
*
*/
#include <libgen.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <libgen.h>
#include <unistd.h>
#include <linux/can.h>
#include <net/if.h>
#include <sys/time.h>
#include <linux/can.h>
#include "lib.h"

View File

@ -44,8 +44,8 @@
#include <stdio.h>
#include <net/if.h>
#include <linux/can.h>
#include <net/if.h>
#include "lib.h"

View File

@ -42,18 +42,18 @@
*
*/
#include <fcntl.h>
#include <getopt.h>
#include <linux/sockios.h>
#include <linux/tty.h>
#include <net/if.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <sys/socket.h>
#include <termios.h>
#include <linux/tty.h>
#include <linux/sockios.h>
#include <unistd.h>
void print_usage(char *prg)
{

View File

@ -22,25 +22,25 @@
*
*/
#include <errno.h>
#include <fcntl.h>
#include <linux/serial.h>
#include <linux/sockios.h>
#include <linux/tty.h>
#include <net/if.h>
#include <pwd.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <syslog.h>
#include <errno.h>
#include <pwd.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <syslog.h>
#include <termios.h>
#include <linux/tty.h>
#include <linux/sockios.h>
#include <linux/serial.h>
#include <stdarg.h>
#include <unistd.h>
/* Change this to whatever your daemon is called */
#define DAEMON_NAME "slcand"

View File

@ -10,20 +10,20 @@
* as published by the Free Software Foundation
*/
#include <signal.h>
#include <time.h>
#include <inttypes.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>
#include <err.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <getopt.h>
#include <net/if.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
#include "libj1939.h"
@ -101,55 +101,56 @@ int main(int argc, char *argv[])
/* argument parsing */
while ((opt = getopt(argc, argv, optstring)) != -1)
switch (opt) {
case 'v':
verbose = 1;
break;
case 's':
todo_send = strtoul(optarg ?: "8", NULL, 0);
if (todo_send > sizeof(dat))
err(1, "Unsupported size. max: %zu", sizeof(dat));
break;
case 'r':
todo_recv = 1;
break;
case 'e':
todo_echo = 1;
break;
case 'p':
todo_prio = strtoul(optarg, NULL, 0);
break;
case 'P':
todo_promisc = 1;
break;
case 'c':
todo_connect = 1;
break;
case 'n':
todo_names = 1;
break;
case 'b':
todo_rebind = 1;
break;
case 'B':
todo_broadcast = 1;
break;
case 'o':
no_bind = 1;
break;
case 'w':
schedule_oneshot_itimer(strtod(optarg ?: "1", NULL));
signal(SIGALRM, onsigalrm);
todo_wait = 1;
break;
default:
fputs(help_msg, stderr);
exit(1);
break;
}
switch (opt) {
case 'v':
verbose = 1;
break;
case 's':
todo_send = strtoul(optarg ?: "8", NULL, 0);
if (todo_send > sizeof(dat))
err(1, "Unsupported size. max: %zu",
sizeof(dat));
break;
case 'r':
todo_recv = 1;
break;
case 'e':
todo_echo = 1;
break;
case 'p':
todo_prio = strtoul(optarg, NULL, 0);
break;
case 'P':
todo_promisc = 1;
break;
case 'c':
todo_connect = 1;
break;
case 'n':
todo_names = 1;
break;
case 'b':
todo_rebind = 1;
break;
case 'B':
todo_broadcast = 1;
break;
case 'o':
no_bind = 1;
break;
case 'w':
schedule_oneshot_itimer(strtod(optarg ?: "1", NULL));
signal(SIGALRM, onsigalrm);
todo_wait = 1;
break;
default:
fputs(help_msg, stderr);
exit(1);
break;
}
if (argv[optind]) {
if (strcmp("-", argv[optind]))
if (strcmp("-", argv[optind]) != 0)
libj1939_parse_canaddr(argv[optind], &sockname);
++optind;
}
@ -158,7 +159,7 @@ int main(int argc, char *argv[])
sockname.can_addr.j1939.addr++;
if (argv[optind]) {
if (strcmp("-", argv[optind])) {
if (strcmp("-", argv[optind]) != 0) {
libj1939_parse_canaddr(argv[optind], &peername);
valid_peername = 1;
}