" generation mode - see below)\n");
fprintf(stderr, " -p <timeout> (poll on -ENOBUFS to write frames"
" with <timeout> ms)\n");
+ fprintf(stderr, " -n <count> (terminate after <count> CAN frames "
+ "- default infinite)\n");
fprintf(stderr, " -i (ignore -ENOBUFS return values on"
" write() syscalls)\n");
fprintf(stderr, " -x (disable local loopback of "
unsigned char dlc_mode = MODE_RANDOM;
unsigned char loopback_disable = 0;
unsigned char verbose = 0;
+ int count = 0;
uint64_t incdata = 0;
int opt;
struct ifreq ifr;
struct timespec ts;
+ struct timeval now;
+
+ /* set seed value for pseudo random numbers */
+ gettimeofday(&now, NULL);
+ srandom(now.tv_usec);
signal(SIGTERM, sigterm);
signal(SIGHUP, sigterm);
signal(SIGINT, sigterm);
- while ((opt = getopt(argc, argv, "ig:eI:L:D:xp:vh?")) != -1) {
+ while ((opt = getopt(argc, argv, "ig:eI:L:D:xp:n:vh?")) != -1) {
switch (opt) {
case 'i':
polltimeout = strtoul(optarg, NULL, 10);
break;
+ case 'n':
+ count = atoi(optarg);
+ if (count < 1) {
+ print_usage(basename(argv[0]));
+ return 1;
+ }
+ break;
+
case '?':
case 'h':
default:
while (running) {
+ if (count && (--count == 0))
+ running = 0;
+
if (id_mode == MODE_RANDOM) {
frame.can_id = random();
fprint_canframe(stdout, &frame, "\n", 1);
}
+resend:
nbytes = write(s, &frame, sizeof(struct can_frame));
if (nbytes < 0) {
if (errno != ENOBUFS) {
if (poll(&fds, 1, polltimeout) < 0) {
perror("poll");
return 1;
- }
+ } else
+ goto resend;
} else
enobufs_count++;