Formatting, Cleanup, & Suggested Changes
Corrected formatting, removed old commented code, made suggested code changes. Update README.mdpull/88/head
parent
384ed8d919
commit
042038fb52
|
|
@ -13,7 +13,7 @@ subsystem (aka SocketCAN):
|
||||||
* canplayer : replay CAN logfiles
|
* canplayer : replay CAN logfiles
|
||||||
* cansend : send a single frame
|
* cansend : send a single frame
|
||||||
* cangen : generate (random) CAN traffic
|
* cangen : generate (random) CAN traffic
|
||||||
* cansniffer : display CAN data content differences ~~(just 11bit CAN IDs)~~
|
* cansniffer : display CAN data content differences
|
||||||
|
|
||||||
#### CAN access via IP sockets
|
#### CAN access via IP sockets
|
||||||
* canlogserver : log CAN frames from a remote/local host
|
* canlogserver : log CAN frames from a remote/local host
|
||||||
|
|
|
||||||
50
cansniffer.c
50
cansniffer.c
|
|
@ -106,9 +106,9 @@ struct snif {
|
||||||
struct can_frame notch;
|
struct can_frame notch;
|
||||||
} sniftab[MAX_SLOTS];
|
} sniftab[MAX_SLOTS];
|
||||||
|
|
||||||
|
|
||||||
extern int optind, opterr, optopt;
|
extern int optind, opterr, optopt;
|
||||||
|
|
||||||
|
static int idx;
|
||||||
static int running = 1;
|
static int running = 1;
|
||||||
static int clearscreen = 1;
|
static int clearscreen = 1;
|
||||||
static int notch;
|
static int notch;
|
||||||
|
|
@ -124,23 +124,23 @@ void print_snifline(int slot);
|
||||||
int handle_keyb(int fd);
|
int handle_keyb(int fd);
|
||||||
int handle_frame(int fd, long currcms);
|
int handle_frame(int fd, long currcms);
|
||||||
int handle_timeo(int fd, long currcms);
|
int handle_timeo(int fd, long currcms);
|
||||||
int sniftab_index(canid_t id);
|
|
||||||
void writesettings(char* name);
|
void writesettings(char* name);
|
||||||
void readsettings(char* name, int sockfd);
|
void readsettings(char* name, int sockfd);
|
||||||
|
static int sniftab_index(canid_t id);
|
||||||
int idx = 0;
|
|
||||||
|
|
||||||
|
|
||||||
int comp (const void * elem1, const void * elem2)
|
int comp (const void * elem1, const void * elem2)
|
||||||
{
|
{
|
||||||
unsigned long f = ((struct snif*)elem1)->current.can_id;
|
unsigned long f = ((struct snif*)elem1)->current.can_id;
|
||||||
unsigned long s = ((struct snif*)elem2)->current.can_id;
|
unsigned long s = ((struct snif*)elem2)->current.can_id;
|
||||||
if (f > s) return 1;
|
|
||||||
if (f < s) return -1;
|
if (f > s)
|
||||||
|
return 1;
|
||||||
|
if (f < s)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void print_usage(char *prg)
|
void print_usage(char *prg)
|
||||||
{
|
{
|
||||||
const char manual [] = {
|
const char manual [] = {
|
||||||
|
|
@ -164,20 +164,10 @@ void print_usage(char *prg)
|
||||||
"29 bit IDs:\n"
|
"29 bit IDs:\n"
|
||||||
"+18FEDF55<ENTER> - add CAN-ID 0x18FEDF55\n"
|
"+18FEDF55<ENTER> - add CAN-ID 0x18FEDF55\n"
|
||||||
"-00000090<ENTER> - remove CAN-ID 0x00000090\n"
|
"-00000090<ENTER> - remove CAN-ID 0x00000090\n"
|
||||||
/* "-42E7FF<ENTER> - remove CAN-ID 0x42E (using Bitmask)\N"*/
|
|
||||||
/* "-500700<ENTER> - remove CAN-IDs 0x500 - 0x5FF\n"*/
|
|
||||||
/* "+400600<ENTER> - add CAN-IDs 0x400 - 0x5FF\n"*/
|
|
||||||
/* "+000000<ENTER> - add all CAN-IDs\n"*/
|
|
||||||
/* "-000000<ENTER> - remove all CAN-IDs\n"*/
|
|
||||||
/* "\n"*/
|
|
||||||
/* "if (id & filter) == (sniff-id & filter) the action (+/-) IS PERFORMED,\N" */
|
|
||||||
/* "which is quite easy when the filter is 000\n"*/
|
|
||||||
"\n"
|
"\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
fprintf(stderr, "\nUsage: %s [can-interface]\n", prg);
|
fprintf(stderr, "\nUsage: %s [can-interface]\n", prg);
|
||||||
// fprintf(stderr, "Options: -m <mask> (initial FILTER default 0x00000000)\n");
|
|
||||||
// fprintf(stderr, " -v <value> (initial FILTER default 0x00000000)\n");
|
|
||||||
fprintf(stderr, "Options: -q (quiet - all slots are deactivated)\n");
|
fprintf(stderr, "Options: -q (quiet - all slots are deactivated)\n");
|
||||||
fprintf(stderr, " -r <name> (read %sname from file)\n", SETFNAME);
|
fprintf(stderr, " -r <name> (read %sname from file)\n", SETFNAME);
|
||||||
fprintf(stderr, " -b (start with binary mode)\n");
|
fprintf(stderr, " -b (start with binary mode)\n");
|
||||||
|
|
@ -200,8 +190,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
fd_set rdfs;
|
fd_set rdfs;
|
||||||
int s;
|
int s;
|
||||||
// canid_t mask = 0;
|
|
||||||
// canid_t value = 0;
|
|
||||||
long currcms = 0;
|
long currcms = 0;
|
||||||
long lastcms = 0;
|
long lastcms = 0;
|
||||||
unsigned char quiet = 0;
|
unsigned char quiet = 0;
|
||||||
|
|
@ -211,7 +199,6 @@ int main(int argc, char **argv)
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
signal(SIGTERM, sigterm);
|
signal(SIGTERM, sigterm);
|
||||||
signal(SIGHUP, sigterm);
|
signal(SIGHUP, sigterm);
|
||||||
signal(SIGINT, sigterm);
|
signal(SIGINT, sigterm);
|
||||||
|
|
@ -221,14 +208,6 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "m:v:r:t:h:l:qbBcf?")) != -1) {
|
while ((opt = getopt(argc, argv, "m:v:r:t:h:l:qbBcf?")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
// case 'm':
|
|
||||||
// sscanf(optarg, "%x", &mask);
|
|
||||||
// break;
|
|
||||||
//
|
|
||||||
// case 'v':
|
|
||||||
// sscanf(optarg, "%x", &value);
|
|
||||||
// break;
|
|
||||||
//
|
|
||||||
case 'r':
|
case 'r':
|
||||||
readsettings(optarg, 0);
|
readsettings(optarg, 0);
|
||||||
break;
|
break;
|
||||||
|
|
@ -281,16 +260,6 @@ int main(int argc, char **argv)
|
||||||
for (i = 0; i < MAX_SLOTS; i++)
|
for (i = 0; i < MAX_SLOTS; i++)
|
||||||
do_clr(i, ENABLE);
|
do_clr(i, ENABLE);
|
||||||
|
|
||||||
// Change this to do socket filtering
|
|
||||||
// else if (mask || value) {
|
|
||||||
// for (i=0; i < MAX_SLOTS ;i++) {
|
|
||||||
// if ((i & mask) == (value & mask))
|
|
||||||
// do_set(i, ENABLE);
|
|
||||||
// else
|
|
||||||
// do_clr(i, ENABLE);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (strlen(argv[optind]) >= IFNAMSIZ) {
|
if (strlen(argv[optind]) >= IFNAMSIZ) {
|
||||||
printf("name of CAN device '%s' is too long!\n", argv[optind]);
|
printf("name of CAN device '%s' is too long!\n", argv[optind]);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -733,7 +702,6 @@ void readsettings(char* name, int sockfd){
|
||||||
(__u8) strtoul(&buf[2*j+12], (char **)NULL, 16) & 0xFF;
|
(__u8) strtoul(&buf[2*j+12], (char **)NULL, 16) & 0xFF;
|
||||||
buf[2*j+12] = 0; /* cut off each time */
|
buf[2*j+12] = 0; /* cut off each time */
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!sockfd)
|
if (!sockfd)
|
||||||
|
|
@ -752,7 +720,7 @@ void readsettings(char* name, int sockfd){
|
||||||
printf("unable to read setting file '%s'!\n", fname);
|
printf("unable to read setting file '%s'!\n", fname);
|
||||||
};
|
};
|
||||||
|
|
||||||
int sniftab_index(canid_t id){
|
static int sniftab_index(canid_t id) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue