X-Git-Url: https://rtime.felk.cvut.cz/gitweb/sojka/can-utils.git/blobdiff_plain/8d365bc5b045889046ddc2014e126733d8ace1ef..HEAD:/cansniffer.c diff --git a/cansniffer.c b/cansniffer.c index c184e37..71ca721 100644 --- a/cansniffer.c +++ b/cansniffer.c @@ -1,19 +1,14 @@ -/* - * $Id$ - */ - /* * can-sniffer.c * - * Copyright (c) 2002-2005 Volkswagen Group Electronic Research + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions, the following disclaimer and - * the referenced file 'COPYING'. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. @@ -23,8 +18,8 @@ * * Alternatively, provided that this notice is retained in full, this * software may be distributed under the terms of the GNU General - * Public License ("GPL") version 2 as distributed in the 'COPYING' - * file from the main directory of the linux kernel source. + * Public License ("GPL") version 2, in which case the provisions of the + * GPL apply INSTEAD OF those given above. * * The provided data structures and external interfaces from this code * are not restricted to be used by modules with a GPL compatible license. @@ -42,7 +37,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * - * Send feedback to + * Send feedback to * */ @@ -72,6 +67,7 @@ #define U64_DATA(p) (*(unsigned long long*)(p)->data) #define SETFNAME "sniffset." +#define ANYDEV "any" /* flags */ @@ -102,15 +98,15 @@ const char anichar[MAXANI] = {'|', '/', '-', '\\', '|', '/', '-', '\\'}; #define STARTLINESTR "X time ID data ... " struct snif { - int flags; - long hold; - long timeout; - struct timeval laststamp; - struct timeval currstamp; - struct can_frame last; - struct can_frame current; - struct can_frame marker; - struct can_frame notch; + int flags; + long hold; + long timeout; + struct timeval laststamp; + struct timeval currstamp; + struct can_frame last; + struct can_frame current; + struct can_frame marker; + struct can_frame notch; } sniftab[2048]; @@ -118,13 +114,15 @@ extern int optind, opterr, optopt; static int running = 1; static int clearscreen = 1; -static int notch = 0; +static int notch; +static int filter_id_only; static long timeout = TIMEOUT; static long hold = HOLD; static long loop = LOOP; -static unsigned char binary = 0; -static unsigned char binary_gap = 0; -static unsigned char color = 0; +static unsigned char binary; +static unsigned char binary_gap; +static unsigned char color; +static char *interface; void rx_setup (int fd, int id); void rx_delete (int fd, int id); @@ -137,604 +135,622 @@ void readsettings(char* name, int sockfd); void print_usage(char *prg) { - const char manual [] = { - "commands that can be entered at runtime:\n" - "\n" - "q - quit\n" - "b - toggle binary / HEX-ASCII output\n" - "B - toggle binary with gap / HEX-ASCII output (exceeds 80 chars!)\n" - "c - toggle color mode\n" - "# - notch currently marked/changed bits (can be used repeatedly)\n" - "* - clear notched marked\n" - "rMYNAME - read settings file (filter/notch)\n" - "wMYNAME - write settings file (filter/notch)\n" - "+FILTER - add CAN-IDs to sniff\n" - "-FILTER - remove CAN-IDs to sniff\n" - "\n" - "FILTER can be a single CAN-ID or a CAN-ID/Bitmask:\n" - "+1F5 - add CAN-ID 0x1F5\n" - "-42E - remove CAN-ID 0x42E\n" - "-42E7FF - remove CAN-ID 0x42E (using Bitmask)\n" - "-500700 - remove CAN-IDs 0x500 - 0x5FF\n" - "+400600 - add CAN-IDs 0x400 - 0x5FF\n" - "+000000 - add all CAN-IDs\n" - "-000000 - 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" - }; - - fprintf(stderr, "\nUsage: %s [can-interface]\n", prg); - fprintf(stderr, "Options: -m (initial FILTER default 0x00000000)\n"); - fprintf(stderr, " -v (initial FILTER default 0x00000000)\n"); - fprintf(stderr, " -q (quiet - all IDs deactivated)\n"); - fprintf(stderr, " -r (read %sname from file)\n", SETFNAME); - fprintf(stderr, " -b (start with binary mode)\n"); - fprintf(stderr, " -B (start with binary mode with gap - exceeds 80 chars!)\n"); - fprintf(stderr, " -c (color changes)\n"); - fprintf(stderr, " -t