4 * Copyright (c) 2002-2009 Volkswagen Group Electronic Research
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Volkswagen nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * Alternatively, provided that this notice is retained in full, this
20 * software may be distributed under the terms of the GNU General
21 * Public License ("GPL") version 2, in which case the provisions of the
22 * GPL apply INSTEAD OF those given above.
24 * The provided data structures and external interfaces from this code
25 * are not restricted to be used by modules with a GPL compatible license.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
40 * Send feedback to <linux-can@vger.kernel.org>
56 #include <sys/types.h>
57 #include <sys/socket.h>
58 #include <sys/ioctl.h>
62 #include <linux/can.h>
63 #include <linux/can/raw.h>
64 #include <linux/net_tstamp.h>
70 # define SIOCSHWTSTAMP 0x89b0
73 #define MAXSOCK 16 /* max. number of CAN interfaces given on the cmdline */
74 #define MAXIFNAMES 30 /* size of receive name index to omit ioctls */
75 #define MAXCOL 6 /* number of different colors for colorized output */
76 #define ANYDEV "any" /* name of interface to receive from any CAN interface */
77 #define ANL "\r\n" /* newline in ASC mode */
79 #define SILENT_INI 42 /* detect user setting on commandline */
80 #define SILENT_OFF 0 /* no silent mode */
81 #define SILENT_ANI 1 /* silent mode with animation */
82 #define SILENT_ON 2 /* silent mode (completely silent) */
85 #define RED ATTBOLD FGRED
86 #define GREEN ATTBOLD FGGREEN
87 #define YELLOW ATTBOLD FGYELLOW
88 #define BLUE ATTBOLD FGBLUE
89 #define MAGENTA ATTBOLD FGMAGENTA
90 #define CYAN ATTBOLD FGCYAN
92 const char col_on [MAXCOL][19] = {BLUE, RED, GREEN, BOLD, MAGENTA, CYAN};
93 const char col_off [] = ATTRESET;
95 static char *cmdlinename[MAXSOCK];
96 static __u32 dropcnt[MAXSOCK];
97 static __u32 last_dropcnt[MAXSOCK];
98 static char devname[MAXIFNAMES][IFNAMSIZ+1];
99 static int dindex[MAXIFNAMES];
100 static int max_devname_len; /* to prevent frazzled device name output */
101 const int canfd_on = 1;
104 const char anichar[MAXANI] = {'|', '/', '-', '\\'};
105 const char extra_m_info[4][4] = {"- -", "B -", "- E", "B E"};
107 extern int optind, opterr, optopt;
109 static volatile int running = 1;
111 void print_usage(char *prg)
113 fprintf(stderr, "\nUsage: %s [options] <CAN interface>+\n", prg);
114 fprintf(stderr, " (use CTRL-C to terminate %s)\n\n", prg);
115 fprintf(stderr, "Options: -t <type> (timestamp: (a)bsolute/(d)elta/(z)ero/(A)bsolute w date)\n");
116 fprintf(stderr, " -H (use hardware timestamping)\n");
117 fprintf(stderr, " -c (increment color mode level)\n");
118 fprintf(stderr, " -i (binary output - may exceed 80 chars/line)\n");
119 fprintf(stderr, " -a (enable additional ASCII output)\n");
120 fprintf(stderr, " -S (swap byte order in printed CAN data[] - marked with '%c' )\n", SWAP_DELIMITER);
121 fprintf(stderr, " -s <level> (silent mode - %d: off (default) %d: animation %d: silent)\n", SILENT_OFF, SILENT_ANI, SILENT_ON);
122 fprintf(stderr, " -b <can> (bridge mode - send received frames to <can>)\n");
123 fprintf(stderr, " -B <can> (bridge mode - like '-b' with disabled loopback)\n");
124 fprintf(stderr, " -u <usecs> (delay bridge forwarding by <usecs> microseconds)\n");
125 fprintf(stderr, " -l (log CAN-frames into file. Sets '-s %d' by default)\n", SILENT_ON);
126 fprintf(stderr, " -L (use log file format on stdout)\n");
127 fprintf(stderr, " -n <count> (terminate after receiption of <count> CAN frames)\n");
128 fprintf(stderr, " -r <size> (set socket receive buffer to <size>)\n");
129 fprintf(stderr, " -d (monitor dropped CAN frames)\n");
130 fprintf(stderr, " -e (dump CAN error frames in human-readable format)\n");
131 fprintf(stderr, " -x (print extra message infos, rx/tx brs esi)\n");
132 fprintf(stderr, " -T <msecs> (terminate after <msecs> without any reception)\n");
133 fprintf(stderr, "\n");
134 fprintf(stderr, "Up to %d CAN interfaces with optional filter sets can be specified\n", MAXSOCK);
135 fprintf(stderr, "on the commandline in the form: <ifname>[,filter]*\n");
136 fprintf(stderr, "\nComma separated filters can be specified for each given CAN interface:\n");
137 fprintf(stderr, " <can_id>:<can_mask> (matches when <received_can_id> & mask == can_id & mask)\n");
138 fprintf(stderr, " <can_id>~<can_mask> (matches when <received_can_id> & mask != can_id & mask)\n");
139 fprintf(stderr, " #<error_mask> (set error frame filter, see include/linux/can/error.h)\n");
140 fprintf(stderr, " [j|J] (join the given CAN filters - logical AND semantic)\n");
141 fprintf(stderr, "\nCAN IDs, masks and data content are given and expected in hexadecimal values.\n");
142 fprintf(stderr, "When can_id and can_mask are both 8 digits, they are assumed to be 29 bit EFF.\n");
143 fprintf(stderr, "Without any given filter all data frames are received ('0:0' default filter).\n");
144 fprintf(stderr, "\nUse interface name '%s' to receive from all CAN interfaces.\n", ANYDEV);
145 fprintf(stderr, "\nExamples:\n");
146 fprintf(stderr, "%s -c -c -ta can0,123:7FF,400:700,#000000FF can2,400~7F0 can3 can8\n", prg);
147 fprintf(stderr, "%s -l any,0~0,#FFFFFFFF (log only error frames but no(!) data frames)\n", prg);
148 fprintf(stderr, "%s -l any,0:0,#FFFFFFFF (log error frames and also all data frames)\n", prg);
149 fprintf(stderr, "%s vcan2,92345678:DFFFFFFF (match only for extended CAN ID 12345678)\n", prg);
150 fprintf(stderr, "%s vcan2,123:7FF (matches CAN ID 123 - including EFF and RTR frames)\n", prg);
151 fprintf(stderr, "%s vcan2,123:C00007FF (matches CAN ID 123 - only SFF and non-RTR frames)\n", prg);
152 fprintf(stderr, "\n");
155 void sigterm(int signo)
160 int idx2dindex(int ifidx, int socket) {
165 for (i=0; i < MAXIFNAMES; i++) {
166 if (dindex[i] == ifidx)
170 /* create new interface index cache entry */
172 /* remove index cache zombies first */
173 for (i=0; i < MAXIFNAMES; i++) {
175 ifr.ifr_ifindex = dindex[i];
176 if (ioctl(socket, SIOCGIFNAME, &ifr) < 0)
181 for (i=0; i < MAXIFNAMES; i++)
182 if (!dindex[i]) /* free entry */
185 if (i == MAXIFNAMES) {
186 fprintf(stderr, "Interface index cache only supports %d interfaces.\n",
193 ifr.ifr_ifindex = ifidx;
194 if (ioctl(socket, SIOCGIFNAME, &ifr) < 0)
195 perror("SIOCGIFNAME");
197 if (max_devname_len < strlen(ifr.ifr_name))
198 max_devname_len = strlen(ifr.ifr_name);
200 strcpy(devname[i], ifr.ifr_name);
203 printf("new index %d (%s)\n", i, devname[i]);
209 int main(int argc, char **argv)
214 useconds_t bridge_delay = 0;
215 unsigned char timestamp = 0;
216 int hw_timestamp = 0;
217 unsigned char dropmonitor = 0;
218 unsigned char extra_msg_info = 0;
219 unsigned char silent = SILENT_INI;
220 unsigned char silentani = 0;
221 unsigned char color = 0;
222 unsigned char view = 0;
223 unsigned char log = 0;
224 unsigned char logfrmt = 0;
228 int currmax, numfilter;
231 struct sockaddr_can addr;
232 char ctrlmsg[CMSG_SPACE(sizeof(struct timeval)) + CMSG_SPACE(sizeof(__u32))];
235 struct cmsghdr *cmsg;
236 struct can_filter *rfilter;
237 can_err_mask_t err_mask;
238 struct canfd_frame frame;
239 int nbytes, i, maxdlen;
241 struct timeval tv, last_tv;
242 struct timeval timeout, timeout_config = { 0, 0 }, *timeout_current = NULL;
243 FILE *logfile = NULL;
245 signal(SIGTERM, sigterm);
246 signal(SIGHUP, sigterm);
247 signal(SIGINT, sigterm);
252 while ((opt = getopt(argc, argv, "t:ciaSs:b:B:u:ldxLn:r:heT:H?")) != -1) {
255 timestamp = optarg[0];
256 if ((timestamp != 'a') && (timestamp != 'A') &&
257 (timestamp != 'd') && (timestamp != 'z')) {
258 fprintf(stderr, "%s: unknown timestamp mode '%c' - ignored\n",
259 basename(argv[0]), optarg[0]);
273 view |= CANLIB_VIEW_BINARY;
277 view |= CANLIB_VIEW_ASCII;
281 view |= CANLIB_VIEW_SWAP;
285 view |= CANLIB_VIEW_ERROR;
289 silent = atoi(optarg);
290 if (silent > SILENT_ON) {
291 print_usage(basename(argv[0]));
298 if (strlen(optarg) >= IFNAMSIZ) {
299 fprintf(stderr, "Name of CAN device '%s' is too long!\n\n", optarg);
302 bridge = socket(PF_CAN, SOCK_RAW, CAN_RAW);
304 perror("bridge socket");
307 addr.can_family = AF_CAN;
308 strcpy(ifr.ifr_name, optarg);
309 if (ioctl(bridge, SIOCGIFINDEX, &ifr) < 0)
310 perror("SIOCGIFINDEX");
311 addr.can_ifindex = ifr.ifr_ifindex;
313 if (!addr.can_ifindex) {
314 perror("invalid bridge interface");
318 /* disable default receive filter on this write-only RAW socket */
319 setsockopt(bridge, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
322 const int loopback = 0;
324 setsockopt(bridge, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
325 &loopback, sizeof(loopback));
328 if (bind(bridge, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
329 perror("bridge bind");
336 bridge_delay = (useconds_t)strtoul(optarg, (char **)NULL, 10);
356 count = atoi(optarg);
358 print_usage(basename(argv[0]));
364 rcvbuf_size = atoi(optarg);
365 if (rcvbuf_size < 1) {
366 print_usage(basename(argv[0]));
373 timeout_config.tv_usec = strtol(optarg, NULL, 0);
375 print_usage(basename(argv[0]));
378 timeout_config.tv_sec = timeout_config.tv_usec / 1000;
379 timeout_config.tv_usec = (timeout_config.tv_usec % 1000) * 1000;
380 timeout_current = &timeout;
383 print_usage(basename(argv[0]));
389 if (optind == argc) {
390 print_usage(basename(argv[0]));
394 if (logfrmt && view) {
395 fprintf(stderr, "Log file format selected: Please disable ASCII/BINARY/SWAP options!\n");
399 if (silent == SILENT_INI) {
401 fprintf(stderr, "Disabled standard output while logging.\n");
402 silent = SILENT_ON; /* disable output on stdout */
404 silent = SILENT_OFF; /* default output */
407 currmax = argc - optind; /* find real number of CAN devices */
409 if (currmax > MAXSOCK) {
410 fprintf(stderr, "More than %d CAN devices given on commandline!\n", MAXSOCK);
414 for (i=0; i < currmax; i++) {
416 ptr = argv[optind+i];
417 nptr = strchr(ptr, ',');
420 printf("open %d '%s'.\n", i, ptr);
423 s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW);
429 cmdlinename[i] = ptr; /* save pointer to cmdline name of this socket */
432 nbytes = nptr - ptr; /* interface name is up the first ',' */
434 nbytes = strlen(ptr); /* no ',' found => no filter definitions */
436 if (nbytes >= IFNAMSIZ) {
437 fprintf(stderr, "name of CAN device '%s' is too long!\n", ptr);
441 if (nbytes > max_devname_len)
442 max_devname_len = nbytes; /* for nice printing */
444 addr.can_family = AF_CAN;
446 memset(&ifr.ifr_name, 0, sizeof(ifr.ifr_name));
447 strncpy(ifr.ifr_name, ptr, nbytes);
450 printf("using interface name '%s'.\n", ifr.ifr_name);
453 if (strcmp(ANYDEV, ifr.ifr_name)) {
454 if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) {
455 perror("SIOCGIFINDEX");
458 addr.can_ifindex = ifr.ifr_ifindex;
460 addr.can_ifindex = 0; /* any can interface */
464 /* found a ',' after the interface name => check for filters */
466 /* determine number of filters to alloc the filter space */
471 ptr++; /* hop behind the ',' */
472 ptr = strchr(ptr, ','); /* exit condition */
475 rfilter = malloc(sizeof(struct can_filter) * numfilter);
477 fprintf(stderr, "Failed to create filter space!\n");
487 ptr = nptr+1; /* hop behind the ',' */
488 nptr = strchr(ptr, ','); /* update exit condition */
490 if (sscanf(ptr, "%x:%x",
491 &rfilter[numfilter].can_id,
492 &rfilter[numfilter].can_mask) == 2) {
493 rfilter[numfilter].can_mask &= ~CAN_ERR_FLAG;
495 } else if (sscanf(ptr, "%x~%x",
496 &rfilter[numfilter].can_id,
497 &rfilter[numfilter].can_mask) == 2) {
498 rfilter[numfilter].can_id |= CAN_INV_FILTER;
499 rfilter[numfilter].can_mask &= ~CAN_ERR_FLAG;
501 } else if (*ptr == 'j' || *ptr == 'J') {
503 } else if (sscanf(ptr, "#%x", &err_mask) != 1) {
504 fprintf(stderr, "Error in filter option parsing: '%s'\n", ptr);
510 setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
511 &err_mask, sizeof(err_mask));
513 if (join_filter && setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_JOIN_FILTERS,
514 &join_filter, sizeof(join_filter)) < 0) {
515 perror("setsockopt CAN_RAW_JOIN_FILTERS not supported by your Linux Kernel");
520 setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FILTER,
521 rfilter, numfilter * sizeof(struct can_filter));
527 /* try to switch the socket into CAN FD mode */
528 setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
532 int curr_rcvbuf_size;
533 socklen_t curr_rcvbuf_size_len = sizeof(curr_rcvbuf_size);
535 /* try SO_RCVBUFFORCE first, if we run with CAP_NET_ADMIN */
536 if (setsockopt(s[i], SOL_SOCKET, SO_RCVBUFFORCE,
537 &rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
539 printf("SO_RCVBUFFORCE failed so try SO_RCVBUF ...\n");
541 if (setsockopt(s[i], SOL_SOCKET, SO_RCVBUF,
542 &rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
543 perror("setsockopt SO_RCVBUF");
547 if (getsockopt(s[i], SOL_SOCKET, SO_RCVBUF,
548 &curr_rcvbuf_size, &curr_rcvbuf_size_len) < 0) {
549 perror("getsockopt SO_RCVBUF");
553 /* Only print a warning the first time we detect the adjustment */
554 /* n.b.: The wanted size is doubled in Linux in net/sore/sock.c */
555 if (!i && curr_rcvbuf_size < rcvbuf_size*2)
556 fprintf(stderr, "The socket receive buffer size was "
557 "adjusted due to /proc/sys/net/core/rmem_max.\n");
561 if (timestamp || log || logfrmt) {
562 if (hw_timestamp == 0) {
563 const int timestamp_on = 1;
565 if (setsockopt(s[i], SOL_SOCKET, SO_TIMESTAMP,
566 ×tamp_on, sizeof(timestamp_on)) < 0) {
567 perror("setsockopt SO_TIMESTAMP");
571 struct ifreq hwtstamp;
572 struct hwtstamp_config hwconfig;
574 memset(&hwtstamp, 0, sizeof(hwtstamp));
575 strncpy(hwtstamp.ifr_name, ifr.ifr_name, sizeof(hwtstamp.ifr_name));
576 hwtstamp.ifr_data = (void *)&hwconfig;
577 memset(&hwconfig, 0, sizeof(hwconfig));
578 hwconfig.tx_type = HWTSTAMP_TX_OFF;
579 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
581 if (ioctl(s[i], SIOCSHWTSTAMP, &hwtstamp) < 0) {
582 perror("SIOCSHWTSTAMP");
586 const int so_timestamping_flags = SOF_TIMESTAMPING_RAW_HARDWARE;
588 if (setsockopt(s[i], SOL_SOCKET, SO_TIMESTAMPING,
589 &so_timestamping_flags,
590 sizeof(so_timestamping_flags)) < 0)
591 perror("setsockopt SO_TIMESTAMPING");
597 const int dropmonitor_on = 1;
599 if (setsockopt(s[i], SOL_SOCKET, SO_RXQ_OVFL,
600 &dropmonitor_on, sizeof(dropmonitor_on)) < 0) {
601 perror("setsockopt SO_RXQ_OVFL not supported by your Linux Kernel");
606 if (bind(s[i], (struct sockaddr *)&addr, sizeof(addr)) < 0) {
615 char fname[sizeof("candump-2006-11-20_202026.log")+1];
617 if (time(&currtime) == (time_t)-1) {
622 localtime_r(&currtime, &now);
624 sprintf(fname, "candump-%04d-%02d-%02d_%02d%02d%02d.log",
632 if (silent != SILENT_ON)
633 printf("\nWarning: console output active while logging!");
635 fprintf(stderr, "\nEnabling Logfile '%s'\n\n", fname);
637 logfile = fopen(fname, "w");
644 /* these settings are static and can be held out of the hot path */
645 iov.iov_base = &frame;
646 msg.msg_name = &addr;
649 msg.msg_control = &ctrlmsg;
654 for (i=0; i<currmax; i++)
658 *timeout_current = timeout_config;
660 if ((ret = select(s[currmax-1]+1, &rdfs, NULL, NULL, timeout_current)) <= 0) {
666 for (i=0; i<currmax; i++) { /* check all CAN RAW sockets */
668 if (FD_ISSET(s[i], &rdfs)) {
672 /* these settings may be modified by recvmsg() */
673 iov.iov_len = sizeof(frame);
674 msg.msg_namelen = sizeof(addr);
675 msg.msg_controllen = sizeof(ctrlmsg);
678 nbytes = recvmsg(s[i], &msg, 0);
684 if ((size_t)nbytes == CAN_MTU)
685 maxdlen = CAN_MAX_DLEN;
686 else if ((size_t)nbytes == CANFD_MTU)
687 maxdlen = CANFD_MAX_DLEN;
689 fprintf(stderr, "read: incomplete CAN frame\n");
693 if (count && (--count == 0))
698 usleep(bridge_delay);
700 nbytes = write(bridge, &frame, nbytes);
702 perror("bridge write");
704 } else if ((size_t)nbytes != CAN_MTU && (size_t)nbytes != CANFD_MTU) {
705 fprintf(stderr,"bridge write: incomplete CAN frame\n");
710 for (cmsg = CMSG_FIRSTHDR(&msg);
711 cmsg && (cmsg->cmsg_level == SOL_SOCKET);
712 cmsg = CMSG_NXTHDR(&msg,cmsg)) {
713 if (cmsg->cmsg_type == SO_TIMESTAMP)
714 tv = *(struct timeval *)CMSG_DATA(cmsg);
715 else if (cmsg->cmsg_type == SO_RXQ_OVFL)
716 dropcnt[i] = *(__u32 *)CMSG_DATA(cmsg);
717 else if (cmsg->cmsg_type == SO_TIMESTAMPING) {
718 struct timespec *ts = (struct timespec *) CMSG_DATA(cmsg);
719 tv.tv_sec = ts[2].tv_sec;
720 tv.tv_usec = ts[2].tv_nsec / 1000;
725 /* check for (unlikely) dropped frames on this specific socket */
726 if (dropcnt[i] != last_dropcnt[i]) {
728 __u32 frames = dropcnt[i] - last_dropcnt[i];
730 if (silent != SILENT_ON)
731 printf("DROPCOUNT: dropped %d CAN frame%s on '%s' socket (total drops %d)\n",
732 frames, (frames > 1)?"s":"", cmdlinename[i], dropcnt[i]);
735 fprintf(logfile, "DROPCOUNT: dropped %d CAN frame%s on '%s' socket (total drops %d)\n",
736 frames, (frames > 1)?"s":"", cmdlinename[i], dropcnt[i]);
738 last_dropcnt[i] = dropcnt[i];
741 idx = idx2dindex(addr.can_ifindex, s[i]);
743 /* once we detected a EFF frame indent SFF frames accordingly */
744 if (frame.can_id & CAN_EFF_FLAG)
745 view |= CANLIB_VIEW_INDENT_SFF;
748 char buf[CL_CFSZ]; /* max length */
750 /* log CAN frame with absolute timestamp & device */
751 sprint_canframe(buf, &frame, 0, maxdlen);
752 fprintf(logfile, "(%010ld.%06ld) %*s %s\n",
753 tv.tv_sec, tv.tv_usec,
754 max_devname_len, devname[idx], buf);
758 char buf[CL_CFSZ]; /* max length */
760 /* print CAN frame in log file style to stdout */
761 sprint_canframe(buf, &frame, 0, maxdlen);
762 printf("(%010ld.%06ld) %*s %s\n",
763 tv.tv_sec, tv.tv_usec,
764 max_devname_len, devname[idx], buf);
765 goto out_fflush; /* no other output to stdout */
768 if (silent != SILENT_OFF){
769 if (silent == SILENT_ANI) {
770 printf("%c\b", anichar[silentani%=MAXANI]);
773 goto out_fflush; /* no other output to stdout */
776 printf(" %s", (color>2)?col_on[idx%MAXCOL]:"");
780 case 'a': /* absolute with timestamp */
781 printf("(%010ld.%06ld) ", tv.tv_sec, tv.tv_usec);
784 case 'A': /* absolute with date */
789 tm = *localtime(&tv.tv_sec);
790 strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
791 printf("(%s.%06ld) ", timestring, tv.tv_usec);
795 case 'd': /* delta */
796 case 'z': /* starting with zero */
800 if (last_tv.tv_sec == 0) /* first init */
802 diff.tv_sec = tv.tv_sec - last_tv.tv_sec;
803 diff.tv_usec = tv.tv_usec - last_tv.tv_usec;
804 if (diff.tv_usec < 0)
805 diff.tv_sec--, diff.tv_usec += 1000000;
807 diff.tv_sec = diff.tv_usec = 0;
808 printf("(%03ld.%06ld) ", diff.tv_sec, diff.tv_usec);
810 if (timestamp == 'd')
811 last_tv = tv; /* update for delta calculation */
815 default: /* no timestamp output */
819 printf(" %s", (color && (color<3))?col_on[idx%MAXCOL]:"");
820 printf("%*s", max_devname_len, devname[idx]);
822 if (extra_msg_info) {
824 if (msg.msg_flags & MSG_DONTROUTE)
825 printf (" TX %s", extra_m_info[frame.flags & 3]);
827 printf (" RX %s", extra_m_info[frame.flags & 3]);
830 printf("%s ", (color==1)?col_off:"");
832 fprint_long_canframe(stdout, &frame, NULL, view, maxdlen);
834 printf("%s", (color>1)?col_off:"");
843 for (i=0; i<currmax; i++)