Merge pull request #316 from Rubusch/lothar/cansniffer
cansniffer: fix detection of invalid provided CAN interface, refacspull/319/head
commit
02e8b1ff39
6
Makefile
6
Makefile
|
|
@ -102,14 +102,14 @@ PROGRAMS := \
|
||||||
all: $(PROGRAMS)
|
all: $(PROGRAMS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(PROGRAMS) *.o
|
rm -f $(PROGRAMS) *.o mcp251xfd/*.o
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||||
cp -f $(PROGRAMS) $(DESTDIR)$(PREFIX)/bin
|
cp -f $(PROGRAMS) $(DESTDIR)$(PREFIX)/bin
|
||||||
|
|
||||||
distclean:
|
distclean: clean
|
||||||
rm -f $(PROGRAMS) $(LIBRARIES) *.o *~
|
rm -f $(PROGRAMS) $(LIBRARIES) *~
|
||||||
|
|
||||||
asc2log.o: lib.h
|
asc2log.o: lib.h
|
||||||
canbusload.o: lib.h
|
canbusload.o: lib.h
|
||||||
|
|
|
||||||
54
cansniffer.c
54
cansniffer.c
|
|
@ -236,7 +236,7 @@ int main(int argc, char **argv)
|
||||||
long currcms = 0;
|
long currcms = 0;
|
||||||
long lastcms = 0;
|
long lastcms = 0;
|
||||||
unsigned char quiet = 0;
|
unsigned char quiet = 0;
|
||||||
int opt, ret;
|
int opt, ret = 0;
|
||||||
struct timeval timeo, start_tv, tv;
|
struct timeval timeo, start_tv, tv;
|
||||||
struct sockaddr_can addr;
|
struct sockaddr_can addr;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -343,9 +343,11 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
ret = bind(s, (struct sockaddr *)&addr, sizeof(addr));
|
||||||
|
if (ret < 0) {
|
||||||
perror("bind");
|
perror("bind");
|
||||||
return 1;
|
close(s);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
gettimeofday(&start_tv, NULL);
|
gettimeofday(&start_tv, NULL);
|
||||||
|
|
@ -362,11 +364,13 @@ int main(int argc, char **argv)
|
||||||
timeo.tv_sec = 0;
|
timeo.tv_sec = 0;
|
||||||
timeo.tv_usec = 10000 * loop;
|
timeo.tv_usec = 10000 * loop;
|
||||||
|
|
||||||
if ((ret = select(s+1, &rdfs, NULL, NULL, &timeo)) < 0) {
|
ret = select(s+1, &rdfs, NULL, NULL, &timeo);
|
||||||
|
if (ret < 0) {
|
||||||
//perror("select");
|
//perror("select");
|
||||||
running = 0;
|
running = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
} else
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
currcms = (tv.tv_sec - start_tv.tv_sec) * 100 + (tv.tv_usec / 10000);
|
currcms = (tv.tv_sec - start_tv.tv_sec) * 100 + (tv.tv_usec / 10000);
|
||||||
|
|
@ -386,7 +390,7 @@ int main(int argc, char **argv)
|
||||||
printf("%s", CSR_SHOW); /* show cursor */
|
printf("%s", CSR_SHOW); /* show cursor */
|
||||||
|
|
||||||
close(s);
|
close(s);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_modify_sniftab(unsigned int value, unsigned int mask, char cmd)
|
void do_modify_sniftab(unsigned int value, unsigned int mask, char cmd)
|
||||||
|
|
@ -441,7 +445,7 @@ int handle_keyb(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for single SFF/EFF CAN ID length */
|
/* check for single SFF/EFF CAN ID length */
|
||||||
if (!((clen == 3) || (clen == 8)))
|
if (clen != 3 && clen != 8)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* enable/disable single SFF/EFF CAN ID */
|
/* enable/disable single SFF/EFF CAN ID */
|
||||||
|
|
@ -576,16 +580,15 @@ int handle_frame(int fd, long currcms)
|
||||||
pos = sniftab_index(cf.can_id);
|
pos = sniftab_index(cf.can_id);
|
||||||
if (pos < 0) {
|
if (pos < 0) {
|
||||||
/* CAN ID not existing */
|
/* CAN ID not existing */
|
||||||
if (idx < MAX_SLOTS) {
|
if (idx >= MAX_SLOTS) {
|
||||||
/* assign new slot */
|
|
||||||
pos = idx++;
|
|
||||||
rx_changed = true;
|
|
||||||
run_qsort = true;
|
|
||||||
} else {
|
|
||||||
/* informative exit */
|
/* informative exit */
|
||||||
perror("number of different CAN IDs exceeded MAX_SLOTS");
|
perror("number of different CAN IDs exceeded MAX_SLOTS");
|
||||||
return 0; /* quit */
|
return 0; /* quit */
|
||||||
}
|
}
|
||||||
|
/* assign new slot */
|
||||||
|
pos = idx++;
|
||||||
|
rx_changed = true;
|
||||||
|
run_qsort = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (cf.can_dlc == sniftab[pos].current.can_dlc)
|
if (cf.can_dlc == sniftab[pos].current.can_dlc)
|
||||||
|
|
@ -780,8 +783,11 @@ void writesettings(char* name)
|
||||||
|
|
||||||
strncat(fname, name, 29 - strlen(fname));
|
strncat(fname, name, 29 - strlen(fname));
|
||||||
fd = open(fname, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
fd = open(fname, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||||
|
if (fd <= 0) {
|
||||||
|
printf("unable to write setting file '%s'!\n", fname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (fd > 0) {
|
|
||||||
for (i = 0; i < idx ;i++) {
|
for (i = 0; i < idx ;i++) {
|
||||||
sprintf(buf, "<%08X>%c.", sniftab[i].current.can_id, (is_set(i, ENABLE))?'1':'0');
|
sprintf(buf, "<%08X>%c.", sniftab[i].current.can_id, (is_set(i, ENABLE))?'1':'0');
|
||||||
if (write(fd, buf, 12) < 0)
|
if (write(fd, buf, 12) < 0)
|
||||||
|
|
@ -797,9 +803,6 @@ void writesettings(char* name)
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
printf("unable to write setting file '%s'!\n", fname);
|
|
||||||
}
|
|
||||||
|
|
||||||
int readsettings(char* name)
|
int readsettings(char* name)
|
||||||
{
|
{
|
||||||
|
|
@ -812,10 +815,15 @@ int readsettings(char* name)
|
||||||
strncat(fname, name, 29 - strlen(fname));
|
strncat(fname, name, 29 - strlen(fname));
|
||||||
fd = open(fname, O_RDONLY);
|
fd = open(fname, O_RDONLY);
|
||||||
|
|
||||||
if (fd > 0) {
|
if (fd <= 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
idx = 0;
|
idx = 0;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
if (read(fd, &buf, 29) == 29) {
|
if (read(fd, &buf, 29) != 29) {
|
||||||
|
done = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
unsigned long id = strtoul(&buf[1], (char **)NULL, 16);
|
unsigned long id = strtoul(&buf[1], (char **)NULL, 16);
|
||||||
|
|
||||||
sniftab[idx].current.can_id = id;
|
sniftab[idx].current.can_id = id;
|
||||||
|
|
@ -833,15 +841,9 @@ int readsettings(char* name)
|
||||||
|
|
||||||
if (++idx >= MAX_SLOTS)
|
if (++idx >= MAX_SLOTS)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
else
|
|
||||||
done = true;
|
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue