summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2008-09-29 07:53:31 +0000
committerMarc Kleine-Budde <mkl@pengutronix.de>2008-09-29 07:53:31 +0000
commit6142e1d8df28746140ff87213e5461f346e91fa5 (patch)
treef02bf271b57546ba757025bea96872a5a6e985dd
parentae8ffb7f1ed2ab730d2b71d904e6b0d280738154 (diff)
downloadcanutils-6142e1d8df28746140ff87213e5461f346e91fa5.tar.gz
* src/cansequence.c, src/cansend.c:
fix interface cmd line git-svn-id: https://iocaste.extern.pengutronix.de/svn/canutils/trunks/canutils-3.0-trunk@95 5fd5a299-6ef2-0310-aa18-8b01d7c39d8c
-rw-r--r--src/cansend.c22
-rw-r--r--src/cansequence.c20
2 files changed, 29 insertions, 13 deletions
diff --git a/src/cansend.c b/src/cansend.c
index ffb888a..3081dd5 100644
--- a/src/cansend.c
+++ b/src/cansend.c
@@ -33,8 +33,8 @@ static void print_usage(char *prg)
" -f, --family=FAMILY Protocol family (default PF_CAN = %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"
- " -l COUNT send message COUNT times, infinite if omitted\n"
- " --loop=COUNT \n"
+ " -l send message infinite times\n"
+ " --loop=COUNT send message COUNT times\n"
" -v, --verbose be verbose\n"
" -h, --help this help\n"
" --version print version information and exit\n",
@@ -52,7 +52,7 @@ int main(int argc, char **argv)
};
struct ifreq ifr;
struct sockaddr_can addr;
- char *interface = "can0";
+ char *interface;
int family = PF_CAN, type = SOCK_RAW, proto = CAN_RAW;
int loopcount = 1, infinite = 0;
int s, opt, ret, i, dlc = 0, rtr = 0, extended = 0;
@@ -68,11 +68,11 @@ int main(int argc, char **argv)
{ "type", required_argument, 0, 't' },
{ "version", no_argument, 0, VERSION_OPTION},
{ "verbose", no_argument, 0, 'v'},
- { "loop", optional_argument, 0, 'l'},
+ { "loop", required_argument, 0, 'l'},
{ 0, 0, 0, 0 },
};
- while ((opt = getopt_long(argc, argv, "hf:t:p:vi:l::re", long_options, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "hf:t:p:vi:lre", long_options, NULL)) != -1) {
switch (opt) {
case 'h':
print_usage(basename(argv[0]));
@@ -122,8 +122,16 @@ int main(int argc, char **argv)
}
}
- if (optind != argc)
- interface = argv[optind];
+ if (optind == argc) {
+ print_usage(basename(argv[0]));
+ exit(0);
+ }
+
+ if (argv[optind] == NULL) {
+ fprintf(stderr, "No Interface supplied\n");
+ exit(-1);
+ }
+ interface = argv[optind];
printf("interface = %s, family = %d, type = %d, proto = %d\n",
interface, family, type, proto);
diff --git a/src/cansequence.c b/src/cansequence.c
index 8395c65..30b5cd6 100644
--- a/src/cansequence.c
+++ b/src/cansequence.c
@@ -42,8 +42,8 @@ void print_usage(char *prg)
" -t, --type=TYPE Socket type, see man 2 socket (default SOCK_RAW = %d)\n"
" -p, --protocol=PROTO CAN protocol (default CAN_RAW = %d)\n"
" -r, --receive work as receiver\n"
- " -l COUNT send COUNT messages, infinite if omitted\n"
- " --loop=COUNT \n"
+ " -l send message infinite times\n"
+ " --loop=COUNT send message COUNT times\n"
" -q --quit quit if a wrong sequence is encountered\n"
" -v, --verbose be verbose (twice to be even more verbose\n"
" -h --help this help\n"
@@ -82,12 +82,12 @@ int main(int argc, char **argv)
{ "version", no_argument, 0, VERSION_OPTION},
{ "receive", no_argument, 0, 'r'},
{ "quit", no_argument, 0, 'q'},
- { "loop", optional_argument, 0, 'l'},
+ { "loop", required_argument, 0, 'l'},
{ "verbose", no_argument, 0, 'v'},
{ 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:vrlhq", long_options, NULL)) != -1) {
switch (opt) {
case 'h':
print_usage(basename(argv[0]));
@@ -134,8 +134,16 @@ int main(int argc, char **argv)
}
}
- if (optind != argc)
- interface = argv[optind];
+ if (optind == argc) {
+ print_usage(basename(argv[0]));
+ exit(0);
+ }
+
+ if (argv[optind] == NULL) {
+ fprintf(stderr, "No Interface supplied\n");
+ exit(-1);
+ }
+ interface = argv[optind];
printf("interface = %s, family = %d, type = %d, proto = %d\n",
interface, family, type, proto);