Commit Graph

109 Commits (4be73985fced4694108bae79d8dfb84a1be1d3cc)

Author SHA1 Message Date
Darcy Phipps 65e715d56d candump: Use SCM_* consts instead of SO_* for cmsg_type
There are explicit #defines for SCM_TIMESTAMP and SCM_TIMESTAMPING. They
currently happen to have the same value as SO_TIMESTAMP and
SO_TIMESTAMPING but the former should be used when checking cmsg_type in
case one day they do not.
2025-12-05 09:35:50 -05:00
Oliver Hartkopp ed7822c9a2 candump: print CAN XL specific flags as extra message infos
The extra message infos BRS and ESI have been printed when enabled with
the '-x' option. Since CAN XL has similar flags (SEC and RRS) those flags
have been wrongly printed as CAN FD flags.

This patch introduces separate flags for the CAN XL frames and prints them
when a CAN XL frame is processed.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-11-26 19:04:50 +01:00
Rikus Wessels 987bc8aac2
Optional nanosecond timestamp logging (#592)
* Optional nanosecond timestamp logging

* Removed limited string reading
2025-09-03 11:11:47 +02:00
Oliver Hartkopp 8d7d7650d4
can-utils: fix sign-compare warnings (#513)
Fixing several build issues reported by Gary Bisson when he was building
can-utils with clang (AOSP14).

URL: https://github.com/linux-can/can-utils/pull/512
Reported-by: Gary Bisson (https://github.com/gibsson)

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-04-24 20:02:02 +02:00
Oliver Hartkopp 27030b3e54 lib: make sprint_canframe the buffer size aware snprintf_canframe
Make sure the library functions to convert CAN frames into ASCII
represenation do not exceed the given buffer size. This also applies
to the long CAN frame output library function.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-12 19:11:58 +01:00
Oliver Hartkopp 1da219922d unify buffer size for ASCII CAN frame string representations
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-29 07:10:34 +01:00
Oliver Hartkopp 34a1cfad29 lib: make parse_canframe CAN XL aware
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-28 22:00:19 +01:00
Oliver Hartkopp 3644a54d5b candump/lib: make sprint_long_canframe CAN XL aware
The 'long' CAN frame representation does not really fit for CAN XL content.
Therefore just a cropped output is provided to be able to see the CAN XL
header information and up to 64 byte of data (without binary or swap
formating options). To get the full qualified CAN XL content use the log
file format.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-27 20:11:46 +01:00
Oliver Hartkopp 04312e5a10 candump/lib: make sprint_canframe CAN XL aware
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-27 18:23:29 +01:00
Oliver Hartkopp 57238d5f81 candump: add sprintf error handling in sprint_timestamp
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-27 11:33:01 +01:00
Oliver Hartkopp c6cc7151b7 candump/lib: convert to single output buffer
Build the CAN frame ASCII output inside a single (big) buffer as
preparation for CAN XL support.

This unifies different output modes (fprintf/sprintf/printf) at
the time of the CAN frame text generation.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-27 09:29:49 +01:00
Oliver Hartkopp 2522ec127b lib: integrate CAN FD indicator into dual-use struct canfd_frame
Replace maxdlen parameter and use CANFD_FDF flags instead.

Since the CANFD_FDF flag has been introduced in can.h the struct canfd_frame
can be used for CAN CC and CAN FD frames as a dual-use data structure.

Remove the extra maxdlen parameter in library calls and only use the
CANFD_FDF flag to differentiate the two CAN CC/FD frames.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-24 11:28:35 +01:00
Marc Kleine-Budde 697901f9ef candump: convert towards kernel coding style 2023-12-11 09:37:09 +01:00
TyK ceda93bd5c timestamp formatting: always use 64-bit for timesstamp formatting.
Using C99 `unsigned long long` to format `struct timeval`'s `tv_sec`
and `tv_usec`, fix incorrect print under some 32bit platform which
 using time64.
2023-11-28 08:30:27 +08:00
Marc Kleine-Budde 6c7542a3ff candump: main(): use C99 initializers for struct sockaddr_can addr
By using C99 initializers for struct sockaddr_can addr the not
assigned members are automatically set to 0x0, resulting in not
passing uninitialized memory to the bind() syscall.
2023-07-04 09:19:08 +02:00
Yasushi SHOJI 4ec42fa089 candump: Follow Bash exit status when signaled
Bash and many other shells use 128 + signum as the exit status when a
program get signal and exit.  Follow the common behavior so that we
know how the programs are killed.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
2023-03-20 10:21:54 +09:00
Marc Kleine-Budde 92ae2b0e3d candump: sort getopt() by order of option in usage 2023-01-03 10:37:15 +01:00
Marc Kleine-Budde 306254b950 candump: checkpatch: fix space and newline usage
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2023-01-03 10:37:15 +01:00
Vincent Mailhol 4764212483 candump: use linux/net_tstamp.h instead of redefining values ourselves
The project contains a local copy of the timestamp header at
include/linux/net_tstamp.h. However, candump.c redefines the
net_tstamp.h values instead of relying on the header.

Replace these by a "include <linux/net_tstamp.h>".

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-7-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:49:52 +01:00
Vincent Mailhol 8e45fc5158 candump: add global variable progname
Instead of using argv[0] several time, make the progname a global
variable.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-6-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:49:52 +01:00
Vincent Mailhol 0cfd56d613 lib: add pr_debug() macro
Add the pr_debug() macro so that:

  #ifdef DEBUG
  	printf("foo");
  #endif

can be replaced by:

  	pr_debug("foo");

Apply the pr_debug() macro wherever relevant.

Currently, there is no consensus whether debug messages should be
printed on stdout or stderr. Most of the modules: canbusload.c,
candump.c and canlogserver.c use stdout but
mcp251xfd/mcp251xfd-dev-coredump.c uses stderr. Harmonize the behavior
by following the major trend and make
mcp251xfd/mcp251xfd-dev-coredump.c also output to stdout.

slcanpty.c does a #define DEBUG, meaning that debug is always turned
on for this file. Remove this and make debug an option like every
other files.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-5-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:49:52 +01:00
Marc Kleine-Budde e54d677999 candump: main(): fix scope of fname
Reported-by: https://github.com/HBLocker
Link: https://github.com/linux-can/can-utils/issues/379
2022-09-29 12:47:17 +02:00
Marc Kleine-Budde 2b5e93744b candump: reserve enough space for ctrlmsg
The ctrlmsg must be large enough to contains 3 elements of various
sizes, not a single element of the sum of the size.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-27 23:26:39 +02:00
Marc Kleine-Budde 0d26ba9ea3 candump: print number of dropped frames as unsigned values
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-27 23:25:18 +02:00
Oliver Hartkopp c70d0a8e61 candump: handle individual logfile name for stdout
Since commit ad250a68dc ("candump: add option to define individual
filename for logfile") the option "-f <fname>" allows to define an
individual filename for a logfile.

Usually the "-" is used as filename to represent stdout or stdin on
Linux/Posix systems to be able to concatenate several applications via
pipes. This patch handles this special case by detecting the filename
"-" to print the logfile format on stdout instead of creating a logfile
with the name "-".

Fixes: ad250a68dc ("candump: add option to define individual filename for logfile")
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2022-03-25 15:15:57 +01:00
Oliver Hartkopp 5e0895981b candump: fix accidentally disabled traffic timeout feature
With the option '-T <msecs>' candump terminates after getting no CAN traffic
for a specific time. With the introduction of epoll_wait() this feature
has been accidentally disabled.

This patch adds an extra check to detect the timeout again.

Fixes: 639498bc80 ("candump: use epoll_wait() instead of select()")
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2022-03-07 10:32:41 +01:00
Oliver Hartkopp ad250a68dc candump: add option to define individual filename for logfile
Link: https://github.com/linux-can/can-utils/pull/345
Suggested-by: https://github.com/xR3b0rn
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2022-02-16 11:46:46 +01:00
Oliver Hartkopp a705182b28 candump: trivial typo exchange sentence point with closing bracket
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2021-11-28 20:14:43 +01:00
Marc Kleine-Budde 1b4e317083 candump: fix epoll_wait() returning -1, errno == -EINTR
-EINTR is not an error, just restart the syscall.

Fixes: 639498bc80 ("candump: use epoll_wait() instead of select()")
Link: https://github.com/linux-can/can-utils/issues/296
Reported-by: Joakim Zhang <qiangqing.zhang@nxp.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2021-05-28 11:57:38 +02:00
Egor Kurnev bdf3e96ef9
Update candump.c 2021-04-14 18:49:49 +03:00
Richard Young eb66451df2 candump: Enable zero relative timestamps to be used in log files
The logfile format which is generated with '-l' and '-L' consists of an
absolute epoch timestamp. In some use cases (e.g. for documentation) a
zero relative timestamp can be useful which was only configurable with
the '-tz' option for the classic output.

'-tz' and '-ta' are now valid options for the logfile format.

Signed-off-by: Richard Young <code@richyoung.ca>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-12-08 20:52:54 +01:00
Marc Kleine-Budde bfaa44fa91 candump: convert to kernel codeing style
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2020-12-06 10:09:36 +01:00
Marc Kleine-Budde 305b2e8b79 candump: fix indention
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2020-12-06 09:58:52 +01:00
Marc Kleine-Budde 15f3a2e385 candump: remove trailing whitespace
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2020-12-06 09:57:52 +01:00
Jörg Hohensohn 639498bc80 candump: use epoll_wait() instead of select()
Using epoll_wait() instead of select() gives higher
performance for listening on multiple interfaces.
Additionally, the read order has a higher chance
to resemble the true temporal order.
select() gives implicit priority to the lower index socket.

Signed-off-by: Jörg Hohensohn <joerg.hohensohn@gmx.de>
2020-12-06 08:32:36 +01:00
Oliver Hartkopp 11edd1d05e candump: support len8_dlc for standard candump output
The display of Classical CAN raw DLC values is an expert feature which is
not enabled by default to not break toolchains that use the candump
standard output for further processing. (N.B. using the log file format and
the functions from lib.h/lib.c provide convenient CAN frame conversions)

After enabling the raw DLC for Classical CAN with the '-8' option the raw
DLC value is printed in 'unusual' curly braces {}.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-11-22 19:42:38 +01:00
Rosen Penev b153fe3f35
clang-tidy: sort includes alphabetically
Found with llvm-include-order

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:28:58 -07:00
Rosen Penev 3e85fc5422
clang-tidy: fix cmp function usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:28:58 -07:00
Oliver Hartkopp 7cb3e760fe logfile: add new extra info field
This patch adds a fourth string field in the can logfile format.
This new field contains the rx/tx direction information R/T as the
first entry (only one character separated from the CAN frame by space).

To generate the logfile format with this extra field candump has to be
called with the '-x' option for extra message infos,
e.g. 'candump -x -l can0' or 'candump -x -L can0'

log2asc and asc2log are extended to support the direction information
but still support the previous format without direction information.

The format extension does not affect legacy tools, e.g. the existing
canplayer ignores this extra information and does not need to be changed.

Therefore the existing logfiles remain valid and usable.

The extra message infos will be colon separated when there's need for
additional content beyond the rx/tx direction information, e.g. R:xx:yyy

Suggested-by: Pallavi Revanna https://github.com/brpallu
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-08-18 13:29:36 +02:00
Oliver Hartkopp a4905ed7c8 fix timeval to ASCII unsigned value conversion
As reported by Oleksij Rempel here
https://github.com/linux-can/can-utils/issues/233#issuecomment-674818935
the representation of timeval timestamps are signed values which leads to
negative values on 32 bit machines addressing the year 2038 unix sec counter
overflow.

Fix the issue on 32 bit systems by converting the timeval values to unsigned
ASCII value representations.

Fixes: https://github.com/linux-can/can-utils/issues/234
Reported-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-08-18 12:51:35 +02:00
Gary Bisson 46895a41c5 Fix comparison type mismatch warnings
Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
2020-05-28 20:54:37 +02:00
Oliver Hartkopp 819a03f6e2 candump: fix/unify help text indention
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-04-28 18:59:37 +02:00
Alexander GQ Gerasiov 6db632531d candump.c: Reformat help/usage output to be compatible with help2man.
Gbp-Pq: Name 0004-candump.c-Reformat-help-usage-output-to-be-compatibl.patch
2020-04-27 08:20:08 +03:00
Oliver Hartkopp a9985c7652 candump: remove bridging functionality
The tool 'candump' is used to dump CAN traffic to stdout or logfile.
In early days where the in-kernel CAN gateway (can-gw) with the cangw tool was
not yet implemented the bridging functionality allowed to send received (and
filtered) CAN frames to another outgoing CAN interface.

As we now have can-gw and sending CAN frames from a 'reading tool' seems wrong
especially from the Unix philosophy "Write programs that do one thing and do
it well." this patch removes the obsolete functionality from candump.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-01-04 14:11:34 +01:00
Yegor Yefremov 14ccc06eba Fix spelling in various files
codespell parameters:

codespell -q 3 --skip="*.in,*.sh,*.m4,config,configure,autom4te.cache"

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-11-11 14:21:49 +01:00
Oliver Hartkopp 319bd5de45 candump: silence format-overflow warning
When -Wformat-overflow= is enabled the gcc notes ...
"‘sprintf’ output between 30 and 82 bytes into a destination of size xx"
Increasing the buffer for the file name to 83 bytes removes the warning.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2019-08-23 19:57:06 +02:00
Oliver Hartkopp 83a1210b75 candump: preserve silent mode with enabled log file output format
As seen in https://github.com/linux-can/can-utils/issues/150 the logfile
format switch ignores the silent mode switch.

Fix this by checking the silent mode when using logfile format on stdout.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2019-08-23 19:40:27 +02:00
Oliver Hartkopp 818dacd78f candump: fix formatting of status messages regarding standard output
As remarked by Victor in https://github.com/linux-can/can-utils/issues/150
the output in the case of silent mode has puzzled line feeds.

Reported-by: Victor Cushman <VictorSCushman@gmail.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2019-08-23 19:34:10 +02:00
Yegor Yefremov 7b7331976a Add SPDX identifiers
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-06-19 12:24:24 +02:00
Oliver Hartkopp c45a17e96b candump: try to switch bridge socket into CAN FD mode
When using the -b/-B option to send received CAN frames to the brigde interface
the sending failed when processing CAN FD frames. This patch enables CAN FD on
the socket for the bridging interface.

https://github.com/linux-can/can-utils/issues/104

Reported-by: https://github.com/jm3lee
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2018-10-24 09:36:55 +02:00