#include "lib.h"
+#define BUFSZ 400 /* for one line in the logfile */
+
extern int optind, opterr, optopt;
void print_usage(char *prg)
int main(int argc, char **argv)
{
- char buf[100], device[100], ascframe[100], id[10];
+ static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ], id[10];
struct can_frame cf;
static struct timeval tv, start_tv;
FILE *outfile = stdout;
static int maxdev, devno, i, crlf, d4, opt;
- while ((opt = getopt(argc, argv, "I:O:4n")) != -1) {
+ while ((opt = getopt(argc, argv, "I:O:4n?")) != -1) {
switch (opt) {
case 'I':
infile = fopen(optarg, "r");
d4 = 1;
break;
+ case '?':
+ print_usage(basename(argv[0]));
+ return 0;
+ break;
+
default:
fprintf(stderr, "Unknown option %c\n", opt);
print_usage(basename(argv[0]));
//printf("Found %d CAN devices!\n", maxdev);
- while (fgets(buf, 99, infile)) {
+ while (fgets(buf, BUFSZ-1, infile)) {
+
+ if (strlen(buf) >= BUFSZ-2) {
+ fprintf(stderr, "line too long for input buffer\n");
+ return 1;
+ }
+
+ /* check for a comment line */
+ if (buf[0] != '(')
+ continue;
+
if (sscanf(buf, "(%ld.%ld) %s %s", &tv.tv_sec, &tv.tv_usec,
- device, ascframe) != 4)
+ device, ascframe) != 4) {
+ fprintf(stderr, "incorrect line format in logfile\n");
return 1;
+ }
if (!start_tv.tv_sec) { /* print banner */
start_tv = tv;