diff options
author | shemminger <shemminger> | 2004-12-02 19:00:24 +0000 |
---|---|---|
committer | shemminger <shemminger> | 2004-12-02 19:00:24 +0000 |
commit | f7f02257d155d61db5d99c265bff7a8d1f90b6ef (patch) | |
tree | 256abd9c18bf6fc4c70a72669b8452a1b92f971d /brctl | |
parent | 722fb5b06f1634e587d4e2605ea17e855f7f6e35 (diff) | |
download | android_external_brctl-f7f02257d155d61db5d99c265bff7a8d1f90b6ef.tar.gz android_external_brctl-f7f02257d155d61db5d99c265bff7a8d1f90b6ef.tar.bz2 android_external_brctl-f7f02257d155d61db5d99c265bff7a8d1f90b6ef.zip |
1.0.5 updates
Diffstat (limited to 'brctl')
-rw-r--r-- | brctl/Makefile.in | 4 | ||||
-rw-r--r-- | brctl/brctl.c | 46 | ||||
-rw-r--r-- | brctl/brctl.h | 2 | ||||
-rw-r--r-- | brctl/brctl_cmd.c | 42 | ||||
-rw-r--r-- | brctl/brctld.c | 208 |
5 files changed, 54 insertions, 248 deletions
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 <stdlib.h> #include <string.h> #include <sys/errno.h> +#include <getopt.h> + #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[] = { "<bridge>\t\tshow a list of mac addrs"}, { 1, "showstp", br_cmd_showstp, "<bridge>\t\tshow bridge stp info"}, - { 1, "stp", br_cmd_stp, + { 2, "stp", br_cmd_stp, "<bridge> <state>\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 <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <netinet/in.h> -#include <signal.h> -#include <sys/resource.h> -#include <sys/time.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <unistd.h> -#include <asm/param.h> -#include "libbridge.h" -#include "brctl.h" - -char *help_message = -"addbr\t\t\t\t\tadd bridge\n" -"addif\t\t\t<device>\tadd interface to bridge\n" -"bridge\t\t\t<bridge>\tselect bridge to work in\n" -"delbr\t\t\t\t\tdelete bridge\n" -"delif\t\t\t<device>\tdelete interface from bridge\n" -"setageing\t\t<time>\t\tset ageing time\n" -"setbridgeprio\t\t<prio>\t\tset bridge priority\n" -"setfd\t\t\t<time>\t\tset bridge forward delay\n" -"setgcint\t\t<time>\t\tset garbage collection interval\n" -"sethello\t\t<time>\t\tset hello time\n" -"setmaxage\t\t<time>\t\tset max message age\n" -"setpathcost\t\t<port> <cost>\tset path cost\n" -"setportprio\t\t<port> <prio>\tset port priority\n" -"show\t\t\t\t\tshow a list of bridges\n" -"showmacs\t\t\t\tshow a list of mac addrs\n" -"showstp\t\t\t\t\tshow bridge stp info\n" -"stp\t\t\t<state>\t\tturn stp on/off\n" -"quit\t\t\t\t\texit this session\n" -"\n"; - -void help() -{ - fprintf(stderr, help_message); -} - -struct bridge *br = NULL; - -int forkaway() -{ - int f; - - f = fork(); - if (f < 0) { - perror("fork"); - exit(-1); - } - - return f; -} - -void runchild(int sock) -{ - char hostname[128]; - - if (forkaway()) - return; - - /* Hack. */ - close(0); dup(sock); - close(1); dup(sock); - close(2); dup(sock); - - br_init(); - gethostname(hostname, 128); - - printf("\n\n\n\n"); - printf("brctld\t\tCopyright (C) 2000 Lennert Buytenhek <buytenh@gnu.org>\n"); - printf("======================================================================"); - printf("\n\n\n\n"); - - while (1) { - char arg0[128]; - char arg1[128]; - char cmd[128]; - struct command *cmdptr; - char line[1024]; - int numcmd; - - printf("<%s> ", hostname); - fflush(stdout); - line[1023] = 0; - fgets(line, 1023, stdin); - while (strlen(line) > 0 && - (line[strlen(line)-1] == '\r' || - line[strlen(line)-1] == '\n')) - line[strlen(line)-1] = 0; - - numcmd = sscanf(line, "%s %s %s", cmd, arg0, arg1); - - if (!strcmp(cmd, "help")) { - help(); - continue; - } else if (!strcmp(cmd, "bridge")) { - if (numcmd != 2) { - fprintf(stderr, "invalid number of arguments\n"); - continue; - } - - br = br_find_bridge(arg0); - if (br != NULL) - printf("now using bridge %s\n\n", arg0); - else - printf("can't find bridge %s\n\n", arg0); - continue; - } else if (!strcmp(cmd, "quit")) { - break; - } - - if ((cmdptr = br_command_lookup(cmd)) == NULL) { - printf("unknown command '%s'\n\n", line); - continue; - } - - if (cmdptr->needs_bridge_argument && br == NULL) { - printf("this command needs a bridge\n\n"); - continue; - } - - br_refresh(); - cmdptr->func(br, arg0, arg1); - printf("\n"); - } - - shutdown(sock, 2); - exit(0); -} - -void sigchild(int sig) -{ - int status; - - wait3(&status, WNOHANG, NULL); -} - -int main(int argc, char *argv[]) -{ - struct sockaddr_in addr; - int sock; - int x; - - if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - perror("socket"); - return 1; - } - - x = 1; - if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)) < 0) { - perror("setsockopt"); - return 1; - } - - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(INADDR_ANY); - addr.sin_port = htons(31338); - if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror("bind"); - return 1; - } - - if (listen(sock, 1) < 0) { - perror("listen"); - return 1; - } - - if (forkaway()) - return 0; - - setsid(); - signal(SIGCHLD, sigchild); - - while (1) { - int len; - int newsock; - - len = sizeof(addr); - if ((newsock = accept(sock, (struct sockaddr *)&addr, &len)) < 0) { - perror("accept"); - return 1; - } - - runchild(newsock); - } - - return 0; -} |