From f7f02257d155d61db5d99c265bff7a8d1f90b6ef Mon Sep 17 00:00:00 2001 From: shemminger Date: Thu, 2 Dec 2004 19:00:24 +0000 Subject: 1.0.5 updates --- brctl/Makefile.in | 4 +- brctl/brctl.c | 46 ++++++++---- brctl/brctl.h | 2 +- brctl/brctl_cmd.c | 42 +++++------ brctl/brctld.c | 208 ------------------------------------------------------ 5 files changed, 54 insertions(+), 248 deletions(-) delete mode 100644 brctl/brctld.c (limited to 'brctl') diff --git a/brctl/Makefile.in b/brctl/Makefile.in index 93618ec..e1956d6 100644 --- a/brctl/Makefile.in +++ b/brctl/Makefile.in @@ -18,13 +18,11 @@ INSTALL=@INSTALL@ common_SOURCES= brctl_cmd.c brctl_disp.c brctl_SOURCES= brctl.c $(common_SOURCES) -brctld_SOURCES= brctld.c $(common_SOURCES) common_OBJECTS= $(common_SOURCES:.c=.o) brctl_OBJECTS= $(brctl_SOURCES:.c=.o) -brctld_OBJECTS= $(brctld_SOURCES:.c=.o) -OBJECTS= $(common_OBJECTS) $(brctl_OBJECTS) $(brctld_OBJECTS) +OBJECTS= $(common_OBJECTS) $(brctl_OBJECTS) PROGRAMS= brctl diff --git a/brctl/brctl.c b/brctl/brctl.c index 11dc1f3..33c15fd 100644 --- a/brctl/brctl.c +++ b/brctl/brctl.c @@ -20,6 +20,8 @@ #include #include #include +#include + #include "libbridge.h" #include "config.h" @@ -27,39 +29,57 @@ static void help() { + printf("Usage: brctl [commands]\n"); printf("commands:\n"); command_helpall(); } -int main(int argc, char *argv[]) +int main(int argc, char *const* argv) { const struct command *cmd; + int f; + static const struct option options[] = { + { .name = "help", .val = 'h' }, + { .name = "version", .val = 'V' }, + { 0 } + }; - if (argc < 2) + while ((f = getopt_long(argc, argv, "Vh", options, NULL)) != EOF) + switch(f) { + case 'h': + help(); + return 0; + case 'V': + printf("%s, %s\n", PACKAGE, VERSION); + return 0; + default: + fprintf(stderr, "Unknown option '%c'\n", f); + goto help; + } + + if (argc == optind) goto help; - - if (strcmp(argv[1], "-V") == 0) { - printf("%s, %s\n", PACKAGE, VERSION); - return 0; - } - + if (br_init()) { fprintf(stderr, "can't setup bridge control: %s\n", strerror(errno)); return 1; } - if ((cmd = command_lookup(argv[1])) == NULL) { + argc -= optind; + argv += optind; + if ((cmd = command_lookup(*argv)) == NULL) { fprintf(stderr, "never heard of command [%s]\n", argv[1]); goto help; } - if (argc < cmd->nargs + 2) { - fprintf(stderr, "incorrect number of arguments for command\n"); - goto help; + if (argc < cmd->nargs + 1) { + printf("Incorrect number of arguments for command\n"); + printf("Usage: brctl %s %s\n", cmd->name, cmd->help); + return 1; } - return cmd->func(++argv); + return cmd->func(argc, argv); help: help(); diff --git a/brctl/brctl.h b/brctl/brctl.h index 8fdd9ef..55b7897 100644 --- a/brctl/brctl.h +++ b/brctl/brctl.h @@ -23,7 +23,7 @@ struct command { int nargs; const char *name; - int (*func)(char **argv); + int (*func)(int argc, char *const* argv); const char *help; }; diff --git a/brctl/brctl_cmd.c b/brctl/brctl_cmd.c index 9ab7166..f135282 100644 --- a/brctl/brctl_cmd.c +++ b/brctl/brctl_cmd.c @@ -35,7 +35,7 @@ static int strtotimeval(struct timeval *tv, const char *time) return 0; } -static int br_cmd_addbr(char** argv) +static int br_cmd_addbr(int argc, char*const* argv) { int err; @@ -54,7 +54,7 @@ static int br_cmd_addbr(char** argv) } } -static int br_cmd_delbr(char** argv) +static int br_cmd_delbr(int argc, char*const* argv) { int err; @@ -79,7 +79,7 @@ static int br_cmd_delbr(char** argv) } } -static int br_cmd_addif(char** argv) +static int br_cmd_addif(int argc, char *const* argv) { int err; @@ -109,7 +109,7 @@ static int br_cmd_addif(char** argv) } } -static int br_cmd_delif(char** argv) +static int br_cmd_delif(int argc, char *const* argv) { int err; @@ -132,7 +132,7 @@ static int br_cmd_delif(char** argv) } } -static int br_cmd_setageing(char** argv) +static int br_cmd_setageing(int argc, char *const* argv) { int err; struct timeval tv; @@ -150,7 +150,7 @@ static int br_cmd_setageing(char** argv) return err != 0; } -static int br_cmd_setbridgeprio(char** argv) +static int br_cmd_setbridgeprio(int argc, char *const* argv) { int prio; int err; @@ -167,7 +167,7 @@ static int br_cmd_setbridgeprio(char** argv) return err != 0; } -static int br_cmd_setfd(char** argv) +static int br_cmd_setfd(int argc, char *const* argv) { struct timeval tv; int err; @@ -185,7 +185,7 @@ static int br_cmd_setfd(char** argv) return err != 0; } -static int br_cmd_sethello(char** argv) +static int br_cmd_sethello(int argc, char *const* argv) { struct timeval tv; int err; @@ -203,7 +203,7 @@ static int br_cmd_sethello(char** argv) return err != 0; } -static int br_cmd_setmaxage(char** argv) +static int br_cmd_setmaxage(int argc, char *const* argv) { struct timeval tv; int err; @@ -220,7 +220,7 @@ static int br_cmd_setmaxage(char** argv) return err != 0; } -static int br_cmd_setpathcost(char** argv) +static int br_cmd_setpathcost(int argc, char *const* argv) { int cost, err; @@ -236,7 +236,7 @@ static int br_cmd_setpathcost(char** argv) return err != 0; } -static int br_cmd_setportprio(char** argv) +static int br_cmd_setportprio(int argc, char *const* argv) { int cost, err; @@ -253,7 +253,7 @@ static int br_cmd_setportprio(char** argv) return err != 0; } -static int br_cmd_stp(char** argv) +static int br_cmd_stp(int argc, char *const* argv) { int stp, err; @@ -275,7 +275,7 @@ static int br_cmd_stp(char** argv) return err != 0; } -static int br_cmd_showstp(char** argv) +static int br_cmd_showstp(int argc, char *const* argv) { struct bridge_info info; @@ -309,7 +309,7 @@ static int show_bridge(const char *name, void *arg) return 0; } -static int br_cmd_show(char** argv) +static int br_cmd_show(int argc, char *const* argv) { printf("bridge name\tbridge id\t\tSTP enabled\tinterfaces\n"); br_foreach_bridge(show_bridge, NULL); @@ -324,7 +324,7 @@ static int compare_fdbs(const void *_f0, const void *_f1) return memcmp(f0->mac_addr, f1->mac_addr, 6); } -static int br_cmd_showmacs(char** argv) +static int br_cmd_showmacs(int argc, char *const* argv) { const char *brname = argv[1]; #define CHUNK 128 @@ -394,7 +394,7 @@ static const struct command commands[] = { "\t\tshow a list of mac addrs"}, { 1, "showstp", br_cmd_showstp, "\t\tshow bridge stp info"}, - { 1, "stp", br_cmd_stp, + { 2, "stp", br_cmd_stp, " \tturn stp on/off" }, }; @@ -410,15 +410,11 @@ const struct command *command_lookup(const char *cmd) return NULL; } -void command_help(const struct command *cmd) -{ - printf("\t%-10s\t%s\n", cmd->name, cmd->help); -} - void command_helpall(void) { int i; - for (i = 0; i < sizeof(commands)/sizeof(commands[0]); i++) - command_help(commands+i); + for (i = 0; i < sizeof(commands)/sizeof(commands[0]); i++) { + printf("\t%-10s\t%s\n", commands[i].name, commands[i].help); + } } diff --git a/brctl/brctld.c b/brctl/brctld.c deleted file mode 100644 index f2b4e45..0000000 --- a/brctl/brctld.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2000 Lennert Buytenhek - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libbridge.h" -#include "brctl.h" - -char *help_message = -"addbr\t\t\t\t\tadd bridge\n" -"addif\t\t\t\tadd interface to bridge\n" -"bridge\t\t\t\tselect bridge to work in\n" -"delbr\t\t\t\t\tdelete bridge\n" -"delif\t\t\t\tdelete interface from bridge\n" -"setageing\t\t