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

View File

@ -108,21 +108,21 @@
* *
*/ */
#include <errno.h>
#include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <errno.h>
#include <time.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 <net/if.h>
#include <netinet/in.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.h>
#include <linux/can/bcm.h> #include <linux/can/bcm.h>

View File

@ -18,16 +18,16 @@
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <libgen.h>
#include <limits.h> #include <limits.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <libgen.h>
#include <string.h> #include <string.h>
#include <linux/types.h>
#include <linux/can/netlink.h> #include <linux/can/netlink.h>
#include <linux/types.h>
/* imported from kernel */ /* imported from kernel */
@ -691,7 +691,8 @@ int main(int argc, char *argv[])
} }
for (i = 0; i < ARRAY_SIZE(can_calc_consts); i++) { 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; continue;
found = true; 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 <ctype.h>
#include <libgen.h> #include <libgen.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.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/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <net/if.h>
#include <linux/can.h> #include <linux/can.h>
#include <linux/can/raw.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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <ctype.h>
#include <libgen.h>
#include <time.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/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <net/if.h>
#include <linux/can.h> #include <linux/can.h>
#include <linux/can/raw.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); printf("using interface name '%s'.\n", ifr.ifr_name);
#endif #endif
if (strcmp(ANYDEV, ifr.ifr_name)) { if (strcmp(ANYDEV, ifr.ifr_name) != 0) {
if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) { if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) {
perror("SIOCGIFINDEX"); perror("SIOCGIFINDEX");
exit(1); exit(1);

View File

@ -17,24 +17,24 @@
* Send feedback to <linux-can@vger.kernel.org> * 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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <libgen.h>
#include <getopt.h>
#include <time.h> #include <time.h>
#include <sched.h> #include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.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.h>
#include <linux/can/raw.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)) while ((ret = send(sockfd, frame, sizeof(*frame), 0))
!= sizeof(*frame)) { != sizeof(*frame)) {
if (ret < 0) { if (ret >= 0) {
if (errno != ENOBUFS) {
perror("send failed");
return -1;
} else {
if (verbose) {
printf("N");
fflush(stdout);
}
}
} else {
fprintf(stderr, "send returned %d", ret); fprintf(stderr, "send returned %d", ret);
return -1; return -1;
} }
if (errno != ENOBUFS) {
perror("send failed");
return -1;
}
if (verbose) {
printf("N");
fflush(stdout);
}
} }
return 0; return 0;
} }
@ -332,19 +330,19 @@ static int can_echo_gen(void)
if (recv_tx_pos == inflight_count) if (recv_tx_pos == inflight_count)
recv_tx_pos = 0; recv_tx_pos = 0;
continue; 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++; loops++;
if (test_loops && loops >= test_loops) if (test_loops && loops >= test_loops)
break; break;

View File

