From: Oliver Hartkopp Date: Wed, 30 May 2007 07:20:18 +0000 (+0000) Subject: Added new commandline option '-B' which acts like the bridging option '-b' but X-Git-Url: https://rtime.felk.cvut.cz/gitweb/sojka/can-utils.git/commitdiff_plain/5723c5ce864b7f7ee9bfaaa8e69be82f6ecfe549 Added new commandline option '-B' which acts like the bridging option '-b' but disables the local loopback functionality (for ECU analysis and MITM-attacks :) Fixed missing fflush(). --- diff --git a/candump.c b/candump.c index 16628ab..325ee56 100644 --- a/candump.c +++ b/candump.c @@ -107,6 +107,7 @@ void print_usage(char *prg) fprintf(stderr, " -a (enable additional ASCII output)\n"); fprintf(stderr, " -s (silent mode - 1: animation 2: nothing)\n"); fprintf(stderr, " -b (bridge mode - send received frames to )\n"); + fprintf(stderr, " -B (bridge mode - like '-b' with disabled loopback)\n"); fprintf(stderr, " -l (log CAN-frames into file)\n"); fprintf(stderr, " -L (use log file format on stdout)\n"); fprintf(stderr, "\n"); @@ -192,7 +193,7 @@ int main(int argc, char **argv) last_tv.tv_sec = 0; last_tv.tv_usec = 0; - while ((opt = getopt(argc, argv, "m:v:i:e:t:cas:b:lL")) != -1) { + while ((opt = getopt(argc, argv, "m:v:i:e:t:cas:b:B:lL")) != -1) { switch (opt) { case 'm': i = sscanf(optarg, "%x,%x,%x,%x,%x,%x", @@ -249,6 +250,7 @@ int main(int argc, char **argv) break; case 'b': + case 'B': if (strlen(optarg) >= IFNAMSIZ) { printf("Name of CAN device '%s' is too long!\n\n", optarg); return 1; @@ -269,6 +271,12 @@ int main(int argc, char **argv) return 1; } + if (opt == 'B') { + int loopback = 0; + + setsockopt(bridge, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &loopback, sizeof(loopback)); + } + if (bind(bridge, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("bridge bind"); return 1; @@ -463,7 +471,7 @@ int main(int argc, char **argv) printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); printf("%*s ", max_devname_len, devname[idx]); fprint_canframe(stdout, &frame, "\n", 0); - continue; /* no other output to stdout */ + goto out_fflush; /* no other output to stdout */ } if (silent){ @@ -471,7 +479,7 @@ int main(int argc, char **argv) printf("%c\b", anichar[silentani%=MAXANI]); silentani++; } - continue; /* no other output to stdout */ + goto out_fflush; /* no other output to stdout */ } printf(" %s", (color>2)?col_on[idx]:""); @@ -526,6 +534,8 @@ int main(int argc, char **argv) printf("%s", (color>1)?col_off:""); printf("\n"); } + +out_fflush: fflush(stdout); } }