Compare commits

...

8 Commits

Author SHA1 Message Date
Mathew 7bcc46dacb
Merge 0cfff2e5da into a24bff8b08 2025-03-01 23:28:39 +01:00
Marc Kleine-Budde a24bff8b08
Merge pull request #582 from yegorich/clangd
CMakeLists.txt: enable CMAKE_EXPORT_COMPILE_COMMANDS by default
2025-03-01 16:47:48 +01:00
Yegor Yefremov fe9ea67814 CMakeLists.txt: enable CMAKE_EXPORT_COMPILE_COMMANDS by default
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2025-03-01 16:15:08 +01:00
Marc Kleine-Budde 6050aa155d
Merge pull request #581 from yegorich/cmake-linting
CMakeLists.txt: remove unneeded spaces
2025-03-01 12:33:50 +01:00
Yegor Yefremov 302184f383 CMakeLists.txt: remove unneeded spaces
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2025-03-01 10:51:12 +01:00
Oliver Hartkopp c542c9ada7 gitignore: remove accidentally added Makefile item
Fixes: 4577316bd6 ("Update .gitignore")
Link: https://github.com/linux-can/can-utils/pull/577#issuecomment-2690362731
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-02-28 21:34:03 +01:00
Mateusz Juzwiak 0cfff2e5da isotpsniffer: change -q to -i parameter, const buffer size 2024-09-26 14:31:06 +02:00
Mateusz Juzwiak 1e2c8fea4c isotpsniffer: option for no quitting on invalid message received 2024-07-19 05:37:53 -04:00
3 changed files with 36 additions and 18 deletions

1
.gitignore vendored
View File

@ -6,7 +6,6 @@
.ccls-cache
CMakeCache.txt
CMakeFiles/
Makefile
cmake_install.cmake
compile_commands.json
tags

View File

@ -4,14 +4,18 @@ project(can-utils LANGUAGES C)
message(STATUS "CMake version: ${CMAKE_VERSION}")
include (CheckFunctionExists)
include (CheckSymbolExists)
include (GNUInstallDirs)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(GNUInstallDirs)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(CMAKE_EXPORT_COMPILE_COMMANDS STREQUAL "")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "project default" FORCE)
endif()
# Add an option to enable treating warnings as errors
option(ENABLE_WERROR "Treat all compiler warnings as errors" OFF)
@ -32,8 +36,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCLOCK_TAI=11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSO_TXTIME=61")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSCM_TXTIME=SO_TXTIME")
include_directories (.)
include_directories (./include)
include_directories(.)
include_directories(./include)
check_function_exists(fork HAVE_FORK)

View File

@ -59,6 +59,7 @@
#include <linux/can.h>
#include <linux/can/isotp.h>
#include <linux/sockios.h>
#include <errno.h>
#define NO_CAN_ID 0xFFFFFFFFU
@ -66,6 +67,8 @@
#define FORMAT_ASCII 2
#define FORMAT_DEFAULT (FORMAT_ASCII | FORMAT_HEX)
#define PDU_BUF_SIZE 4096
void print_usage(char *prg)
{
fprintf(stderr, "\nUsage: %s [options] <CAN interface>\n", prg);
@ -79,6 +82,7 @@ void print_usage(char *prg)
fprintf(stderr, " -f <format> (1 = HEX, 2 = ASCII, 3 = HEX & ASCII - default: %d)\n", FORMAT_DEFAULT);
fprintf(stderr, " -L (set link layer options for CAN FD)\n");
fprintf(stderr, " -h <len> (head: print only first <len> bytes)\n");
fprintf(stderr, " -i (ignore syscall errors to receive malformed PDUs)\n");
fprintf(stderr, "\nCAN IDs and addresses are given and expected in hexadecimal values.\n");
fprintf(stderr, "\n");
}
@ -189,15 +193,16 @@ int main(int argc, char **argv)
int head = 0;
int timestamp = 0;
int format = FORMAT_DEFAULT;
int ignore_errors = 0;
canid_t src = NO_CAN_ID;
canid_t dst = NO_CAN_ID;
extern int optind, opterr, optopt;
static struct timeval tv, last_tv;
unsigned char buffer[4096];
unsigned char buffer[PDU_BUF_SIZE];
int nbytes;
while ((opt = getopt(argc, argv, "s:d:x:X:h:ct:f:L?")) != -1) {
while ((opt = getopt(argc, argv, "s:d:x:X:h:ct:f:L?i")) != -1) {
switch (opt) {
case 's':
src = strtoul(optarg, NULL, 16);
@ -249,6 +254,10 @@ int main(int argc, char **argv)
}
break;
case 'i':
ignore_errors = 1;
break;
case '?':
print_usage(basename(argv[0]));
goto out;
@ -367,31 +376,37 @@ int main(int argc, char **argv)
}
if (FD_ISSET(s, &rdfs)) {
nbytes = read(s, buffer, 4096);
nbytes = read(s, buffer, PDU_BUF_SIZE);
if (nbytes < 0) {
perror("read socket s");
r = 1;
if(!ignore_errors)
goto out;
}
if (nbytes > 4095) {
if (nbytes > (PDU_BUF_SIZE - 1)) {
r = 1;
fprintf(stderr, "PDU length %d longer than PDU buffer: %s\n", nbytes, strerror(errno));
goto out;
}
if(nbytes > 0)
printbuf(buffer, nbytes, color?2:0, timestamp, format,
&tv, &last_tv, dst, s, if_name, head);
}
if (FD_ISSET(t, &rdfs)) {
nbytes = read(t, buffer, 4096);
nbytes = read(t, buffer, PDU_BUF_SIZE);
if (nbytes < 0) {
perror("read socket t");
r = 1;
if(!ignore_errors)
goto out;
}
if (nbytes > 4095) {
if (nbytes > (PDU_BUF_SIZE - 1)) {
r = 1;
fprintf(stderr, "PDU length %d longer than PDU buffer: %s\n", nbytes, strerror(errno));
goto out;
}
if(nbytes > 0)
printbuf(buffer, nbytes, color?1:0, timestamp, format,
&tv, &last_tv, src, t, if_name, head);
}