bridge-utils update to 1.5
[tomato.git] / release / src / router / bridge / brctl / brctl.c
blob454b8dd686f7efc62c11afd91059ccdd1ba1551d
1 /*
2 * Copyright (C) 2000 Lennert Buytenhek
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/errno.h>
23 #include <getopt.h>
25 #include "libbridge.h"
26 #include "config.h"
28 #include "brctl.h"
30 static void help()
32 printf("Usage: brctl [commands]\n");
33 printf("commands:\n");
34 command_helpall();
37 int main(int argc, char *const* argv)
39 const struct command *cmd;
40 int f;
41 static const struct option options[] = {
42 { .name = "help", .val = 'h' },
43 { .name = "version", .val = 'V' },
44 { 0 }
47 while ((f = getopt_long(argc, argv, "Vh", options, NULL)) != EOF)
48 switch(f) {
49 case 'h':
50 help();
51 return 0;
52 case 'V':
53 printf("%s, %s\n", PACKAGE_NAME, PACKAGE_VERSION);
54 return 0;
55 default:
56 fprintf(stderr, "Unknown option '%c'\n", f);
57 goto help;
60 if (argc == optind)
61 goto help;
63 if (br_init()) {
64 fprintf(stderr, "can't setup bridge control: %s\n",
65 strerror(errno));
66 return 1;
69 argc -= optind;
70 argv += optind;
71 if ((cmd = command_lookup(*argv)) == NULL) {
72 fprintf(stderr, "never heard of command [%s]\n", argv[1]);
73 goto help;
76 if (argc < cmd->nargs + 1) {
77 printf("Incorrect number of arguments for command\n");
78 printf("Usage: brctl %s %s\n", cmd->name, cmd->help);
79 return 1;
82 return cmd->func(argc, argv);
84 help:
85 help();
86 return 1;