@ -45,12 +45,12 @@
*/ */
#include "canframelen.h" #include "canframelen.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <arpa/inet.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. * 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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <poll.h>
#include <ctype.h>
#include <libgen.h>
#include <time.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/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <net/if.h>
#include "lib.h"
#include <linux/can.h> #include <linux/can.h>
#include <linux/can/raw.h> #include <linux/can/raw.h>
#include "lib.h"
#define DEFAULT_GAP 200 /* ms */ #define DEFAULT_GAP 200 /* ms */
#define DEFAULT_BURST_COUNT 1 #define DEFAULT_BURST_COUNT 1
@ -297,7 +297,7 @@ int main(int argc, char **argv)
} }
ts.tv_sec = gap / 1000; 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 */ /* recognize obviously missing commandline option */
if (id_mode == MODE_FIX && frame.can_id > 0x7FF && !extended) { if (id_mode == MODE_FIX && frame.can_id > 0x7FF && !extended) {
@ -468,8 +468,8 @@ resend:
if (poll(&fds, 1, polltimeout) < 0) { if (poll(&fds, 1, polltimeout) < 0) {
perror("poll"); perror("poll");
return 1; return 1;
} else }
goto resend; goto resend;
} else } else
enobufs_count++; 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 <errno.h>
#include <sys/socket.h> #include <libgen.h>
#include <net/if.h> #include <linux/can/gw.h>
#include <linux/netlink.h> #include <linux/netlink.h>
#include <linux/rtnetlink.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 { enum {
UNSPEC, UNSPEC,
@ -706,8 +706,8 @@ int main(int argc, char **argv)
struct can_filter filter; struct can_filter filter;
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr;
struct cgw_csum_xor cs_xor; struct cgw_csum_xor cs_xor = {};
struct cgw_csum_crc8 cs_crc8; struct cgw_csum_crc8 cs_crc8 = {};
char crc8tab[513] = {0}; char crc8tab[513] = {0};
struct modattr modmsg[CGW_MOD_FUNCS]; struct modattr modmsg[CGW_MOD_FUNCS];
@ -717,8 +717,6 @@ int main(int argc, char **argv)
int i; int i;
memset(&req, 0, sizeof(req)); 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) { while ((opt = getopt(argc, argv, "ADFLs:d:Xteiu:l:f:c:p:x:m:M:?")) != -1) {
switch (opt) { 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 <ctype.h>
#include <libgen.h> #include <libgen.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.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 <net/if.h>
#include <netinet/in.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.h>
#include <linux/can/raw.h> #include <linux/can/raw.h>
#include <linux/sockios.h> #include <linux/sockios.h>
#include <signal.h> #include <signal.h>
#include <errno.h>
#include "lib.h" #include "lib.h"
@ -300,8 +300,7 @@ int main(int argc, char **argv)
//printf("accepted\n"); //printf("accepted\n");
if (!fork()) if (!fork())
break; break;
else close(accsocket);
close(accsocket);
} }
else if (errno != EINTR) { else if (errno != EINTR) {
perror("accept"); perror("accept");
@ -357,15 +356,14 @@ int main(int argc, char **argv)
addr.can_family = AF_CAN; 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]); strcpy(ifr.ifr_name, argv[optind+i]);
if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) { if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) {
perror("SIOCGIFINDEX"); perror("SIOCGIFINDEX");
exit(1); exit(1);
} }
addr.can_ifindex = ifr.ifr_ifindex; addr.can_ifindex = ifr.ifr_ifindex;
} } else
else
addr.can_ifindex = 0; /* any can interface */ addr.can_ifindex = 0; /* any can interface */
if (bind(s[i], (struct sockaddr *)&addr, sizeof(addr)) < 0) { if (bind(s[i], (struct sockaddr *)&addr, sizeof(addr)) < 0) {

View File

@ -42,19 +42,19 @@
* *
*/ */
#include <libgen.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <libgen.h>
#include <stdlib.h>
#include <unistd.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.h>
#include <linux/can/raw.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" #include "lib.h"
@ -215,7 +215,7 @@ int add_assignment(char *mode, int socket, char *txname, char *rxname,
} }
strcpy(asgn[i].rxif, rxname); strcpy(asgn[i].rxif, rxname);
if (strcmp(txname, "stdout")) { if (strcmp(txname, "stdout") != 0) {
strcpy(ifr.ifr_name, txname); strcpy(ifr.ifr_name, txname);
if (ioctl(socket, SIOCGIFINDEX, &ifr) < 0) { if (ioctl(socket, SIOCGIFINDEX, &ifr) < 0) {
perror("SIOCGIFINDEX"); 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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <ctype.h>
#include <libgen.h>
#include <time.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/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <net/if.h>
#include <linux/can.h> #include <linux/can.h>
#include <linux/can/raw.h> #include <linux/can/raw.h>
@ -333,7 +333,7 @@ int main(int argc, char **argv)
addr.can_family = AF_CAN; addr.can_family = AF_CAN;
if (strcmp(ANYDEV, argv[optind])) if (strcmp(ANYDEV, argv[optind]) != 0)
addr.can_ifindex = if_nametoindex(argv[optind]); addr.can_ifindex = if_nametoindex(argv[optind]);
else else
addr.can_ifindex = 0; /* any can interface */ addr.can_ifindex = 0; /* any can interface */

View File

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

View File

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

View File

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

View File

@ -42,16 +42,16 @@
* *
*/ */
#include <libgen.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <libgen.h> #include <unistd.h>
#include <net/if.h> #include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/can.h> #include <linux/can.h>
#include <linux/can/isotp.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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <libgen.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <errno.h>
#include <time.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 <net/if.h>
#include <netinet/in.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.h>
#include <linux/can/isotp.h> #include <linux/can/isotp.h>

View File

@ -42,23 +42,23 @@
* *
*/ */
#include <stdio.h>
#include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <libgen.h>
#include <time.h> #include <time.h>
#include <unistd.h>
#include <net/if.h> #include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "terminal.h"
#include <linux/can.h> #include <linux/can.h>
#include <linux/can/isotp.h> #include <linux/can/isotp.h>
#include <linux/sockios.h> #include <linux/sockios.h>
#include "terminal.h"
#define NO_CAN_ID 0xFFFFFFFFU #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 <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h> #include <syslog.h>
#include <unistd.h>
#include <net/if.h> #include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/can.h> #include <linux/can.h>
#include <linux/can/isotp.h> #include <linux/can/isotp.h>

View File

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

View File

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

View File

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

View File

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

6
lib.c
View File

@ -42,13 +42,13 @@
* *
*/ */
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdint.h>
#include <sys/socket.h> /* for sa_family_t */
#include <linux/can.h> #include <linux/can.h>
#include <linux/can/error.h> #include <linux/can/error.h>
#include <sys/socket.h> /* for sa_family_t */
#include "lib.h" #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 (class & mask) {
if (classes) if (classes)
n += snprintf(buf + n, len - n, "%s", sep); 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) if (mask == CAN_ERR_LOSTARB)
n += snprintf_error_lostarb(buf + n, len - n, n += snprintf_error_lostarb(buf + n, len - n,
cf); cf);

View File

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

View File

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

View File

@ -44,8 +44,8 @@
#include <stdio.h> #include <stdio.h>
#include <net/if.h>
#include <linux/can.h> #include <linux/can.h>
#include <net/if.h>
#include "lib.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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/socket.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <net/if.h> #include <sys/socket.h>
#include <termios.h> #include <termios.h>
#include <linux/tty.h> #include <unistd.h>
#include <linux/sockios.h>
void print_usage(char *prg) 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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.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 <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 <termios.h>
#include <linux/tty.h> #include <unistd.h>
#include <linux/sockios.h>
#include <linux/serial.h>
#include <stdarg.h>
/* Change this to whatever your daemon is called */ /* Change this to whatever your daemon is called */
#define DAEMON_NAME "slcand" #define DAEMON_NAME "slcand"

View File

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