* src/cansequence.c, src/cansend.c:

cleanups

git-svn-id: https://iocaste.extern.pengutronix.de/svn/canutils/trunks/canutils-3.0-trunk@90 5fd5a299-6ef2-0310-aa18-8b01d7c39d8c
pull/254/head^2
Marc Kleine-Budde 2008-09-09 15:18:51 +00:00
parent d8be4d8a4f
commit bd3ea25fe1
1 changed files with 81 additions and 76 deletions

View File

@ -24,8 +24,7 @@ extern int optind, opterr, optopt;
static int s = -1; static int s = -1;
static int running = 1; static int running = 1;
enum enum {
{
VERSION_OPTION = CHAR_MAX + 1, VERSION_OPTION = CHAR_MAX + 1,
}; };
@ -43,7 +42,8 @@ void print_usage(char *prg)
" -t, --type=TYPE Socket type, see man 2 socket (default SOCK_RAW = %d)\n" " -t, --type=TYPE Socket type, see man 2 socket (default SOCK_RAW = %d)\n"
" -p, --protocol=PROTO CAN protocol (default CAN_RAW = %d)\n" " -p, --protocol=PROTO CAN protocol (default CAN_RAW = %d)\n"
" -r, --receive work as receiver\n" " -r, --receive work as receiver\n"
" -l --loop=COUNT send COUNT messages\n" " -l COUNT send COUNT messages, infinite if omitted\n"
" --loop=COUNT \n"
" -q --quit quit if a wrong sequence is encountered\n" " -q --quit quit if a wrong sequence is encountered\n"
" -v, --verbose be verbose (twice to be even more verbose\n" " -v, --verbose be verbose (twice to be even more verbose\n"
" -h --help this help\n" " -h --help this help\n"
@ -65,7 +65,7 @@ int main(int argc, char **argv)
int nbytes; int nbytes;
struct ifreq ifr; struct ifreq ifr;
int receive = 0; int receive = 0;
int loopcount = 1, infinite = 1; int loopcount = 1, infinite;
unsigned char sequence = 0; unsigned char sequence = 0;
int sequence_init = 1; int sequence_init = 1;
int verbose = 0, quit = 0; int verbose = 0, quit = 0;
@ -81,12 +81,12 @@ int main(int argc, char **argv)
{ "version", no_argument, 0, VERSION_OPTION}, { "version", no_argument, 0, VERSION_OPTION},
{ "receive", no_argument, 0, 'r'}, { "receive", no_argument, 0, 'r'},
{ "quit", no_argument, 0, 'q'}, { "quit", no_argument, 0, 'q'},
{ "loop", required_argument, 0, 'l'}, { "loop", optional_argument, 0, 'l'},
{ "verbose", no_argument, 0, 'v'}, { "verbose", no_argument, 0, 'v'},
{ 0, 0, 0, 0}, { 0, 0, 0, 0},
}; };
while ((opt = getopt_long(argc, argv, "f:t:p:vrl:hq", long_options, NULL)) != -1) { while ((opt = getopt_long(argc, argv, "f:t:p:vrl::hq", long_options, NULL)) != -1) {
switch (opt) { switch (opt) {
case 'h': case 'h':
print_usage(basename(argv[0])); print_usage(basename(argv[0]));
@ -105,8 +105,10 @@ int main(int argc, char **argv)
break; break;
case 'l': case 'l':
if (optarg)
loopcount = strtoul(optarg, NULL, 0); loopcount = strtoul(optarg, NULL, 0);
infinite = 0; else
infinite = 1;
break; break;
case 'r': case 'r':
@ -138,7 +140,9 @@ int main(int argc, char **argv)
printf("interface = %s, family = %d, type = %d, proto = %d\n", printf("interface = %s, family = %d, type = %d, proto = %d\n",
argv[optind], family, type, proto); argv[optind], family, type, proto);
if ((s = socket(family, type, proto)) < 0) {
s = socket(family, type, proto);
if (s < 0) {
perror("socket"); perror("socket");
return 1; return 1;
} }
@ -155,7 +159,8 @@ int main(int argc, char **argv)
if (receive) { if (receive) {
while ((infinite || loopcount--) && running) { while ((infinite || loopcount--) && running) {
if ((nbytes = read(s, &frame, sizeof(struct can_frame))) < 0) { nbytes = read(s, &frame, sizeof(struct can_frame);
if (nbytes < 0) {
perror("read"); perror("read");
return 1; return 1;
} else { } else {