summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2015-05-10 22:59:58 +0200
committerMarc Kleine-Budde <mkl@pengutronix.de>2015-05-10 23:21:13 +0200
commitf9d600c8ec852241139273e09822d582974a0c08 (patch)
tree89e7c5d71172fb87f952a7cb99a6a1d2269b46be
parent50d721b860dd8f7526534bea1a8fb8d65daea239 (diff)
downloadcanutils-f9d600c8ec852241139273e09822d582974a0c08.tar.gz
canutils-f9d600c8ec852241139273e09822d582974a0c08.tar.xz
cansequence: add support for drop after a certain number of incidents
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r--src/cansequence.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/cansequence.c b/src/cansequence.c
index 0939b9e..62eb744 100644
--- a/src/cansequence.c
+++ b/src/cansequence.c
@@ -31,7 +31,8 @@ static int s = -1;
static bool running = true;
static bool infinite = true;
static bool sequence_init = true;
-static bool quit = false;
+static unsigned int drop_until_quit;
+static unsigned int drop_count;
static bool use_poll = false;
static unsigned int loopcount = 1;
@@ -63,7 +64,7 @@ static void print_usage(char *prg)
" -r, --receive work as receiver\n"
" --loop=COUNT send message COUNT times\n"
" -p --poll use poll(2) to wait for buffer space while sending\n"
- " -q --quit quit if a wrong sequence is encountered\n"
+ " -q --quit <num> quit if <num> wrong sequences are encountered\n"
" -v, --verbose be verbose (twice to be even more verbose\n"
" -h --help this help\n"
" --version print version information and exit\n",
@@ -126,6 +127,8 @@ static void do_receive()
if (frame.data[0] != sequence) {
uint32_t overflows = 0;
+ drop_count++;
+
for (cmsg = CMSG_FIRSTHDR(&msg);
cmsg && (cmsg->cmsg_level == SOL_SOCKET);
cmsg = CMSG_NXTHDR(&msg,cmsg)) {
@@ -135,10 +138,10 @@ static void do_receive()
}
}
- fprintf(stderr, "received wrong sequence count. expected: %d, got: %d, socket overflows: %u\n",
- sequence, frame.data[0], overflows);
+ fprintf(stderr, "[%d] received wrong sequence count. expected: %d, got: %d, socket overflows: %u\n",
+ drop_count, sequence, frame.data[0], overflows);
- if (quit)
+ if (drop_count == drop_until_quit)
exit(EXIT_FAILURE);
sequence = frame.data[0];
@@ -219,7 +222,7 @@ int main(int argc, char **argv)
{ "extended", no_argument, 0, 'e' },
{ "help", no_argument, 0, 'h' },
{ "poll", no_argument, 0, 'p' },
- { "quit", no_argument, 0, 'q' },
+ { "quit", optional_argument, 0, 'q' },
{ "receive", no_argument, 0, 'r' },
{ "verbose", no_argument, 0, 'v' },
{ "version", no_argument, 0, VERSION_OPTION},
@@ -228,7 +231,7 @@ int main(int argc, char **argv)
{ 0, 0, 0, 0},
};
- while ((opt = getopt_long(argc, argv, "ehpqrvi:l:", long_options, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "ehpq:rvi:l:", long_options, NULL)) != -1) {
switch (opt) {
case 'e':
extended = true;
@@ -244,7 +247,10 @@ int main(int argc, char **argv)
break;
case 'q':
- quit = true;
+ if (optarg)
+ drop_until_quit = strtoul(optarg, NULL, 0);
+ else
+ drop_until_quit = 1;
break;
case 'r':