*.o
+*.lo
*~
+.*.swp
*.so
*.a
-admin
-ngdump
+*.la
+*.pc
+ngcli
+ngspy
lib/doc/
raw/doc/
-brouillon
+*.m4
+m4/
+config.*
+autom4te.cache/
+configure
+Makefile
+Makefile.in
+autoscan.log
+configure.scan
+compile
+install-sh
+ltmain.sh
+missing
+depcomp
+build-aux/
+libtool
+stamp-h1
+.deps/
+.libs/
--- /dev/null
+Hervé Boisse <admin@darkcoven.tk>
--- /dev/null
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
+++ /dev/null
-
-
-all: raw lib libdoc cli
-
-
-
-raw: force
- @+$(MAKE) -C raw lib
-
-
-lib: raw force
- @+$(MAKE) -C lib lib
-
-
-libdoc: force
- @+$(MAKE) -C lib libdoc
-
-
-cli: lib force
- @+$(MAKE) -C cli
-
-
-dump: raw force
- @+$(MAKE) -C dump
-
-
-force:
- @true
-
-
-clean:
- @+$(MAKE) -C raw clean
- @+$(MAKE) -C lib clean
- @+$(MAKE) -C cli clean
- @+$(MAKE) -C dump clean
-
-mrproper: clean
- @+$(MAKE) -C raw mrproper
- @+$(MAKE) -C lib mrproper
- @+$(MAKE) -C cli mrproper
- @+$(MAKE) -C dump mrproper
-
-
--- /dev/null
+
+ACLOCAL_AMFLAGS = -I .
+
+SUBDIRS = raw lib cli
+
+if ENABLE_SPY
+SUBDIRS += spy
+endif
+
+if ENABLE_EMU
+SUBDIRS += emu
+endif
+
+++ /dev/null
-
-CC=gcc
-CFLAGS=-I../lib/include/ -W -Wall -Wextra -Os
-LDFLAGS=-L../lib -lngadmin -lreadline
-EXEC=admin
-
-SRC=$(wildcard *.c)
-OBJ=$(SRC:.c=.o)
-
-
-ifeq ($(DEBUG), yes)
-CFLAGS+=-g
-LDFLAGS+=-g
-else
-CFLAGS+=-fomit-frame-pointer
-LDFLAGS+=-s
-endif
-
-
-$(EXEC): $(OBJ)
- $(CC) $^ -o $@ $(LDFLAGS)
-
-%.o: %.c
- $(CC) -c $^ -o $@ $(CFLAGS)
-
-
-clean:
- @rm -f *.o
-
-mrproper: clean
- @rm -f $(EXEC)
-
-
-
--- /dev/null
+
+SUBDIRS = man src
+
+++ /dev/null
-
-#include <stdio.h>
-#include <signal.h>
-#include <unistd.h>
-#include <setjmp.h>
-
-#include <getopt.h>
-#include <readline/readline.h>
-#include <readline/history.h>
-
-#include "common.h"
-#include "commands.h"
-
-
-#define MAXCOM 32
-
-
-
-static const struct TreeNode* getSubCom (char **com, int n, int *t)
-{
- int i;
- const struct TreeNode *cur, *next;
-
-
- cur = &commands;
- for (i = 0; i < n; i++) {
- /* we have reached a terminal command, exit */
- if (cur->sub == NULL)
- break;
-
- /* search sub command in sub command array */
- for (next = cur->sub; next->name != NULL && strcmp(next->name, com[i]) != 0; next++);
-
- /* sub command not found, exit */
- if (next->name == NULL)
- break;
-
- /* next command is now the current one */
- cur = next;
- }
-
- *t = i;
-
-
- return cur;
-}
-
-
-static const struct TreeNode *compcur;
-
-
-static char* my_generator (const char* text, int state)
-{
- static int len;
- static const struct TreeNode *tn;
- const char *name;
-
-
- if (compcur == NULL) {
- /* sub command not found */
- return NULL;
- } else if (state == 0) {
- tn = compcur->sub;
- len = strlen(text);
- }
-
- if (tn == NULL) /* terminal command */
- return NULL;
-
- while ((name = tn++->name) != NULL) {
- if (strncmp(name, text, len) == 0)
- return strdup(name);
- }
-
-
- return NULL;
-}
-
-
-static char** my_completion (const char *text, int start, int end UNUSED)
-{
- char **matches = NULL;
- char *line, *com[MAXCOM];
- int i, n;
-
-
- memset(com, 0, MAXCOM * sizeof(char*));
- line = strdup(rl_line_buffer);
- line[start] = '\0';
- trim(line, start);
- n = explode(line, com, MAXCOM);
- free(line);
-
- compcur = getSubCom(com, n, &i);
-
- if (i < n)
- compcur = NULL;
- matches = rl_completion_matches(text, my_generator);
-
- for (i = 0; com[i] != NULL; i++)
- free(com[i]);
-
-
- return matches;
-}
-
-
-int main_loop_continue;
-static struct ngadmin *nga;
-static sigjmp_buf jmpbuf;
-static struct termios orig_term;
-struct termios current_term;
-static bool batch;
-
-
-NORET static void handler (int sig)
-{
- switch (sig) {
-
- case SIGTERM:
- case SIGINT:
- printf("interrupt\n");
-
- current_term.c_lflag |= ECHO;
- tcsetattr(STDIN_FILENO, TCSANOW, ¤t_term);
-
- if (!batch && main_loop_continue)
- siglongjmp(jmpbuf, 1);
-
- default:
- ngadmin_close(nga);
-
- tcsetattr(STDIN_FILENO, TCSANOW, &orig_term);
-
- exit(0);
- }
-}
-
-
-static int pre_login (const struct ether_addr *mac, int retries)
-{
- const struct swi_attr *sa;
- int i, n, err;
-
-
- for (i = 1; retries <= 0 || i <= retries; i++) {
- /* scan */
- printf("scan... ");
- fflush(stdout);
- err = ngadmin_scan(nga);
- if (err < 0) {
- printErrCode(err);
- return err;
- }
-
- /* search switch with requested MAC */
- sa = ngadmin_getSwitchTab(nga, &n);
- while (--n >= 0) {
- if (memcmp(mac, &sa[n].mac, ETH_ALEN) == 0)
- break;
- }
-
- if (n < 0) {
- printf("no switch found\n");
- } else {
- printf("done\n");
- break;
- }
- }
-
- if (n < 0)
- return 1;
-
- /* login */
- printf("login... ");
- fflush(stdout);
- err = ngadmin_login(nga, n);
- if (err < 0)
- printErrCode(err);
- else
- printf("done\n");
-
- return err;
-}
-
-
-int main (int argc, char **argv)
-{
- static const struct option opts[] = {
- {"batch", no_argument, NULL, 'a'},
- {"keep-broadcasting", no_argument, NULL, 'b'},
- {"force-interface", no_argument, NULL, 'f'},
- {"help", no_argument, NULL, 'h'},
- {"interface", required_argument, NULL, 'i'},
- {"local-broadcast", no_argument, NULL, 'l'},
- {"mac", required_argument, NULL, 'm'},
- {"password", required_argument, NULL, 'p'},
- {"retries", required_argument, NULL, 'r'},
- {"timeout", required_argument, NULL, 't'},
- {0, 0, 0, 0}
- };
- char *line, *com[MAXCOM];
- const char *iface = "eth0", *password = NULL;
- float timeout = 0.f;
- bool kb = false, force = false, global = true;
- struct timeval tv;
- const struct TreeNode *cur, *next;
- struct ether_addr *mac = NULL;
- int i, n, retries = 3;
-
-
- tcgetattr(STDIN_FILENO, &orig_term);
- current_term = orig_term;
- batch = false;
-
- opterr = 0;
-
- while ((n = getopt_long(argc, argv, "abfhi:lm:p:r:t:", opts, NULL)) != -1) {
- switch (n) {
-
- case 'a':
- batch = true;
- break;
-
- case 'b':
- kb = true;
- break;
-
- case 'f':
- force = true;
- break;
-
- case 'h':
- printf("usage: %s [-a] [-b] [-f] [-g] [-i <interface>] [-m <MAC>] [-p <password>]\n", argv[0]);
- goto end;
-
- case 'i':
- iface = optarg;
- break;
-
- case 'l':
- global = false;
- break;
-
- case 'm':
- mac = ether_aton(optarg);
- if (mac == NULL) {
- printf("invalid MAC\n");
- goto end;
- }
- break;
-
- case 'p':
- password = optarg;
- break;
-
- case 'r':
- retries = strtol(optarg, NULL, 0);
- break;
-
- case 't':
- timeout = strtof(optarg, NULL);
- break;
-
- case '?':
- printf("unknown option: \"%s\"\n", argv[optind - 1]);
- goto end;
- }
- }
-
- argc -= optind;
- argv += optind;
-
- if (argc != 0) {
- printf("unknown trailing options\n");
- goto end;
- }
-
-
- memset(com, 0, MAXCOM * sizeof(char*));
-
- nga = ngadmin_init(iface);
- if (nga == NULL) {
- fprintf(stderr, "initialization error\n");
- goto end;
- }
-
- /* set timeout */
- if (timeout > 0.f) {
- tv.tv_sec = (int)timeout;
- tv.tv_usec = (int)((timeout - (float)tv.tv_sec) * 1.e6f);
- ngadmin_setTimeout(nga, &tv);
- }
-
-
- if (ngadmin_setKeepBroadcasting(nga, kb) != ERR_OK)
- goto end;
-
- if (force && ngadmin_forceInterface(nga) != ERR_OK)
- goto end;
-
- if (ngadmin_useGlobalBroadcast(nga, global) != ERR_OK)
- goto end;
-
- /* non-TTY inputs are automatically set to batch mode */
- if (!isatty(STDIN_FILENO))
- batch = true;
-
- if (password != NULL)
- ngadmin_setPassword(nga, password);
-
- signal(SIGTERM, handler);
- signal(SIGINT, handler);
-
- /* automatic scan & login when switch MAC is specified on the command line */
- if (mac != NULL && pre_login(mac, retries) != 0)
- goto end;
-
- if (batch) {
- /* in batch mode, we must be logged to continue */
- if (ngadmin_getCurrentSwitch(nga) == NULL) {
- printf("must be logged\n");
- goto end;
- }
- } else {
- /* initialize readline functions */
- rl_attempted_completion_function = my_completion;
- rl_completion_entry_function = my_generator;
-
- sigsetjmp(jmpbuf, 1);
- }
-
- main_loop_continue = 1;
- while (main_loop_continue) {
- /* read user input */
- line = NULL;
- n = 0;
- if (batch)
- n = getline(&line, (size_t*)&i, stdin);
- else
- line = readline("> ");
- if (n < 0 || line == NULL)
- goto end;
-
- /* split string into words */
- trim(line, strlen(line));
- n = explode(line, com, MAXCOM);
-
- if (n == 0) {
- free(line);
- continue;
- } else {
- if (!batch)
- add_history(line);
- free(line);
- }
-
- cur = getSubCom(com, n, &i);
-
- if (cur->sub != NULL) {
- /* not terminal command */
- if (i == 0) {
- /* root command */
- printf("unknown command: %s\n", com[i]);
- } else if (i < n) {
- /* intermediate command, remaining string */
- printf("unknown %s subcommand: %s\n", com[i - 1], com[i]);
- } else {
- /* intermediate command, no remaining string */
- /* print available subcommands */
- for (next = cur->sub; next->name != NULL; next++)
- printf("%s ", next->name);
- putchar('\n');
- }
- } else if (cur->comfunc == NULL) {
- /* erroneous terminal command without function */
- printf("terminal command without function\n");
- } else {
- /* execute terminal command */
- cur->comfunc(n - i, (const char**)&com[i], nga);
- }
-
- for (i = 0; com[i] != NULL; i++) {
- free(com[i]);
- com[i] = NULL;
- }
- }
-
-end:
- handler(0);
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-/* helper function to analyse bitrate speed specifications */
-static int bitrate_analyse (int argc, const char **argv, int *ports)
-{
- int i = 0, s;
-
-
- while (i < argc - 1) {
- s = parseBitrate(argv[i + 1]);
- if (strcmp(argv[i], "inout") == 0) {
- ports[0] = s;
- ports[1] = s;
- } else if (strcmp(argv[i], "in") == 0) {
- ports[0] = s;
- } else if (strcmp(argv[i], "out") == 0) {
- ports[1] = s;
- } else {
- break;
- }
- i += 2;
- }
-
-
- return i;
-}
-
-
-int do_bitrate_set (int argc, const char **argv, struct ngadmin *nga)
-{
- int i, k = 0, defs[] = {12, 12}, p, *ports = NULL, ret = 0;
- const struct swi_attr *sa;
-
-
- if (argc < 2) {
- printf(
- "usage: bitrate set [all SPEEDSPEC] <port1> SPEEDSPEC [<port2> SPEEDSPEC ...]\n"
- "SPEEDSPEC: [inout <speed>] [in <ispeed>] [out <ospeed>]\n"
- );
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- ports = malloc(2 * sa->ports * sizeof(int));
-
- /* get defaults if present */
- if (strcmp(argv[k], "all") == 0) {
- k++;
- k += bitrate_analyse(argc - k, &argv[k], defs);
- }
-
- /* apply defaults */
- for (i = 0; i < sa->ports; i++)
- memcpy(&ports[2 * i], defs, sizeof(defs));
-
- /* get ports specifics */
- while (k < argc) {
- p = strtol(argv[k++], NULL, 0) - 1;
- if (p >= 0 && p <sa->ports)
- k += bitrate_analyse(argc - k, &argv[k], &ports[2 * p]);
- }
-
- /* send it to the switch */
- i = ngadmin_setBitrateLimits(nga, ports);
- printErrCode(i);
-
-end:
- free(ports);
-
- return ret;
-}
-
-
-int do_bitrate_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i, ret = 0, *ports = NULL;
- const struct swi_attr *sa;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
-
- ports = malloc(2 * sa->ports * sizeof(int));
- i = ngadmin_getBitrateLimits(nga, ports);
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- for (i = 0; i < sa->ports; i++)
- printf("port %i: in %s, out %s\n", i + 1, bitrates[ports[2 * i + 0]], bitrates[ports[2 * i + 1]]);
-
-end:
- free(ports);
-
- return ret;
-}
-
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_cabletest (int argc, const char **argv, struct ngadmin *nga)
-{
- const struct swi_attr *sa;
- struct cabletest *ct = NULL;
- int i, j = 0, k = 0, ret = 0;
-
-
- if (argc < 1) {
- printf("usage: cabletest <port1> [<port2> ...]\n");
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- ct = malloc(sa->ports * sizeof(struct cabletest));
- memset(ct, 0, sa->ports * sizeof(struct cabletest));
-
- while (k < argc) {
- ct[j].port = strtol(argv[k++], NULL, 0);
- if (ct[j].port >= 1 && ct[j].port <= sa->ports)
- j++;
- }
-
- i = ngadmin_cabletest(nga, ct, j);
- if (i < 0) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- for (i = 0; i < j; i++)
- printf("port %i: %08X %08X\n", ct[i].port, ct[i].v1, ct[i].v2);
-
-end:
- free(ct);
-
- return ret;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_defaults (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i, ret = 0;
- const struct swi_attr *sa;
- char line[16];
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- printf("The switch settings will be CLEARED. Continue ? [y/N]: ");
- fflush(stdout);
-
- if (fgets(line, sizeof(line), stdin) != NULL && strcasecmp(line, "y\n") == 0) {
- i = ngadmin_defaults(nga);
- printErrCode(i);
- }
-
-end:
-
- return ret;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_firmware_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- const struct swi_attr *sa;
- int ret = 0;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- puts(sa->firmware);
-
-end:
-
- return ret;
-}
-
-
-int do_firmware_upgrade (int argc, const char **argv, struct ngadmin *nga)
-{
- const struct swi_attr *sa;
- int i, ret = 0;
-
-
- if (argc != 1) {
- printf("usage: firmware upgrade <file>\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- i = ngadmin_upgradeFirmware(nga, argv[0]);
- printErrCode(i);
-
-end:
-
- return ret;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-bool do_help (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED)
-{
- const struct TreeNode *s;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- printf("Available commands: \n");
-
- for (s = commands.sub; s->name != NULL; s++)
- printf("%s ", s->name);
- putchar('\n');
-
-
- return 0;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_igmp_set (int argc, const char **argv, struct ngadmin *nga)
-{
- int i;
- struct igmp_conf ic;
-
-
- if (argc != 4) {
- printf("usage: igmp set <enable> <vlan> <validate> <block>\n");
- return 1;
- }
-
- if (ngadmin_getCurrentSwitch(nga) == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- ic.enable = strtol(argv[0], NULL, 0);
- ic.vlan = strtol(argv[1], NULL, 0);
- ic.validate = strtol(argv[2], NULL, 0);
- ic.block = strtol(argv[3], NULL, 0);
-
- i = ngadmin_setIGMPConf(nga, &ic);
- printErrCode(i);
-
-
- return 0;
-}
-
-
-int do_igmp_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i, ret = 0;
- const struct swi_attr *sa;
- struct igmp_conf ic;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- i = ngadmin_getIGMPConf(nga, &ic);
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- printf("IGMP snooping enabled: %s\n", ic.enable ? "yes" : "no" );
- printf("IGMP snooping vlan: %u\n", ic.vlan);
- printf("Validate IGMPv3 headers: %s\n", ic.validate ? "yes" : "no" );
- printf("Block unknown multicast addresses: %s\n", ic.block ? "yes" : "no" );
-
-end:
-
- return ret;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-bool do_list (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int n;
- const struct swi_attr *sa;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- sa = ngadmin_getSwitchTab(nga, &n);
- displaySwitchTab(sa, n);
-
-
- return 0;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-bool do_login (int argc, const char **argv, struct ngadmin *nga)
-{
- int i;
-
-
- if (argc != 1) {
- printf("usage: login <num>\n");
- return 1;
- }
-
- i = strtol(argv[0], NULL, 0);
- i = ngadmin_login(nga, i);
- printErrCode(i);
-
-
- return 0;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_mirror_disable (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- if (ngadmin_getCurrentSwitch(nga) == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- i = ngadmin_setMirror(nga, NULL);
- printErrCode(i);
-
-
- return 0;
-}
-
-
-int do_mirror_set (int argc, const char **argv, struct ngadmin *nga)
-{
- const struct swi_attr *sa;
- char *ports = NULL;
- int i, k = 0, ret = 0;
-
-
- if (argc < 3) {
- printf("usage: mirror set <destination port> clone <port1> [<port2> ...]\n");
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- ports = malloc((sa->ports + 1) * sizeof(char));
- memset(ports, 0, sa->ports + 1);
-
- ports[0] = strtol(argv[k++], NULL, 0);
- if (ports[0] < 1 || ports[0] > sa->ports || strcasecmp(argv[k++], "clone") != 0) {
- printf("syntax error\n");
- ret = 1;
- goto end;
- }
-
- while (k < argc) {
- i = strtol(argv[k++], NULL, 0);
- if (i < 1 || i > sa->ports) {
- printf("port out of range\n");
- ret = 1;
- goto end;
- } else if (i == ports[0]) {
- printf("destination port cannot be in port list\n");
- ret = 1;
- goto end;
- }
- ports[i] = 1;
- }
-
- i = ngadmin_setMirror(nga, ports);
- printErrCode(i);
-
-end:
- free(ports);
-
- return ret;
-}
-
-
-int do_mirror_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- const struct swi_attr *sa;
- char *ports = NULL;
- int i;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- ports = malloc((sa->ports + 1) * sizeof(char));
- i = ngadmin_getMirror(nga, ports);
- if (i != ERR_OK) {
- printErrCode(i);
- goto end;
- }
-
- if (ports[0] == 0) {
- printf("port mirroring is disabled\n");
- goto end;
- }
-
- printf("destination: %i\n", ports[0]);
- printf("ports: ");
- for (i = 1; i <= sa->ports; i++) {
- if (ports[i])
- printf("%i ", i);
- }
- printf("\n");
-
-
-end:
- free(ports);
-
- return 0;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_name_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- const struct swi_attr *sa;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- puts(sa->name);
-
-
- return 0;
-}
-
-
-int do_name_set (int argc, const char **argv, struct ngadmin *nga)
-{
- int i;
- const struct swi_attr *sa;
-
-
- if (argc != 1) {
- printf("usage: name set <value>\n");
- return 1;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- i = ngadmin_setName(nga, argv[0]);
- printErrCode(i);
-
-
- return 0;
-}
-
-
-int do_name_clear (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i;
- const struct swi_attr *sa;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- i = ngadmin_setName(nga, NULL);
- printErrCode(i);
-
-
- return 0;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_netconf_set (int argc, const char **argv, struct ngadmin *nga)
-{
- int i, k, ret = 0;
- const struct swi_attr *sa;
- struct net_conf nc;
-
-
- if (argc == 0) {
- printf("usage: netconf set [dhcp yes|no] [ip <ip>] [mask <mask>] [gw <gw>]\n");
- return 1;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- memset(&nc, 0, sizeof(struct net_conf));
-
- for (k = 0; k < argc; k += 2) {
- if (strcasecmp(argv[k], "dhcp") == 0) {
- if (strcasecmp(argv[k + 1], "yes") == 0) {
- nc.dhcp = true;
- } else if (strcasecmp(argv[k + 1], "no") == 0) {
- nc.dhcp = 1;
- } else {
- printf("Incorrect DHCP value\n");
- ret = 1;
- goto end;
- }
- } else if (strcasecmp(argv[k], "ip") == 0) {
- if (inet_aton(argv[k + 1], &nc.ip) == 0) {
- printf("Incorrect IP value\n");
- ret = 1;
- goto end;
- }
- } else if (strcasecmp(argv[k], "mask") == 0) {
- /* TODO: check if it is a correct mask */
- if (inet_aton(argv[k + 1], &nc.netmask) == 0) {
- printf("Incorrect mask value\n");
- ret = 1;
- goto end;
- }
- } else if (strcasecmp(argv[k], "gw") == 0) {
- if (inet_aton(argv[k + 1], &nc.gw) == 0) {
- printf("Incorrect gateway value\n");
- ret = 1;
- goto end;
- }
- }
- }
-
- i = ngadmin_setNetConf(nga, &nc);
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- }
-
-end:
-
- return ret;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_password_change (int argc, const char **argv, struct ngadmin *nga)
-{
- int i;
- const struct swi_attr *sa;
-
-
- if (argc != 1) {
- printf("usage: password change <value>\n");
- return 1;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- i = ngadmin_changePassword(nga, argv[0]);
- printErrCode(i);
-
-
- return 0;
-}
-
-
-int do_password_set (int argc, const char **argv, struct ngadmin *nga)
-{
- int i;
- char buf[64];
- const char *pass;
-
-
- if (argc > 1) {
- printf("usage: password set [<value>]\n");
- return 1;
- }
-
- if (argc == 0) {
- printf("Enter password: ");
- fflush(stdout);
- current_term.c_lflag &= ~ECHO;
- tcsetattr(STDIN_FILENO, TCSANOW, ¤t_term);
- pass = fgets(buf, sizeof(buf), stdin);
- trim(buf, strlen(buf));
- current_term.c_lflag |= ECHO;
- tcsetattr(STDIN_FILENO, TCSANOW, ¤t_term);
- putchar('\n');
- } else {
- pass = argv[0];
- }
-
- if (pass != NULL) {
- i = ngadmin_setPassword(nga, pass);
- printErrCode(i);
- }
-
-
- return 0;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_ports_state (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i, ret = 0;
- const struct swi_attr *sa;
- unsigned char *ports = NULL;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- ports = malloc(sa->ports * sizeof(unsigned char));
- i = ngadmin_getPortsStatus(nga, ports);
- if (i < 0) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- for (i = 0; i < sa->ports; i++) {
- printf("port %i: ", i + 1);
- switch (ports[i]) {
-
- case 0:
- printf("down");
- break;
-
- case SPEED_10:
- printf("up, 10M");
- break;
-
- case SPEED_100:
- printf("up, 100M");
- break;
-
- case SPEED_1000:
- printf("up, 1000M");
- break;
-
- default:
- printf("unknown (%i)", ports[i]);
- }
- putchar('\n');
- }
-
-end:
- free(ports);
-
-
- return ret;
-}
-
-
-int do_ports_statistics_reset (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- if (ngadmin_getCurrentSwitch(nga) == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- i = ngadmin_resetPortsStatistics(nga);
- printErrCode(i);
-
- return 0;
-}
-
-
-int do_ports_statistics_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i, ret = 0;
- const struct swi_attr *sa;
- struct port_stats *ps = NULL;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- ps = calloc(sa->ports, sizeof(struct port_stats));
- i = ngadmin_getPortsStatistics(nga, ps);
- if (i < 0) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- printf("Port\tReceived\tSent\tCRC errors\n");
- for (i = 0; i < sa->ports; i++)
- printf("% 4i%12llu%12llu%14llu\n", i + 1, ps[i].recv, ps[i].sent, ps[i].crc);
-
-end:
- free(ps);
-
- return ret;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_qos_mode (int argc, const char **argv, struct ngadmin *nga)
-{
- int i, s, ret = 0;
- const struct swi_attr *sa;
-
-
- if (argc == 0) {
- printf("usage: qos mode port|802.1p\n");
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- if (strcasecmp(argv[0], "port") == 0) {
- s = QOS_PORT;
- } else if (strcasecmp(argv[0], "802.1p") == 0) {
- s = QOS_DOT;
- } else {
- printf("Unknown QOS mode\n");
- ret = 1;
- goto end;
- }
-
- i = ngadmin_setQOSMode(nga, s);
- printErrCode(i);
-
-end:
-
- return ret;
-}
-
-
-int do_qos_set (int argc, const char **argv, struct ngadmin *nga)
-{
- int i, p, ret = 0;
- const struct swi_attr *sa;
- char d = PRIO_UNSPEC, *ports = NULL;
-
-
- if (argc < 2) {
- printf("usage: qos set (all <prio0>)|(<port1> <prio1> [<port2> <prio2> ...])\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa ==NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- ports = malloc(sa->ports * sizeof(char));
-
- /* read defaults */
- if (strcmp(argv[0], "all") == 0) {
- d = parsePrio(argv[1]);
- argv += 2;
- argc -= 2;
- }
-
- /* apply defaults */
- for (i = 0; i < sa->ports; i++)
- ports[i] = d;
-
- /* read and apply port specifics */
- for (i = 0; i < argc; i += 2) {
- p = strtol(argv[i], NULL, 0);
- if (p < 1 || p > sa->ports)
- continue;
- ports[p - 1] = parsePrio(argv[i + 1]);
- }
-
- /* send the new configuration to the switch */
- i = ngadmin_setQOSValues(nga, ports);
- printErrCode(i);
-
-end:
- free(ports);
-
- return ret;
-}
-
-
-int do_qos_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i, s = 0, ret = 0;
- const struct swi_attr *sa;
- char *ports = NULL;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- i = ngadmin_getQOSMode(nga, &s);
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- printf("QoS mode: ");
- switch (s) {
-
- case QOS_DOT:
- printf("802.1p\n");
- goto end;
-
- case QOS_PORT:
- printf("port based\n");
- break;
-
- default:
- printf("unknown (%i)\n", s);
- goto end;
- }
-
- ports = malloc(sa->ports * sizeof(char));
- i = ngadmin_getQOSValues(nga, ports);
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- for (i = 0; i < sa->ports; i++)
- printf("port %i: %s\n", i + 1, prio[(int)ports[i]]);
-
-end:
- free(ports);
-
- return ret;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_quit (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED)
-{
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- main_loop_continue = 0;
-
- return 0;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_restart (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED)
-{
- int i, ret = 0;
- const struct swi_attr *sa;
- char line[16];
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- printf("The switch will be restarted. Continue ? [y/N]: ");
- fflush(stdout);
-
- if (fgets(line, sizeof(line), stdin) != NULL && strcasecmp(line, "y\n") == 0) {
- i = ngadmin_restart(nga);
- printErrCode(i);
- }
-
-end:
-
- return ret;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_scan (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i;
- const struct swi_attr *sa;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- i = ngadmin_scan(nga);
- if (i < 0) {
- printErrCode(i);
- return 1;
- }
-
- sa = ngadmin_getSwitchTab(nga, &i);
- displaySwitchTab(sa, i);
-
-
- return 0;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-int do_stormfilter_enable (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i;
- const struct swi_attr *sa;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- i = ngadmin_setStormFilterState(nga, 1);
- printErrCode(i);
-
-
- return 0;
-}
-
-
-int do_stormfilter_disable (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i;
- const struct swi_attr *sa;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- i = ngadmin_setStormFilterState(nga, 0);
- printErrCode(i);
-
-
- return 0;
-}
-
-
-int do_stormfilter_set (int argc, const char **argv, struct ngadmin *nga)
-{
- int i, d = BITRATE_UNSPEC, p, *ports = NULL, ret = 0;
- const struct swi_attr *sa;
-
-
- if (argc < 2) {
- printf("usage: stormfilt set (all <speed0>)|(<port1> <speed1> [<port2> <speed2> ...])\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- ports = malloc(sa->ports * sizeof(int));
-
- /* read defaults */
- if (strcmp(argv[0], "all") == 0) {
- d = parseBitrate(argv[1]);
- argv += 2;
- argc -= 2;
- }
-
- /* apply defaults */
- for (i = 0; i < sa->ports; i++)
- ports[i] = d;
-
- /* read and apply port specifics */
- for (i = 0; i < argc - 1; i += 2) {
- p = strtol(argv[i], NULL, 0);
- if (p < 1 || p > sa->ports)
- continue;
- ports[p - 1] = parseBitrate(argv[i + 1]);
- }
-
- /* send the new configuration to the switch */
- i = ngadmin_setStormFilterValues(nga, ports);
- printErrCode(i);
-
-end:
- free(ports);
-
- return ret;
-}
-
-
-int do_stormfilter_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i, s, ret = 0, *ports = NULL;
- const struct swi_attr *sa;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- i = ngadmin_getStormFilterState(nga, &s);
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- if (!s) {
- printf("storm filter is disabled\n");
- goto end;
- }
-
- printf("storm filter is enabled\n");
-
- ports = malloc(sa->ports * sizeof(int));
- i = ngadmin_getStormFilterValues(nga, ports);
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- for (i = 0; i < sa->ports; i++)
- printf("port %i: %s\n", i + 1, bitrates[ports[i]]);
-
-end:
- free(ports);
-
- return ret;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-static void display_node (const struct TreeNode *tn, int depth)
-{
- int i;
- const struct TreeNode *s;
-
-
- for (i = 0; i < depth; i++)
- putchar('\t');
- puts(tn->name);
-
- if (tn->sub == NULL)
- return;
-
- for (s = tn->sub; s->name != NULL; s++)
- display_node(s, depth + 1);
-}
-
-
-int do_tree (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED)
-{
- if (argc > 0) {
- printf("this command takes no argument\n");
- return 1;
- }
-
- display_node(&commands, 0);
-
- return 0;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-
-static char vlan_char (int t)
-{
- switch (t) {
-
- case VLAN_TAGGED:
- return 'T';
-
- case VLAN_UNTAGGED:
- return 'U';
-
- case VLAN_NO:
- return ' ';
-
- default:
- return '?';
- }
-}
-
-
-int do_vlan_8021q_del (int argc, const char **argv, struct ngadmin *nga)
-{
- const struct swi_attr *sa;
- unsigned short vlan;
- int i;
-
-
- if (argc != 1) {
- printf("usage: vlan 8021q del <vlan>\n");
- return 1;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- vlan=strtoul(argv[0], NULL, 0);
- if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
- printf("vlan out of range\n");
- return 1;
- }
-
- i = ngadmin_VLANDestroy(nga, vlan);
- printErrCode(i);
-
-
- return 0;
-}
-
-
-int do_vlan_port_set (int argc, const char **argv, struct ngadmin *nga)
-{
- unsigned char vlan, port, *ports = NULL;
- const struct swi_attr *sa;
- int i, k = 0, ret = 0;
-
-
- if (argc < 2) {
- printf("usage: vlan port set [all <vlan>] [<port1> <vlan>] [<port2> <vlan>] [...]\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- ports = malloc(sa->ports * sizeof(unsigned char));
-
- /* read defaults */
- vlan = 0;
- if (strcmp(argv[k], "all") == 0) {
- k++;
- vlan = strtoul(argv[k++], NULL, 0);
- /* VLAN 0 is allowed and means no change */
- if (vlan > VLAN_PORT_MAX) {
- printf("vlan out of range\n");
- ret = 1;
- goto end;
- }
- }
-
- /* apply defaults */
- memset(ports, vlan, sa->ports);
-
- /* read and apply port specifics */
- while (k < argc - 1) {
- /* read port */
- port = strtoul(argv[k++], NULL, 0);
- if (port < 1 || port > sa->ports) {
- printf("port out of range\n");
- ret = 1;
- goto end;
- }
-
- /* read vlan */
- vlan = strtoul(argv[k++], NULL, 0);
- /* VLAN 0 is allowed and means no change */
- if (vlan > VLAN_PORT_MAX) {
- printf("vlan out of range\n");
- ret = 1;
- goto end;
- }
-
- ports[port - 1] = vlan;
- }
-
- /* set conf */
- i = ngadmin_setVLANPortConf(nga, ports);
- printErrCode(i);
-
-end:
- free(ports);
-
- return ret;
-}
-
-
-int do_vlan_port_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- unsigned char *ports = NULL;
- const struct swi_attr *sa;
- int i, ret = 0;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- ports = malloc(sa->ports * sizeof(unsigned char));
-
- /* request all VLANs config */
- i = ngadmin_getVLANPortConf(nga, ports);
-
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- printf("Ports configuration: \n");
- printf("Port\t");
- for (i = 1; i <= sa->ports; i++)
- printf("%i\t", i);
- putchar('\n');
-
- /* show all VLANs */
- printf("VLAN\t");
- for (i = 0; i < sa->ports; i++)
- printf("%u\t", ports[i]);
- putchar('\n');
-
-end:
- free(ports);
-
- return ret;
-}
-
-
-int do_vlan_8021q_set (int argc, const char **argv, struct ngadmin *nga)
-{
- unsigned char *ports = NULL, p, def = VLAN_UNSPEC;
- const struct swi_attr *sa;
- unsigned short vlan;
- int i, k = 0, ret = 0;
-
-
- if (argc == 0) {
- printf("usage: vlan 802.1q set <vlan> [all unspec|no|untagged|tagged] [<port1> unspec|no|untagged|tagged ...]\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- /* read vlan */
- vlan = strtoul(argv[k++], NULL, 0);
-
- if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
- printf("vlan out of range\n");
- ret = 1;
- goto end;
- }
-
- /* read defaults */
- if (k < argc - 1 && strcasecmp(argv[k], "all") == 0) {
- k++;
- if (strcasecmp(argv[k], "tagged") == 0) {
- def = VLAN_TAGGED;
- } else if (strcasecmp(argv[k], "untagged") == 0) {
- def = VLAN_UNTAGGED;
- } else if (strcasecmp(argv[k], "no") == 0) {
- def = VLAN_NO;
- } else if (strcasecmp(argv[k], "unspec") == 0) {
- def = VLAN_UNSPEC;
- } else {
- printf("incorrect type\n");
- ret = 1;
- goto end;
- }
- k++;
- }
-
- ports = malloc(sa->ports * sizeof(unsigned char));
-
- /* apply defaults */
- memset(ports, def, sa->ports);
-
- /* read and apply port specifics */
- while (k < argc - 1) {
- p = strtoul(argv[k++], NULL, 0) - 1;
- if (p >= sa->ports) {
- printf("port out of range\n");
- ret = 1;
- goto end;
- }
- if (strcasecmp(argv[k], "tagged") ==0) {
- ports[p] = VLAN_TAGGED;
- } else if (strcasecmp(argv[k], "untagged") == 0) {
- ports[p] = VLAN_UNTAGGED;
- } else if (strcasecmp(argv[k], "no") == 0) {
- ports[p] = VLAN_NO;
- } else if (strcasecmp(argv[k], "unspec") == 0) {
- ports[p] = VLAN_UNSPEC;
- } else {
- printf("incorrect type\n");
- ret = 1;
- goto end;
- }
- k++;
- }
-
- /* set conf */
- i = ngadmin_setVLANDotConf(nga, vlan, ports);
- printErrCode(i);
-
-end:
- free(ports);
-
- return ret;
-}
-
-
-int do_vlan_8021q_show (int argc, const char **argv, struct ngadmin *nga)
-{
- unsigned short vl = 0, *vlans = NULL;
- unsigned char *ports = NULL;
- const struct swi_attr *sa;
- int i, j, n = 16, ret = 0;
-
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- if (argc > 0)
- vl = strtoul(argv[0], NULL, 0);
-
- ports = malloc(sa->ports * n * sizeof(unsigned char));
-
- if (vl == 0) {
- /* request all VLANs config */
- vlans = malloc(n * sizeof(unsigned short));
- ports = malloc(sa->ports * n * sizeof(unsigned char));
- i = ngadmin_getVLANDotAllConf(nga, vlans, ports, &n);
- } else {
- /* request single VLAN config */
- ports = malloc(sa->ports * sizeof(unsigned char));
- i = ngadmin_getVLANDotConf(nga, vl, ports);
- }
-
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- printf("Ports configuration: \n");
- printf("VLAN\t");
- for (i = 1; i <= sa->ports; i++)
- printf("%i\t", i);
- putchar('\n');
-
- if (vl == 0) {
- /* show all VLANs */
- for (i = 0; i < n; i++) {
- printf("%u\t", vlans[i]);
- for (j = 0; j < sa->ports; j++)
- printf("%c\t", vlan_char(ports[i * sa->ports + j]));
- putchar('\n');
- }
- } else {
- /* show single VLAN config */
- printf("%u\t", vl);
- for (j = 0; j < sa->ports; j++)
- printf("%c\t", vlan_char(ports[j]));
- putchar('\n');
- }
-
-end:
- free(vlans);
- free(ports);
-
- return ret;
-}
-
-
-int do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga)
-{
- int mode, i;
-
-
- if (argc == 0) {
- printf(
- "usage: vlan mode set <mode>\n"
- "0 - disabled\n"
- "1 - basic port based\n"
- "2 - advanced port based\n"
- "3 - basic 802.1Q\n"
- "4 - advanced 802.1Q\n"
- );
- return 0;
- }
-
- if (ngadmin_getCurrentSwitch(nga) == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- mode = strtoul(argv[0], NULL, 0);
- if (mode < VLAN_DISABLED || mode > VLAN_DOT_ADV) {
- printf("mode out of range\n");
- return 1;
- }
-
- i = ngadmin_setVLANType(nga, mode);
- printErrCode(i);
-
-
- return 0;
-}
-
-
-int do_vlan_mode_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- int i, t, ret = 0;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- if (ngadmin_getCurrentSwitch(nga) == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- i = ngadmin_getVLANType(nga, &t);
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- printf("VLAN type: ");
- switch (t) {
-
- case VLAN_DISABLED:
- printf("disabled\n");
- break;
-
- case VLAN_PORT_BASIC:
- printf("port basic\n");
- break;
-
- case VLAN_PORT_ADV:
- printf("port advanced\n");
- break;
-
- case VLAN_DOT_BASIC:
- printf("802.1Q basic\n");
- break;
-
- case VLAN_DOT_ADV:
- printf("802.1Q advanced\n");
- break;
-
- default:
- printf("unknown (%i)\n", t);
- }
-
-end:
-
- return ret;
-}
-
-
-int do_vlan_pvid_set (int argc, const char **argv, struct ngadmin *nga)
-{
- const struct swi_attr *sa;
- unsigned char port;
- unsigned short vlan;
- int i;
-
-
- if (argc != 2) {
- printf("usage: vlan pvid set <port> <vlan>\n");
- return 1;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- return 1;
- }
-
- port = strtoul(argv[0], NULL, 0);
- vlan = strtoul(argv[1], NULL, 0);
-
- if (port < 1 || port > sa->ports) {
- printf("port out of range\n");
- return 1;
- }
-
- if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
- printf("vlan out of range\n");
- return 1;
- }
-
- i = ngadmin_setPVID(nga, port, vlan);
- printErrCode(i);
-
-
- return 0;
-}
-
-
-int do_vlan_pvid_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
-{
- unsigned short *ports = NULL;
- const struct swi_attr *sa;
- int i, ret = 0;
-
-
- if (argc > 0) {
- printf("this command takes no argument\n");
- ret = 1;
- goto end;
- }
-
- sa = ngadmin_getCurrentSwitch(nga);
- if (sa == NULL) {
- printf("must be logged\n");
- ret = 1;
- goto end;
- }
-
- ports = malloc(sa->ports * sizeof(unsigned short));
- i = ngadmin_getAllPVID(nga, ports);
- if (i != ERR_OK) {
- printErrCode(i);
- ret = 1;
- goto end;
- }
-
- printf("Port\t");
- for (i = 1; i <= sa->ports; i++)
- printf("%i\t", i);
- putchar('\n');
-
- printf("VLAN\t");
- for (i = 0; i < sa->ports; i++)
- printf("%u\t", ports[i]);
- putchar('\n');
-
-end:
- free(ports);
-
- return ret;
-}
-
-
+++ /dev/null
-
-#include "commands.h"
-
-
-/* bitrate */
-int do_bitrate_set (int argc, const char **argv, struct ngadmin *nga);
-int do_bitrate_show (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* cabletest */
-int do_cabletest (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* defaults */
-int do_defaults (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* firmware */
-int do_firmware_show (int argc, const char **argv, struct ngadmin *nga);
-int do_firmware_upgrade (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* help */
-int do_help (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* igmp */
-int do_igmp_set (int argc, const char **argv, struct ngadmin *nga);
-int do_igmp_show (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* list */
-int do_list (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* login */
-int do_login (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* mirror */
-int do_mirror_disable (int argc, const char **argv, struct ngadmin *nga);
-int do_mirror_set (int argc, const char **argv, struct ngadmin *nga);
-int do_mirror_show (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* name */
-int do_name_show (int argc, const char **argv, struct ngadmin *nga);
-int do_name_set (int argc, const char **argv, struct ngadmin *nga);
-int do_name_clear (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* netconf */
-int do_netconf_set (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* password */
-int do_password_change (int argc, const char **argv, struct ngadmin *nga);
-int do_password_set (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* ports */
-int do_ports_state (int argc, const char **argv, struct ngadmin *nga);
-int do_ports_statistics_reset (int argc, const char **argv, struct ngadmin *nga);
-int do_ports_statistics_show (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* qos */
-int do_qos_mode (int argc, const char **argv, struct ngadmin *nga);
-int do_qos_set (int argc, const char **argv, struct ngadmin *nga);
-int do_qos_show (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* quit */
-int do_quit (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* restart */
-int do_restart (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* scan */
-int do_scan (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* stormfilter */
-int do_stormfilter_enable (int argc, const char **argv, struct ngadmin *nga);
-int do_stormfilter_disable (int argc, const char **argv, struct ngadmin *nga);
-int do_stormfilter_set (int argc, const char **argv, struct ngadmin *nga);
-int do_stormfilter_show (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* tree */
-int do_tree (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* vlan */
-int do_vlan_8021q_del (int argc, const char **argv, struct ngadmin *nga);
-int do_vlan_port_set (int argc, const char **argv, struct ngadmin *nga);
-int do_vlan_port_show (int argc, const char **argv, struct ngadmin *nga);
-int do_vlan_8021q_set (int argc, const char **argv, struct ngadmin *nga);
-int do_vlan_8021q_show (int argc, const char **argv, struct ngadmin *nga);
-int do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga);
-int do_vlan_mode_show (int argc, const char **argv, struct ngadmin *nga);
-int do_vlan_pvid_set (int argc, const char **argv, struct ngadmin *nga);
-int do_vlan_pvid_show (int argc, const char **argv, struct ngadmin *nga);
-
-
-/* commands structure */
-COM_ROOT_START(commands)
- COM_START(bitrate)
- COM_TERM(set, do_bitrate_set)
- COM_TERM(show, do_bitrate_show)
- COM_END
-
- COM_TERM(cabletest, do_cabletest)
-
- COM_TERM(defaults, do_defaults)
-
- COM_START(firmware)
- COM_TERM(show, do_firmware_show)
- COM_TERM(upgrade, do_firmware_upgrade)
- COM_END
-
- COM_TERM(help, do_help)
-
- COM_START(igmp)
- COM_TERM(set, do_igmp_set)
- COM_TERM(show, do_igmp_show)
- COM_END
-
- COM_TERM(list, do_list)
-
- COM_TERM(login, do_login)
-
- COM_START(mirror)
- COM_TERM(disable, do_mirror_disable)
- COM_TERM(set, do_mirror_set)
- COM_TERM(show, do_mirror_show)
- COM_END
-
- COM_START(name)
- COM_TERM(show, do_name_show)
- COM_TERM(set, do_name_set)
- COM_TERM(clear, do_name_clear)
- COM_END
-
- COM_START(netconf)
- COM_TERM(set, do_netconf_set)
- COM_END
-
- COM_START(password)
- COM_TERM(change, do_password_change)
- COM_TERM(set, do_password_set)
- COM_END
-
- COM_START(ports)
- COM_TERM(state, do_ports_state)
- COM_START(statistics)
- COM_TERM(reset, do_ports_statistics_reset)
- COM_TERM(show, do_ports_statistics_show)
- COM_END
- COM_END
-
- COM_START(qos)
- COM_TERM(mode, do_qos_mode)
- COM_TERM(set, do_qos_set)
- COM_TERM(show, do_qos_show)
- COM_END
-
- COM_TERM(quit, do_quit)
-
- COM_TERM(restart, do_restart)
-
- COM_TERM(scan, do_scan)
-
- COM_START(stormfilter)
- COM_TERM(enable, do_stormfilter_enable)
- COM_TERM(disable, do_stormfilter_disable)
- COM_TERM(set, do_stormfilter_set)
- COM_TERM(show, do_stormfilter_show)
- COM_END
-
- COM_TERM(tree, do_tree)
-
- COM_START(vlan)
- COM_START(802.1q)
- COM_TERM(del, do_vlan_8021q_del)
- COM_TERM(set, do_vlan_8021q_set)
- COM_TERM(show, do_vlan_8021q_show)
- COM_END
- COM_START(mode)
- COM_TERM(set, do_vlan_mode_set)
- COM_TERM(show, do_vlan_mode_show)
- COM_END
- COM_START(port)
- COM_TERM(set, do_vlan_port_set)
- COM_TERM(show, do_vlan_port_show)
- COM_END
- COM_START(pvid)
- COM_TERM(set, do_vlan_pvid_set)
- COM_TERM(show, do_vlan_pvid_show)
- COM_END
- COM_END
-COM_ROOT_END
-
-
+++ /dev/null
-
-#ifndef DEF_COMMANDS
-#define DEF_COMMANDS
-
-
-#include "common.h"
-
-
-struct TreeNode {
- const char *name;
- int (*comfunc)(int, const char**, struct ngadmin*);
- const struct TreeNode *sub;
-};
-
-
-#define COM_ROOT_START(v) const struct TreeNode v = {.name = "<root>", .comfunc = NULL, .sub = (const struct TreeNode[]){
-#define COM_ROOT_END {.name = NULL, .comfunc = NULL, .sub = NULL}}};
-#define COM_START(nam) {.name = #nam, .comfunc = NULL, .sub = (const struct TreeNode[]){
-#define COM_END {.name = NULL, .comfunc = NULL, .sub = NULL}}},
-#define COM_TERM(nam, func) {.name = #nam, .comfunc = func, .sub = NULL},
-
-
-extern const struct TreeNode commands;
-
-
-#endif
-
+++ /dev/null
-
-#include "common.h"
-
-
-void printErrCode (int err)
-{
- switch (err) {
- case ERR_OK:
- break;
-
- case ERR_NET:
- printf("network error\n");
- break;
-
- case ERR_NOTLOG:
- printf("no switch selected\n");
- break;
-
- case ERR_DENIED:
- printf("access denied\n");
- break;
-
- case ERR_BADPASS:
- printf("wrong password\n");
- break;
-
- case ERR_BADID:
- printf("bad switch id\n");
- break;
-
- case ERR_INVARG:
- printf("invalid argument\n");
- break;
-
- case ERR_TIMEOUT:
- printf("timeout\n");
- break;
-
- case ERR_NOTIMPL:
- printf("not implemented\n");
- break;
-
- default:
- printf("unknown status code (%i)\n", err);
- }
-}
-
-
-const char* const bitrates[] = {
- "nl",
- "512K",
- "1M",
- "2M",
- "4M",
- "8M",
- "16M",
- "32M",
- "64M",
- "128M",
- "256M",
- "512M",
- NULL
-};
-
-
-const char* const prio[]={
- NULL,
- "high",
- "medium",
- "normal",
- "low",
- NULL
-};
-
-
-int parseBitrate (const char *s)
-{
- int i;
-
- for (i = 0; bitrates[i] != NULL && strcasecmp(bitrates[i], s) != 0; i++);
-
- return i;
-}
-
-
-char parsePrio (const char *s)
-{
- int i;
-
- for (i = 1; prio[i] != NULL && strcasecmp(prio[i], s) != 0; i++);
-
- return (char)i;
-}
-
-
-void displaySwitchTab (const struct swi_attr *sa, int nb)
-{
- int i=0;
-
- if (nb == 0) {
- printf("no switch found\n");
- return;
- }
-
- printf("Num\tMac\t\t\tProduct\t\tName\t\t\tIP/mask\t\t\tDHCP\tPorts\tFirmware\n");
-
- for (i = 0; i < nb; i++) {
- printf("%i\t%s\t%s\t%s\t\t%s/", i, ether_ntoa(&sa[i].mac), sa[i].product, sa[i].name, inet_ntoa(sa[i].nc.ip));
- printf("%s\t%s\t%i\t%s\n", inet_ntoa(sa[i].nc.netmask), ( sa[i].nc.dhcp ? "Yes" : "No" ), sa[i].ports, sa[i].firmware);
- }
-
- printf("\nfound %i switch(es)\n", nb);
-}
-
-
-int trim (char *txt, int start)
-{
- char *p;
-
- if (txt == NULL)
- return 0;
-
- p = txt + start;
- for (p--; p >= txt && (*p == ' ' || *p == '\n'); *p-- = 0);
-
- return p - txt + 1;
-}
-
-
-int explode (const char *commande, char** tab, int maximum)
-{
- const char *start, *end;
- int n = 0, len;
-
-
- for (end = commande; ; n++) {
- for (start = end; *start == ' ' && *start != 0; start++);
- for (end = start; (*end != ' ' || n >= maximum - 1 ) && *end != 0; end++);
-
- len = end - start;
- if (len == 0)
- break;
-
- tab[n] = malloc(sizeof(char) * (len + 1));
- memcpy(tab[n], start, len);
- tab[n][len] = 0;
- }
-
-
- return n;
-}
-
-
+++ /dev/null
-
-#ifndef DEF_COMMON
-#define DEF_COMMON
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include <ngadmin.h>
-
-
-#define UNUSED __attribute__((unused))
-#define NORET __attribute__((noreturn))
-
-
-extern int main_loop_continue;
-extern struct termios current_term;
-
-
-extern const char * const bitrates[], * const prio[];
-
-
-void displaySwitchTab (const struct swi_attr *sa, int nb);
-void printErrCode (int err);
-int parseBitrate (const char *s);
-char parsePrio (const char *s);
-
-
-int trim (char *txt, int start);
-
-int explode (const char *commande, char** tab, int maximum);
-
-
-#endif
-
--- /dev/null
+
+man_MANS = ngadmin.1
+
--- /dev/null
+
+bin_PROGRAMS = ngcli
+
+ngcli_SOURCES = admin.c com_bitrate.c com_cabletest.c com_defaults.c com_firmware.c \
+ com_help.c com_igmp.c com_list.c com_login.c commands.c com_mirror.c \
+ common.c com_name.c com_netconf.c com_password.c com_ports.c com_qos.c \
+ com_quit.c com_restart.c com_scan.c com_stormfilter.c com_tree.c com_vlan.c
+ngcli_CPPFLAGS = -I$(top_srcdir)/lib/include/
+ngcli_LDADD = $(top_builddir)/lib/src/libngadmin.la $(READLINE_LIBS)
+
--- /dev/null
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+#include <setjmp.h>
+
+#include <getopt.h>
+#ifdef HAVE_LIBREADLINE
+#include <readline/readline.h>
+#include <readline/history.h>
+#endif
+
+#include "common.h"
+#include "commands.h"
+
+
+#define MAXCOM 32
+
+
+
+static const struct TreeNode* getSubCom (char **com, int n, int *t)
+{
+ int i;
+ const struct TreeNode *cur, *next;
+
+
+ cur = &commands;
+ for (i = 0; i < n; i++) {
+ /* we have reached a terminal command, exit */
+ if (cur->sub == NULL)
+ break;
+
+ /* search sub command in sub command array */
+ for (next = cur->sub; next->name != NULL && strcmp(next->name, com[i]) != 0; next++);
+
+ /* sub command not found, exit */
+ if (next->name == NULL)
+ break;
+
+ /* next command is now the current one */
+ cur = next;
+ }
+
+ *t = i;
+
+
+ return cur;
+}
+
+
+#ifdef HAVE_LIBREADLINE
+static const struct TreeNode *compcur;
+
+
+static char* my_generator (const char* text, int state)
+{
+ static int len;
+ static const struct TreeNode *tn;
+ const char *name;
+
+
+ if (compcur == NULL) {
+ /* sub command not found */
+ return NULL;
+ } else if (state == 0) {
+ tn = compcur->sub;
+ len = strlen(text);
+ }
+
+ if (tn == NULL) /* terminal command */
+ return NULL;
+
+ while ((name = tn++->name) != NULL) {
+ if (strncmp(name, text, len) == 0)
+ return strdup(name);
+ }
+
+
+ return NULL;
+}
+
+
+static char** my_completion (const char *text, int start, int end UNUSED)
+{
+ char **matches = NULL;
+ char *line, *com[MAXCOM];
+ int i, n;
+
+
+ memset(com, 0, MAXCOM * sizeof(char*));
+ line = strdup(rl_line_buffer);
+ line[start] = '\0';
+ trim(line, start);
+ n = explode(line, com, MAXCOM);
+ free(line);
+
+ compcur = getSubCom(com, n, &i);
+
+ if (i < n)
+ compcur = NULL;
+ matches = rl_completion_matches(text, my_generator);
+
+ for (i = 0; com[i] != NULL; i++)
+ free(com[i]);
+
+
+ return matches;
+}
+#endif /* HAVE_LIBREADLINE */
+
+
+int main_loop_continue;
+static struct ngadmin *nga;
+static sigjmp_buf jmpbuf;
+static struct termios orig_term;
+struct termios current_term;
+static bool batch;
+
+
+NORET static void handler (int sig)
+{
+ switch (sig) {
+
+ case SIGTERM:
+ case SIGINT:
+ printf("interrupt\n");
+
+ current_term.c_lflag |= ECHO;
+ tcsetattr(STDIN_FILENO, TCSANOW, ¤t_term);
+
+ if (!batch && main_loop_continue)
+ siglongjmp(jmpbuf, 1);
+
+ default:
+ ngadmin_close(nga);
+
+ tcsetattr(STDIN_FILENO, TCSANOW, &orig_term);
+
+ exit(0);
+ }
+}
+
+
+static int pre_login (const struct ether_addr *mac, int retries)
+{
+ const struct swi_attr *sa;
+ int i, n, err;
+
+
+ for (i = 1; retries <= 0 || i <= retries; i++) {
+ /* scan */
+ printf("scan... ");
+ fflush(stdout);
+ err = ngadmin_scan(nga);
+ if (err < 0) {
+ printErrCode(err);
+ return err;
+ }
+
+ /* search switch with requested MAC */
+ sa = ngadmin_getSwitchTab(nga, &n);
+ while (--n >= 0) {
+ if (memcmp(mac, &sa[n].mac, ETH_ALEN) == 0)
+ break;
+ }
+
+ if (n < 0) {
+ printf("no switch found\n");
+ } else {
+ printf("done\n");
+ break;
+ }
+ }
+
+ if (n < 0)
+ return 1;
+
+ /* login */
+ printf("login... ");
+ fflush(stdout);
+ err = ngadmin_login(nga, n);
+ if (err < 0)
+ printErrCode(err);
+ else
+ printf("done\n");
+
+ return err;
+}
+
+
+int main (int argc, char **argv)
+{
+ static const struct option opts[] = {
+ {"batch", no_argument, NULL, 'a'},
+ {"keep-broadcasting", no_argument, NULL, 'b'},
+ {"force-interface", no_argument, NULL, 'f'},
+ {"help", no_argument, NULL, 'h'},
+ {"interface", required_argument, NULL, 'i'},
+ {"local-broadcast", no_argument, NULL, 'l'},
+ {"mac", required_argument, NULL, 'm'},
+ {"password", required_argument, NULL, 'p'},
+ {"retries", required_argument, NULL, 'r'},
+ {"timeout", required_argument, NULL, 't'},
+ {0, 0, 0, 0}
+ };
+ char *line, *com[MAXCOM];
+ const char *iface = "eth0", *password = NULL;
+ float timeout = 0.f;
+ bool kb = false, force = false, global = true;
+ struct timeval tv;
+ const struct TreeNode *cur, *next;
+ struct ether_addr *mac = NULL;
+ int i, n, retries = 3;
+
+
+ tcgetattr(STDIN_FILENO, &orig_term);
+ current_term = orig_term;
+#ifdef HAVE_LIBREADLINE
+ batch = false;
+#else
+ batch = true;
+#endif
+
+ opterr = 0;
+
+ while ((n = getopt_long(argc, argv, "abfhi:lm:p:r:t:", opts, NULL)) != -1) {
+ switch (n) {
+
+ case 'a':
+ batch = true;
+ break;
+
+ case 'b':
+ kb = true;
+ break;
+
+ case 'f':
+ force = true;
+ break;
+
+ case 'h':
+ printf("usage: %s [-a] [-b] [-f] [-g] [-i <interface>] [-m <MAC>] [-p <password>]\n", argv[0]);
+ goto end;
+
+ case 'i':
+ iface = optarg;
+ break;
+
+ case 'l':
+ global = false;
+ break;
+
+ case 'm':
+ mac = ether_aton(optarg);
+ if (mac == NULL) {
+ printf("invalid MAC\n");
+ goto end;
+ }
+ break;
+
+ case 'p':
+ password = optarg;
+ break;
+
+ case 'r':
+ retries = strtol(optarg, NULL, 0);
+ break;
+
+ case 't':
+ timeout = strtof(optarg, NULL);
+ break;
+
+ case '?':
+ printf("unknown option: \"%s\"\n", argv[optind - 1]);
+ goto end;
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 0) {
+ printf("unknown trailing options\n");
+ goto end;
+ }
+
+
+ memset(com, 0, MAXCOM * sizeof(char*));
+
+ nga = ngadmin_init(iface);
+ if (nga == NULL) {
+ fprintf(stderr, "initialization error\n");
+ goto end;
+ }
+
+ /* set timeout */
+ if (timeout > 0.f) {
+ tv.tv_sec = (int)timeout;
+ tv.tv_usec = (int)((timeout - (float)tv.tv_sec) * 1.e6f);
+ ngadmin_setTimeout(nga, &tv);
+ }
+
+
+ if (ngadmin_setKeepBroadcasting(nga, kb) != ERR_OK)
+ goto end;
+
+ if (force && ngadmin_forceInterface(nga) != ERR_OK)
+ goto end;
+
+ if (ngadmin_useGlobalBroadcast(nga, global) != ERR_OK)
+ goto end;
+
+ /* non-TTY inputs are automatically set to batch mode */
+ if (!isatty(STDIN_FILENO))
+ batch = true;
+
+ if (password != NULL)
+ ngadmin_setPassword(nga, password);
+
+ signal(SIGTERM, handler);
+ signal(SIGINT, handler);
+
+ /* automatic scan & login when switch MAC is specified on the command line */
+ if (mac != NULL && pre_login(mac, retries) != 0)
+ goto end;
+
+ if (batch) {
+ /* in batch mode, we must be logged to continue */
+ if (ngadmin_getCurrentSwitch(nga) == NULL) {
+ printf("must be logged\n");
+ goto end;
+ }
+ } else {
+#ifdef HAVE_LIBREADLINE
+ /* initialize readline functions */
+ rl_attempted_completion_function = my_completion;
+ rl_completion_entry_function = my_generator;
+
+ sigsetjmp(jmpbuf, 1);
+#endif
+ }
+
+ main_loop_continue = 1;
+ while (main_loop_continue) {
+ /* read user input */
+ line = NULL;
+ n = 0;
+ if (batch)
+ n = getline(&line, (size_t*)&i, stdin);
+#ifdef HAVE_LIBREADLINE
+ else
+ line = readline("> ");
+#endif
+ if (n < 0 || line == NULL)
+ goto end;
+
+ /* split string into words */
+ trim(line, strlen(line));
+ n = explode(line, com, MAXCOM);
+
+ if (n == 0) {
+ free(line);
+ continue;
+ } else {
+#ifdef HAVE_LIBREADLINE
+ if (!batch)
+ add_history(line);
+#endif
+ free(line);
+ }
+
+ cur = getSubCom(com, n, &i);
+
+ if (cur->sub != NULL) {
+ /* not terminal command */
+ if (i == 0) {
+ /* root command */
+ printf("unknown command: %s\n", com[i]);
+ } else if (i < n) {
+ /* intermediate command, remaining string */
+ printf("unknown %s subcommand: %s\n", com[i - 1], com[i]);
+ } else {
+ /* intermediate command, no remaining string */
+ /* print available subcommands */
+ for (next = cur->sub; next->name != NULL; next++)
+ printf("%s ", next->name);
+ putchar('\n');
+ }
+ } else if (cur->comfunc == NULL) {
+ /* erroneous terminal command without function */
+ printf("terminal command without function\n");
+ } else {
+ /* execute terminal command */
+ cur->comfunc(n - i, (const char**)&com[i], nga);
+ }
+
+ for (i = 0; com[i] != NULL; i++) {
+ free(com[i]);
+ com[i] = NULL;
+ }
+ }
+
+end:
+ handler(0);
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+/* helper function to analyse bitrate speed specifications */
+static int bitrate_analyse (int argc, const char **argv, int *ports)
+{
+ int i = 0, s;
+
+
+ while (i < argc - 1) {
+ s = parseBitrate(argv[i + 1]);
+ if (strcmp(argv[i], "inout") == 0) {
+ ports[0] = s;
+ ports[1] = s;
+ } else if (strcmp(argv[i], "in") == 0) {
+ ports[0] = s;
+ } else if (strcmp(argv[i], "out") == 0) {
+ ports[1] = s;
+ } else {
+ break;
+ }
+ i += 2;
+ }
+
+
+ return i;
+}
+
+
+int do_bitrate_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ int i, k = 0, defs[] = {12, 12}, p, *ports = NULL, ret = 0;
+ const struct swi_attr *sa;
+
+
+ if (argc < 2) {
+ printf(
+ "usage: bitrate set [all SPEEDSPEC] <port1> SPEEDSPEC [<port2> SPEEDSPEC ...]\n"
+ "SPEEDSPEC: [inout <speed>] [in <ispeed>] [out <ospeed>]\n"
+ );
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ ports = malloc(2 * sa->ports * sizeof(int));
+
+ /* get defaults if present */
+ if (strcmp(argv[k], "all") == 0) {
+ k++;
+ k += bitrate_analyse(argc - k, &argv[k], defs);
+ }
+
+ /* apply defaults */
+ for (i = 0; i < sa->ports; i++)
+ memcpy(&ports[2 * i], defs, sizeof(defs));
+
+ /* get ports specifics */
+ while (k < argc) {
+ p = strtol(argv[k++], NULL, 0) - 1;
+ if (p >= 0 && p <sa->ports)
+ k += bitrate_analyse(argc - k, &argv[k], &ports[2 * p]);
+ }
+
+ /* send it to the switch */
+ i = ngadmin_setBitrateLimits(nga, ports);
+ printErrCode(i);
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
+int do_bitrate_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i, ret = 0, *ports = NULL;
+ const struct swi_attr *sa;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+
+ ports = malloc(2 * sa->ports * sizeof(int));
+ i = ngadmin_getBitrateLimits(nga, ports);
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ for (i = 0; i < sa->ports; i++)
+ printf("port %i: in %s, out %s\n", i + 1, bitrates[ports[2 * i + 0]], bitrates[ports[2 * i + 1]]);
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_cabletest (int argc, const char **argv, struct ngadmin *nga)
+{
+ const struct swi_attr *sa;
+ struct cabletest *ct = NULL;
+ int i, j = 0, k = 0, ret = 0;
+
+
+ if (argc < 1) {
+ printf("usage: cabletest <port1> [<port2> ...]\n");
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ ct = malloc(sa->ports * sizeof(struct cabletest));
+ memset(ct, 0, sa->ports * sizeof(struct cabletest));
+
+ while (k < argc) {
+ ct[j].port = strtol(argv[k++], NULL, 0);
+ if (ct[j].port >= 1 && ct[j].port <= sa->ports)
+ j++;
+ }
+
+ i = ngadmin_cabletest(nga, ct, j);
+ if (i < 0) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ for (i = 0; i < j; i++)
+ printf("port %i: %08X %08X\n", ct[i].port, ct[i].v1, ct[i].v2);
+
+end:
+ free(ct);
+
+ return ret;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_defaults (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i, ret = 0;
+ const struct swi_attr *sa;
+ char line[16];
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ printf("The switch settings will be CLEARED. Continue ? [y/N]: ");
+ fflush(stdout);
+
+ if (fgets(line, sizeof(line), stdin) != NULL && strcasecmp(line, "y\n") == 0) {
+ i = ngadmin_defaults(nga);
+ printErrCode(i);
+ }
+
+end:
+
+ return ret;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_firmware_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ const struct swi_attr *sa;
+ int ret = 0;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ puts(sa->firmware);
+
+end:
+
+ return ret;
+}
+
+
+int do_firmware_upgrade (int argc, const char **argv, struct ngadmin *nga)
+{
+ const struct swi_attr *sa;
+ int i, ret = 0;
+
+
+ if (argc != 1) {
+ printf("usage: firmware upgrade <file>\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ i = ngadmin_upgradeFirmware(nga, argv[0]);
+ printErrCode(i);
+
+end:
+
+ return ret;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+bool do_help (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED)
+{
+ const struct TreeNode *s;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ printf("Available commands: \n");
+
+ for (s = commands.sub; s->name != NULL; s++)
+ printf("%s ", s->name);
+ putchar('\n');
+
+
+ return 0;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_igmp_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ int i;
+ struct igmp_conf ic;
+
+
+ if (argc != 4) {
+ printf("usage: igmp set <enable> <vlan> <validate> <block>\n");
+ return 1;
+ }
+
+ if (ngadmin_getCurrentSwitch(nga) == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ ic.enable = strtol(argv[0], NULL, 0);
+ ic.vlan = strtol(argv[1], NULL, 0);
+ ic.validate = strtol(argv[2], NULL, 0);
+ ic.block = strtol(argv[3], NULL, 0);
+
+ i = ngadmin_setIGMPConf(nga, &ic);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
+int do_igmp_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i, ret = 0;
+ const struct swi_attr *sa;
+ struct igmp_conf ic;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ i = ngadmin_getIGMPConf(nga, &ic);
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ printf("IGMP snooping enabled: %s\n", ic.enable ? "yes" : "no" );
+ printf("IGMP snooping vlan: %u\n", ic.vlan);
+ printf("Validate IGMPv3 headers: %s\n", ic.validate ? "yes" : "no" );
+ printf("Block unknown multicast addresses: %s\n", ic.block ? "yes" : "no" );
+
+end:
+
+ return ret;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+bool do_list (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int n;
+ const struct swi_attr *sa;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ sa = ngadmin_getSwitchTab(nga, &n);
+ displaySwitchTab(sa, n);
+
+
+ return 0;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+bool do_login (int argc, const char **argv, struct ngadmin *nga)
+{
+ int i;
+
+
+ if (argc != 1) {
+ printf("usage: login <num>\n");
+ return 1;
+ }
+
+ i = strtol(argv[0], NULL, 0);
+ i = ngadmin_login(nga, i);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_mirror_disable (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ if (ngadmin_getCurrentSwitch(nga) == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ i = ngadmin_setMirror(nga, NULL);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
+int do_mirror_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ const struct swi_attr *sa;
+ char *ports = NULL;
+ int i, k = 0, ret = 0;
+
+
+ if (argc < 3) {
+ printf("usage: mirror set <destination port> clone <port1> [<port2> ...]\n");
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ ports = malloc((sa->ports + 1) * sizeof(char));
+ memset(ports, 0, sa->ports + 1);
+
+ ports[0] = strtol(argv[k++], NULL, 0);
+ if (ports[0] < 1 || ports[0] > sa->ports || strcasecmp(argv[k++], "clone") != 0) {
+ printf("syntax error\n");
+ ret = 1;
+ goto end;
+ }
+
+ while (k < argc) {
+ i = strtol(argv[k++], NULL, 0);
+ if (i < 1 || i > sa->ports) {
+ printf("port out of range\n");
+ ret = 1;
+ goto end;
+ } else if (i == ports[0]) {
+ printf("destination port cannot be in port list\n");
+ ret = 1;
+ goto end;
+ }
+ ports[i] = 1;
+ }
+
+ i = ngadmin_setMirror(nga, ports);
+ printErrCode(i);
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
+int do_mirror_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ const struct swi_attr *sa;
+ char *ports = NULL;
+ int i;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ ports = malloc((sa->ports + 1) * sizeof(char));
+ i = ngadmin_getMirror(nga, ports);
+ if (i != ERR_OK) {
+ printErrCode(i);
+ goto end;
+ }
+
+ if (ports[0] == 0) {
+ printf("port mirroring is disabled\n");
+ goto end;
+ }
+
+ printf("destination: %i\n", ports[0]);
+ printf("ports: ");
+ for (i = 1; i <= sa->ports; i++) {
+ if (ports[i])
+ printf("%i ", i);
+ }
+ printf("\n");
+
+
+end:
+ free(ports);
+
+ return 0;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_name_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ const struct swi_attr *sa;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ puts(sa->name);
+
+
+ return 0;
+}
+
+
+int do_name_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ int i;
+ const struct swi_attr *sa;
+
+
+ if (argc != 1) {
+ printf("usage: name set <value>\n");
+ return 1;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ i = ngadmin_setName(nga, argv[0]);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
+int do_name_clear (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i;
+ const struct swi_attr *sa;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ i = ngadmin_setName(nga, NULL);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_netconf_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ int i, k, ret = 0;
+ const struct swi_attr *sa;
+ struct net_conf nc;
+
+
+ if (argc == 0) {
+ printf("usage: netconf set [dhcp yes|no] [ip <ip>] [mask <mask>] [gw <gw>]\n");
+ return 1;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ memset(&nc, 0, sizeof(struct net_conf));
+
+ for (k = 0; k < argc; k += 2) {
+ if (strcasecmp(argv[k], "dhcp") == 0) {
+ if (strcasecmp(argv[k + 1], "yes") == 0) {
+ nc.dhcp = true;
+ } else if (strcasecmp(argv[k + 1], "no") == 0) {
+ nc.dhcp = 1;
+ } else {
+ printf("Incorrect DHCP value\n");
+ ret = 1;
+ goto end;
+ }
+ } else if (strcasecmp(argv[k], "ip") == 0) {
+ if (inet_aton(argv[k + 1], &nc.ip) == 0) {
+ printf("Incorrect IP value\n");
+ ret = 1;
+ goto end;
+ }
+ } else if (strcasecmp(argv[k], "mask") == 0) {
+ /* TODO: check if it is a correct mask */
+ if (inet_aton(argv[k + 1], &nc.netmask) == 0) {
+ printf("Incorrect mask value\n");
+ ret = 1;
+ goto end;
+ }
+ } else if (strcasecmp(argv[k], "gw") == 0) {
+ if (inet_aton(argv[k + 1], &nc.gw) == 0) {
+ printf("Incorrect gateway value\n");
+ ret = 1;
+ goto end;
+ }
+ }
+ }
+
+ i = ngadmin_setNetConf(nga, &nc);
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ }
+
+end:
+
+ return ret;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_password_change (int argc, const char **argv, struct ngadmin *nga)
+{
+ int i;
+ const struct swi_attr *sa;
+
+
+ if (argc != 1) {
+ printf("usage: password change <value>\n");
+ return 1;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ i = ngadmin_changePassword(nga, argv[0]);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
+int do_password_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ int i;
+ char buf[64];
+ const char *pass;
+
+
+ if (argc > 1) {
+ printf("usage: password set [<value>]\n");
+ return 1;
+ }
+
+ if (argc == 0) {
+ printf("Enter password: ");
+ fflush(stdout);
+ current_term.c_lflag &= ~ECHO;
+ tcsetattr(STDIN_FILENO, TCSANOW, ¤t_term);
+ pass = fgets(buf, sizeof(buf), stdin);
+ trim(buf, strlen(buf));
+ current_term.c_lflag |= ECHO;
+ tcsetattr(STDIN_FILENO, TCSANOW, ¤t_term);
+ putchar('\n');
+ } else {
+ pass = argv[0];
+ }
+
+ if (pass != NULL) {
+ i = ngadmin_setPassword(nga, pass);
+ printErrCode(i);
+ }
+
+
+ return 0;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_ports_state (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i, ret = 0;
+ const struct swi_attr *sa;
+ unsigned char *ports = NULL;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ ports = malloc(sa->ports * sizeof(unsigned char));
+ i = ngadmin_getPortsStatus(nga, ports);
+ if (i < 0) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ for (i = 0; i < sa->ports; i++) {
+ printf("port %i: ", i + 1);
+ switch (ports[i]) {
+
+ case 0:
+ printf("down");
+ break;
+
+ case SPEED_10:
+ printf("up, 10M");
+ break;
+
+ case SPEED_100:
+ printf("up, 100M");
+ break;
+
+ case SPEED_1000:
+ printf("up, 1000M");
+ break;
+
+ default:
+ printf("unknown (%i)", ports[i]);
+ }
+ putchar('\n');
+ }
+
+end:
+ free(ports);
+
+
+ return ret;
+}
+
+
+int do_ports_statistics_reset (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ if (ngadmin_getCurrentSwitch(nga) == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ i = ngadmin_resetPortsStatistics(nga);
+ printErrCode(i);
+
+ return 0;
+}
+
+
+int do_ports_statistics_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i, ret = 0;
+ const struct swi_attr *sa;
+ struct port_stats *ps = NULL;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ ps = calloc(sa->ports, sizeof(struct port_stats));
+ i = ngadmin_getPortsStatistics(nga, ps);
+ if (i < 0) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ printf("Port\tReceived\tSent\tCRC errors\n");
+ for (i = 0; i < sa->ports; i++)
+ printf("% 4i%12llu%12llu%14llu\n", i + 1, ps[i].recv, ps[i].sent, ps[i].crc);
+
+end:
+ free(ps);
+
+ return ret;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_qos_mode (int argc, const char **argv, struct ngadmin *nga)
+{
+ int i, s, ret = 0;
+ const struct swi_attr *sa;
+
+
+ if (argc == 0) {
+ printf("usage: qos mode port|802.1p\n");
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ if (strcasecmp(argv[0], "port") == 0) {
+ s = QOS_PORT;
+ } else if (strcasecmp(argv[0], "802.1p") == 0) {
+ s = QOS_DOT;
+ } else {
+ printf("Unknown QOS mode\n");
+ ret = 1;
+ goto end;
+ }
+
+ i = ngadmin_setQOSMode(nga, s);
+ printErrCode(i);
+
+end:
+
+ return ret;
+}
+
+
+int do_qos_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ int i, p, ret = 0;
+ const struct swi_attr *sa;
+ char d = PRIO_UNSPEC, *ports = NULL;
+
+
+ if (argc < 2) {
+ printf("usage: qos set (all <prio0>)|(<port1> <prio1> [<port2> <prio2> ...])\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa ==NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ ports = malloc(sa->ports * sizeof(char));
+
+ /* read defaults */
+ if (strcmp(argv[0], "all") == 0) {
+ d = parsePrio(argv[1]);
+ argv += 2;
+ argc -= 2;
+ }
+
+ /* apply defaults */
+ for (i = 0; i < sa->ports; i++)
+ ports[i] = d;
+
+ /* read and apply port specifics */
+ for (i = 0; i < argc; i += 2) {
+ p = strtol(argv[i], NULL, 0);
+ if (p < 1 || p > sa->ports)
+ continue;
+ ports[p - 1] = parsePrio(argv[i + 1]);
+ }
+
+ /* send the new configuration to the switch */
+ i = ngadmin_setQOSValues(nga, ports);
+ printErrCode(i);
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
+int do_qos_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i, s = 0, ret = 0;
+ const struct swi_attr *sa;
+ char *ports = NULL;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ i = ngadmin_getQOSMode(nga, &s);
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ printf("QoS mode: ");
+ switch (s) {
+
+ case QOS_DOT:
+ printf("802.1p\n");
+ goto end;
+
+ case QOS_PORT:
+ printf("port based\n");
+ break;
+
+ default:
+ printf("unknown (%i)\n", s);
+ goto end;
+ }
+
+ ports = malloc(sa->ports * sizeof(char));
+ i = ngadmin_getQOSValues(nga, ports);
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ for (i = 0; i < sa->ports; i++)
+ printf("port %i: %s\n", i + 1, prio[(int)ports[i]]);
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_quit (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED)
+{
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ main_loop_continue = 0;
+
+ return 0;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_restart (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED)
+{
+ int i, ret = 0;
+ const struct swi_attr *sa;
+ char line[16];
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ printf("The switch will be restarted. Continue ? [y/N]: ");
+ fflush(stdout);
+
+ if (fgets(line, sizeof(line), stdin) != NULL && strcasecmp(line, "y\n") == 0) {
+ i = ngadmin_restart(nga);
+ printErrCode(i);
+ }
+
+end:
+
+ return ret;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_scan (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i;
+ const struct swi_attr *sa;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ i = ngadmin_scan(nga);
+ if (i < 0) {
+ printErrCode(i);
+ return 1;
+ }
+
+ sa = ngadmin_getSwitchTab(nga, &i);
+ displaySwitchTab(sa, i);
+
+
+ return 0;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+int do_stormfilter_enable (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i;
+ const struct swi_attr *sa;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ i = ngadmin_setStormFilterState(nga, 1);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
+int do_stormfilter_disable (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i;
+ const struct swi_attr *sa;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ i = ngadmin_setStormFilterState(nga, 0);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
+int do_stormfilter_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ int i, d = BITRATE_UNSPEC, p, *ports = NULL, ret = 0;
+ const struct swi_attr *sa;
+
+
+ if (argc < 2) {
+ printf("usage: stormfilt set (all <speed0>)|(<port1> <speed1> [<port2> <speed2> ...])\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ ports = malloc(sa->ports * sizeof(int));
+
+ /* read defaults */
+ if (strcmp(argv[0], "all") == 0) {
+ d = parseBitrate(argv[1]);
+ argv += 2;
+ argc -= 2;
+ }
+
+ /* apply defaults */
+ for (i = 0; i < sa->ports; i++)
+ ports[i] = d;
+
+ /* read and apply port specifics */
+ for (i = 0; i < argc - 1; i += 2) {
+ p = strtol(argv[i], NULL, 0);
+ if (p < 1 || p > sa->ports)
+ continue;
+ ports[p - 1] = parseBitrate(argv[i + 1]);
+ }
+
+ /* send the new configuration to the switch */
+ i = ngadmin_setStormFilterValues(nga, ports);
+ printErrCode(i);
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
+int do_stormfilter_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i, s, ret = 0, *ports = NULL;
+ const struct swi_attr *sa;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ i = ngadmin_getStormFilterState(nga, &s);
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ if (!s) {
+ printf("storm filter is disabled\n");
+ goto end;
+ }
+
+ printf("storm filter is enabled\n");
+
+ ports = malloc(sa->ports * sizeof(int));
+ i = ngadmin_getStormFilterValues(nga, ports);
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ for (i = 0; i < sa->ports; i++)
+ printf("port %i: %s\n", i + 1, bitrates[ports[i]]);
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+static void display_node (const struct TreeNode *tn, int depth)
+{
+ int i;
+ const struct TreeNode *s;
+
+
+ for (i = 0; i < depth; i++)
+ putchar('\t');
+ puts(tn->name);
+
+ if (tn->sub == NULL)
+ return;
+
+ for (s = tn->sub; s->name != NULL; s++)
+ display_node(s, depth + 1);
+}
+
+
+int do_tree (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED)
+{
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ return 1;
+ }
+
+ display_node(&commands, 0);
+
+ return 0;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+
+static char vlan_char (int t)
+{
+ switch (t) {
+
+ case VLAN_TAGGED:
+ return 'T';
+
+ case VLAN_UNTAGGED:
+ return 'U';
+
+ case VLAN_NO:
+ return ' ';
+
+ default:
+ return '?';
+ }
+}
+
+
+int do_vlan_8021q_del (int argc, const char **argv, struct ngadmin *nga)
+{
+ const struct swi_attr *sa;
+ unsigned short vlan;
+ int i;
+
+
+ if (argc != 1) {
+ printf("usage: vlan 8021q del <vlan>\n");
+ return 1;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ vlan=strtoul(argv[0], NULL, 0);
+ if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
+ printf("vlan out of range\n");
+ return 1;
+ }
+
+ i = ngadmin_VLANDestroy(nga, vlan);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
+int do_vlan_port_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ unsigned char vlan, port, *ports = NULL;
+ const struct swi_attr *sa;
+ int i, k = 0, ret = 0;
+
+
+ if (argc < 2) {
+ printf("usage: vlan port set [all <vlan>] [<port1> <vlan>] [<port2> <vlan>] [...]\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ ports = malloc(sa->ports * sizeof(unsigned char));
+
+ /* read defaults */
+ vlan = 0;
+ if (strcmp(argv[k], "all") == 0) {
+ k++;
+ vlan = strtoul(argv[k++], NULL, 0);
+ /* VLAN 0 is allowed and means no change */
+ if (vlan > VLAN_PORT_MAX) {
+ printf("vlan out of range\n");
+ ret = 1;
+ goto end;
+ }
+ }
+
+ /* apply defaults */
+ memset(ports, vlan, sa->ports);
+
+ /* read and apply port specifics */
+ while (k < argc - 1) {
+ /* read port */
+ port = strtoul(argv[k++], NULL, 0);
+ if (port < 1 || port > sa->ports) {
+ printf("port out of range\n");
+ ret = 1;
+ goto end;
+ }
+
+ /* read vlan */
+ vlan = strtoul(argv[k++], NULL, 0);
+ /* VLAN 0 is allowed and means no change */
+ if (vlan > VLAN_PORT_MAX) {
+ printf("vlan out of range\n");
+ ret = 1;
+ goto end;
+ }
+
+ ports[port - 1] = vlan;
+ }
+
+ /* set conf */
+ i = ngadmin_setVLANPortConf(nga, ports);
+ printErrCode(i);
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
+int do_vlan_port_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ unsigned char *ports = NULL;
+ const struct swi_attr *sa;
+ int i, ret = 0;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ ports = malloc(sa->ports * sizeof(unsigned char));
+
+ /* request all VLANs config */
+ i = ngadmin_getVLANPortConf(nga, ports);
+
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ printf("Ports configuration: \n");
+ printf("Port\t");
+ for (i = 1; i <= sa->ports; i++)
+ printf("%i\t", i);
+ putchar('\n');
+
+ /* show all VLANs */
+ printf("VLAN\t");
+ for (i = 0; i < sa->ports; i++)
+ printf("%u\t", ports[i]);
+ putchar('\n');
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
+int do_vlan_8021q_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ unsigned char *ports = NULL, p, def = VLAN_UNSPEC;
+ const struct swi_attr *sa;
+ unsigned short vlan;
+ int i, k = 0, ret = 0;
+
+
+ if (argc == 0) {
+ printf("usage: vlan 802.1q set <vlan> [all unspec|no|untagged|tagged] [<port1> unspec|no|untagged|tagged ...]\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ /* read vlan */
+ vlan = strtoul(argv[k++], NULL, 0);
+
+ if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
+ printf("vlan out of range\n");
+ ret = 1;
+ goto end;
+ }
+
+ /* read defaults */
+ if (k < argc - 1 && strcasecmp(argv[k], "all") == 0) {
+ k++;
+ if (strcasecmp(argv[k], "tagged") == 0) {
+ def = VLAN_TAGGED;
+ } else if (strcasecmp(argv[k], "untagged") == 0) {
+ def = VLAN_UNTAGGED;
+ } else if (strcasecmp(argv[k], "no") == 0) {
+ def = VLAN_NO;
+ } else if (strcasecmp(argv[k], "unspec") == 0) {
+ def = VLAN_UNSPEC;
+ } else {
+ printf("incorrect type\n");
+ ret = 1;
+ goto end;
+ }
+ k++;
+ }
+
+ ports = malloc(sa->ports * sizeof(unsigned char));
+
+ /* apply defaults */
+ memset(ports, def, sa->ports);
+
+ /* read and apply port specifics */
+ while (k < argc - 1) {
+ p = strtoul(argv[k++], NULL, 0) - 1;
+ if (p >= sa->ports) {
+ printf("port out of range\n");
+ ret = 1;
+ goto end;
+ }
+ if (strcasecmp(argv[k], "tagged") ==0) {
+ ports[p] = VLAN_TAGGED;
+ } else if (strcasecmp(argv[k], "untagged") == 0) {
+ ports[p] = VLAN_UNTAGGED;
+ } else if (strcasecmp(argv[k], "no") == 0) {
+ ports[p] = VLAN_NO;
+ } else if (strcasecmp(argv[k], "unspec") == 0) {
+ ports[p] = VLAN_UNSPEC;
+ } else {
+ printf("incorrect type\n");
+ ret = 1;
+ goto end;
+ }
+ k++;
+ }
+
+ /* set conf */
+ i = ngadmin_setVLANDotConf(nga, vlan, ports);
+ printErrCode(i);
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
+int do_vlan_8021q_show (int argc, const char **argv, struct ngadmin *nga)
+{
+ unsigned short vl = 0, *vlans = NULL;
+ unsigned char *ports = NULL;
+ const struct swi_attr *sa;
+ int i, j, n = 16, ret = 0;
+
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ if (argc > 0)
+ vl = strtoul(argv[0], NULL, 0);
+
+ ports = malloc(sa->ports * n * sizeof(unsigned char));
+
+ if (vl == 0) {
+ /* request all VLANs config */
+ vlans = malloc(n * sizeof(unsigned short));
+ ports = malloc(sa->ports * n * sizeof(unsigned char));
+ i = ngadmin_getVLANDotAllConf(nga, vlans, ports, &n);
+ } else {
+ /* request single VLAN config */
+ ports = malloc(sa->ports * sizeof(unsigned char));
+ i = ngadmin_getVLANDotConf(nga, vl, ports);
+ }
+
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ printf("Ports configuration: \n");
+ printf("VLAN\t");
+ for (i = 1; i <= sa->ports; i++)
+ printf("%i\t", i);
+ putchar('\n');
+
+ if (vl == 0) {
+ /* show all VLANs */
+ for (i = 0; i < n; i++) {
+ printf("%u\t", vlans[i]);
+ for (j = 0; j < sa->ports; j++)
+ printf("%c\t", vlan_char(ports[i * sa->ports + j]));
+ putchar('\n');
+ }
+ } else {
+ /* show single VLAN config */
+ printf("%u\t", vl);
+ for (j = 0; j < sa->ports; j++)
+ printf("%c\t", vlan_char(ports[j]));
+ putchar('\n');
+ }
+
+end:
+ free(vlans);
+ free(ports);
+
+ return ret;
+}
+
+
+int do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ int mode, i;
+
+
+ if (argc == 0) {
+ printf(
+ "usage: vlan mode set <mode>\n"
+ "0 - disabled\n"
+ "1 - basic port based\n"
+ "2 - advanced port based\n"
+ "3 - basic 802.1Q\n"
+ "4 - advanced 802.1Q\n"
+ );
+ return 0;
+ }
+
+ if (ngadmin_getCurrentSwitch(nga) == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ mode = strtoul(argv[0], NULL, 0);
+ if (mode < VLAN_DISABLED || mode > VLAN_DOT_ADV) {
+ printf("mode out of range\n");
+ return 1;
+ }
+
+ i = ngadmin_setVLANType(nga, mode);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
+int do_vlan_mode_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ int i, t, ret = 0;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ if (ngadmin_getCurrentSwitch(nga) == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ i = ngadmin_getVLANType(nga, &t);
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ printf("VLAN type: ");
+ switch (t) {
+
+ case VLAN_DISABLED:
+ printf("disabled\n");
+ break;
+
+ case VLAN_PORT_BASIC:
+ printf("port basic\n");
+ break;
+
+ case VLAN_PORT_ADV:
+ printf("port advanced\n");
+ break;
+
+ case VLAN_DOT_BASIC:
+ printf("802.1Q basic\n");
+ break;
+
+ case VLAN_DOT_ADV:
+ printf("802.1Q advanced\n");
+ break;
+
+ default:
+ printf("unknown (%i)\n", t);
+ }
+
+end:
+
+ return ret;
+}
+
+
+int do_vlan_pvid_set (int argc, const char **argv, struct ngadmin *nga)
+{
+ const struct swi_attr *sa;
+ unsigned char port;
+ unsigned short vlan;
+ int i;
+
+
+ if (argc != 2) {
+ printf("usage: vlan pvid set <port> <vlan>\n");
+ return 1;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ return 1;
+ }
+
+ port = strtoul(argv[0], NULL, 0);
+ vlan = strtoul(argv[1], NULL, 0);
+
+ if (port < 1 || port > sa->ports) {
+ printf("port out of range\n");
+ return 1;
+ }
+
+ if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
+ printf("vlan out of range\n");
+ return 1;
+ }
+
+ i = ngadmin_setPVID(nga, port, vlan);
+ printErrCode(i);
+
+
+ return 0;
+}
+
+
+int do_vlan_pvid_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+ unsigned short *ports = NULL;
+ const struct swi_attr *sa;
+ int i, ret = 0;
+
+
+ if (argc > 0) {
+ printf("this command takes no argument\n");
+ ret = 1;
+ goto end;
+ }
+
+ sa = ngadmin_getCurrentSwitch(nga);
+ if (sa == NULL) {
+ printf("must be logged\n");
+ ret = 1;
+ goto end;
+ }
+
+ ports = malloc(sa->ports * sizeof(unsigned short));
+ i = ngadmin_getAllPVID(nga, ports);
+ if (i != ERR_OK) {
+ printErrCode(i);
+ ret = 1;
+ goto end;
+ }
+
+ printf("Port\t");
+ for (i = 1; i <= sa->ports; i++)
+ printf("%i\t", i);
+ putchar('\n');
+
+ printf("VLAN\t");
+ for (i = 0; i < sa->ports; i++)
+ printf("%u\t", ports[i]);
+ putchar('\n');
+
+end:
+ free(ports);
+
+ return ret;
+}
+
+
--- /dev/null
+
+#include "commands.h"
+
+
+/* bitrate */
+int do_bitrate_set (int argc, const char **argv, struct ngadmin *nga);
+int do_bitrate_show (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* cabletest */
+int do_cabletest (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* defaults */
+int do_defaults (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* firmware */
+int do_firmware_show (int argc, const char **argv, struct ngadmin *nga);
+int do_firmware_upgrade (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* help */
+int do_help (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* igmp */
+int do_igmp_set (int argc, const char **argv, struct ngadmin *nga);
+int do_igmp_show (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* list */
+int do_list (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* login */
+int do_login (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* mirror */
+int do_mirror_disable (int argc, const char **argv, struct ngadmin *nga);
+int do_mirror_set (int argc, const char **argv, struct ngadmin *nga);
+int do_mirror_show (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* name */
+int do_name_show (int argc, const char **argv, struct ngadmin *nga);
+int do_name_set (int argc, const char **argv, struct ngadmin *nga);
+int do_name_clear (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* netconf */
+int do_netconf_set (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* password */
+int do_password_change (int argc, const char **argv, struct ngadmin *nga);
+int do_password_set (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* ports */
+int do_ports_state (int argc, const char **argv, struct ngadmin *nga);
+int do_ports_statistics_reset (int argc, const char **argv, struct ngadmin *nga);
+int do_ports_statistics_show (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* qos */
+int do_qos_mode (int argc, const char **argv, struct ngadmin *nga);
+int do_qos_set (int argc, const char **argv, struct ngadmin *nga);
+int do_qos_show (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* quit */
+int do_quit (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* restart */
+int do_restart (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* scan */
+int do_scan (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* stormfilter */
+int do_stormfilter_enable (int argc, const char **argv, struct ngadmin *nga);
+int do_stormfilter_disable (int argc, const char **argv, struct ngadmin *nga);
+int do_stormfilter_set (int argc, const char **argv, struct ngadmin *nga);
+int do_stormfilter_show (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* tree */
+int do_tree (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* vlan */
+int do_vlan_8021q_del (int argc, const char **argv, struct ngadmin *nga);
+int do_vlan_port_set (int argc, const char **argv, struct ngadmin *nga);
+int do_vlan_port_show (int argc, const char **argv, struct ngadmin *nga);
+int do_vlan_8021q_set (int argc, const char **argv, struct ngadmin *nga);
+int do_vlan_8021q_show (int argc, const char **argv, struct ngadmin *nga);
+int do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga);
+int do_vlan_mode_show (int argc, const char **argv, struct ngadmin *nga);
+int do_vlan_pvid_set (int argc, const char **argv, struct ngadmin *nga);
+int do_vlan_pvid_show (int argc, const char **argv, struct ngadmin *nga);
+
+
+/* commands structure */
+COM_ROOT_START(commands)
+ COM_START(bitrate)
+ COM_TERM(set, do_bitrate_set)
+ COM_TERM(show, do_bitrate_show)
+ COM_END
+
+ COM_TERM(cabletest, do_cabletest)
+
+ COM_TERM(defaults, do_defaults)
+
+ COM_START(firmware)
+ COM_TERM(show, do_firmware_show)
+ COM_TERM(upgrade, do_firmware_upgrade)
+ COM_END
+
+ COM_TERM(help, do_help)
+
+ COM_START(igmp)
+ COM_TERM(set, do_igmp_set)
+ COM_TERM(show, do_igmp_show)
+ COM_END
+
+ COM_TERM(list, do_list)
+
+ COM_TERM(login, do_login)
+
+ COM_START(mirror)
+ COM_TERM(disable, do_mirror_disable)
+ COM_TERM(set, do_mirror_set)
+ COM_TERM(show, do_mirror_show)
+ COM_END
+
+ COM_START(name)
+ COM_TERM(show, do_name_show)
+ COM_TERM(set, do_name_set)
+ COM_TERM(clear, do_name_clear)
+ COM_END
+
+ COM_START(netconf)
+ COM_TERM(set, do_netconf_set)
+ COM_END
+
+ COM_START(password)
+ COM_TERM(change, do_password_change)
+ COM_TERM(set, do_password_set)
+ COM_END
+
+ COM_START(ports)
+ COM_TERM(state, do_ports_state)
+ COM_START(statistics)
+ COM_TERM(reset, do_ports_statistics_reset)
+ COM_TERM(show, do_ports_statistics_show)
+ COM_END
+ COM_END
+
+ COM_START(qos)
+ COM_TERM(mode, do_qos_mode)
+ COM_TERM(set, do_qos_set)
+ COM_TERM(show, do_qos_show)
+ COM_END
+
+ COM_TERM(quit, do_quit)
+
+ COM_TERM(restart, do_restart)
+
+ COM_TERM(scan, do_scan)
+
+ COM_START(stormfilter)
+ COM_TERM(enable, do_stormfilter_enable)
+ COM_TERM(disable, do_stormfilter_disable)
+ COM_TERM(set, do_stormfilter_set)
+ COM_TERM(show, do_stormfilter_show)
+ COM_END
+
+ COM_TERM(tree, do_tree)
+
+ COM_START(vlan)
+ COM_START(802.1q)
+ COM_TERM(del, do_vlan_8021q_del)
+ COM_TERM(set, do_vlan_8021q_set)
+ COM_TERM(show, do_vlan_8021q_show)
+ COM_END
+ COM_START(mode)
+ COM_TERM(set, do_vlan_mode_set)
+ COM_TERM(show, do_vlan_mode_show)
+ COM_END
+ COM_START(port)
+ COM_TERM(set, do_vlan_port_set)
+ COM_TERM(show, do_vlan_port_show)
+ COM_END
+ COM_START(pvid)
+ COM_TERM(set, do_vlan_pvid_set)
+ COM_TERM(show, do_vlan_pvid_show)
+ COM_END
+ COM_END
+COM_ROOT_END
+
+
--- /dev/null
+
+#ifndef DEF_COMMANDS
+#define DEF_COMMANDS
+
+
+#include "common.h"
+
+
+struct TreeNode {
+ const char *name;
+ int (*comfunc)(int, const char**, struct ngadmin*);
+ const struct TreeNode *sub;
+};
+
+
+#define COM_ROOT_START(v) const struct TreeNode v = {.name = "<root>", .comfunc = NULL, .sub = (const struct TreeNode[]){
+#define COM_ROOT_END {.name = NULL, .comfunc = NULL, .sub = NULL}}};
+#define COM_START(nam) {.name = #nam, .comfunc = NULL, .sub = (const struct TreeNode[]){
+#define COM_END {.name = NULL, .comfunc = NULL, .sub = NULL}}},
+#define COM_TERM(nam, func) {.name = #nam, .comfunc = func, .sub = NULL},
+
+
+extern const struct TreeNode commands;
+
+
+#endif
+
--- /dev/null
+
+#include "common.h"
+
+
+void printErrCode (int err)
+{
+ switch (err) {
+ case ERR_OK:
+ break;
+
+ case ERR_NET:
+ printf("network error\n");
+ break;
+
+ case ERR_NOTLOG:
+ printf("no switch selected\n");
+ break;
+
+ case ERR_DENIED:
+ printf("access denied\n");
+ break;
+
+ case ERR_BADPASS:
+ printf("wrong password\n");
+ break;
+
+ case ERR_BADID:
+ printf("bad switch id\n");
+ break;
+
+ case ERR_INVARG:
+ printf("invalid argument\n");
+ break;
+
+ case ERR_TIMEOUT:
+ printf("timeout\n");
+ break;
+
+ case ERR_NOTIMPL:
+ printf("not implemented\n");
+ break;
+
+ default:
+ printf("unknown status code (%i)\n", err);
+ }
+}
+
+
+const char* const bitrates[] = {
+ "nl",
+ "512K",
+ "1M",
+ "2M",
+ "4M",
+ "8M",
+ "16M",
+ "32M",
+ "64M",
+ "128M",
+ "256M",
+ "512M",
+ NULL
+};
+
+
+const char* const prio[]={
+ NULL,
+ "high",
+ "medium",
+ "normal",
+ "low",
+ NULL
+};
+
+
+int parseBitrate (const char *s)
+{
+ int i;
+
+ for (i = 0; bitrates[i] != NULL && strcasecmp(bitrates[i], s) != 0; i++);
+
+ return i;
+}
+
+
+char parsePrio (const char *s)
+{
+ int i;
+
+ for (i = 1; prio[i] != NULL && strcasecmp(prio[i], s) != 0; i++);
+
+ return (char)i;
+}
+
+
+void displaySwitchTab (const struct swi_attr *sa, int nb)
+{
+ int i=0;
+
+ if (nb == 0) {
+ printf("no switch found\n");
+ return;
+ }
+
+ printf("Num\tMac\t\t\tProduct\t\tName\t\t\tIP/mask\t\t\tDHCP\tPorts\tFirmware\n");
+
+ for (i = 0; i < nb; i++) {
+ printf("%i\t%s\t%s\t%s\t\t%s/", i, ether_ntoa(&sa[i].mac), sa[i].product, sa[i].name, inet_ntoa(sa[i].nc.ip));
+ printf("%s\t%s\t%i\t%s\n", inet_ntoa(sa[i].nc.netmask), ( sa[i].nc.dhcp ? "Yes" : "No" ), sa[i].ports, sa[i].firmware);
+ }
+
+ printf("\nfound %i switch(es)\n", nb);
+}
+
+
+int trim (char *txt, int start)
+{
+ char *p;
+
+ if (txt == NULL)
+ return 0;
+
+ p = txt + start;
+ for (p--; p >= txt && (*p == ' ' || *p == '\n'); *p-- = 0);
+
+ return p - txt + 1;
+}
+
+
+int explode (const char *commande, char** tab, int maximum)
+{
+ const char *start, *end;
+ int n = 0, len;
+
+
+ for (end = commande; ; n++) {
+ for (start = end; *start == ' ' && *start != 0; start++);
+ for (end = start; (*end != ' ' || n >= maximum - 1 ) && *end != 0; end++);
+
+ len = end - start;
+ if (len == 0)
+ break;
+
+ tab[n] = malloc(sizeof(char) * (len + 1));
+ memcpy(tab[n], start, len);
+ tab[n][len] = 0;
+ }
+
+
+ return n;
+}
+
+
--- /dev/null
+
+#ifndef DEF_COMMON
+#define DEF_COMMON
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include <ngadmin.h>
+
+
+#define UNUSED __attribute__((unused))
+#define NORET __attribute__((noreturn))
+
+
+extern int main_loop_continue;
+extern struct termios current_term;
+
+
+extern const char * const bitrates[], * const prio[];
+
+
+void displaySwitchTab (const struct swi_attr *sa, int nb);
+void printErrCode (int err);
+int parseBitrate (const char *s);
+char parsePrio (const char *s);
+
+
+int trim (char *txt, int start);
+
+int explode (const char *commande, char** tab, int maximum);
+
+
+#endif
+
--- /dev/null
+
+AC_PREREQ([2.68])
+AC_INIT([ngadmin], [0.1], [admin@darkcoven.tk])
+AC_CONFIG_MACRO_DIR([.])
+AC_CONFIG_SRCDIR([raw/src/attr.c])
+AC_CONFIG_HEADERS([config.h])
+
+AM_INIT_AUTOMAKE
+
+# check for programs
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_PROG_LIBTOOL
+AC_PROG_INSTALL
+
+LT_PREREQ([2.4])
+LT_INIT
+
+
+# enable/disable readline
+AC_ARG_WITH([readline],
+ [AS_HELP_STRING([--with-readline], [support fancy command line editing @<:@default=check@:>@])],
+ [with_readline="$withval"], [with_readline=yes])
+
+# enable debug build
+AC_ARG_ENABLE(debug,
+ [AS_HELP_STRING([--enable-debug], [enable debug mode [default=no]])],
+ [enable_debug=yes], [enable_debug=no])
+
+# enable/disable documentation generation
+AC_ARG_ENABLE(doc,
+ [AS_HELP_STRING([--enable-doc], [enable documentation generation [default=no]])],
+ [enable_doc=yes], [enable_doc=no])
+
+# enable/disable build of NgSpy
+AC_ARG_ENABLE(spy,
+ [AS_HELP_STRING([--enable-spy], [enable NgSpy [default=no]])],
+ [enable_spy=yes], [enable_spy=no])
+AM_CONDITIONAL(ENABLE_SPY, test x$enable_spy = xyes)
+
+# enable/disable build of NgEmu
+AC_ARG_ENABLE(emu,
+ [AS_HELP_STRING([--enable-emu], [enable NgEmu [default=no]])],
+ [enable_emu=yes], [enable_emu=no])
+AM_CONDITIONAL(ENABLE_EMU, test x$enable_emu = xyes)
+
+
+
+AS_IF([test "x${enable_doc}" = "xyes"], [
+ AC_CHECK_PROGS([DOXYGEN], [doxygen])
+ AS_IF([test -z "$DOXYGEN"], [
+ AC_MSG_ERROR([Doxygen not found])
+ ])
+])
+AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
+
+
+AS_IF([test "x${with_readline}" != "xno"], [
+ AC_CHECK_LIB([readline], [readline], [
+ AC_SUBST([READLINE_LIBS], [-lreadline])
+ AC_DEFINE([HAVE_LIBREADLINE], [1], [Define if you have libreadline])
+ ], [
+ AC_MSG_FAILURE([readline test failed (--without-readline to disable)])
+ ])
+])
+
+
+
+CFLAGS="-Wall -Wextra -Os"
+
+if test "x${enable_debug}" = xyes; then
+ CFLAGS="$CFLAGS -g"
+else
+ CFLAGS="$CFLAGS -fomit-frame-pointer"
+ LDFLAGS="$LDFLAGS -s"
+fi
+
+
+# check for header files
+AC_CHECK_HEADERS([arpa/inet.h stdlib.h string.h sys/ioctl.h termios.h unistd.h])
+AC_HEADER_STDBOOL
+
+# check for typedefs, structures, and compiler characteristics
+AC_C_INLINE
+AC_TYPE_SIZE_T
+
+# check for library functions
+AC_FUNC_MALLOC
+AC_CHECK_FUNCS([inet_ntoa memchr memset select socket strcasecmp strdup strtol strtoul])
+
+
+AC_CONFIG_FILES([
+ Makefile
+ raw/Makefile
+ raw/include/Makefile
+ raw/src/Makefile
+ lib/Makefile
+ lib/include/Makefile
+ lib/src/Makefile
+ lib/src/libngadmin.pc
+ cli/Makefile
+ cli/man/Makefile
+ cli/src/Makefile
+])
+
+AM_COND_IF([ENABLE_SPY], [
+ AC_CONFIG_FILES([
+ spy/Makefile
+ spy/man/Makefile
+ spy/src/Makefile
+ ])
+])
+
+AM_COND_IF([ENABLE_EMU], [
+ AC_CONFIG_FILES([
+ emu/Makefile
+ emu/man/Makefile
+ emu/src/Makefile
+ ])
+])
+
+
+AC_OUTPUT
+
+
+echo "
+${PACKAGE_NAME} version ${PACKAGE_VERSION}
+Prefix.............: ${prefix}
+Debug..............: ${enable_debug}
+Doc................: ${enable_doc}
+Compiler...........: ${CC} ${CFLAGS} ${CPPFLAGS}
+Readline suppport..: ${with_readline}
+Spy................: ${enable_spy}
+Emulator...........: ${enable_emu}
+"
+
+
+++ /dev/null
-
-CC=gcc
-CFLAGS=-I../raw/include/ -W -Wall -Wextra -Os
-LDFLAGS=-L../raw -lrawnsdp
-EXEC=ngdump
-
-SRC=$(wildcard *.c)
-OBJ=$(SRC:.c=.o)
-
-
-ifeq ($(DEBUG), yes)
-CFLAGS+=-g
-LDFLAGS+=-g
-else
-CFLAGS+=-fomit-frame-pointer
-LDFLAGS+=-s
-endif
-
-
-$(EXEC): $(OBJ)
- $(CC) $^ -o $@ $(LDFLAGS)
-
-%.o: %.c
- $(CC) -c $^ -o $@ $(CFLAGS)
-
-
-clean:
- @rm -f *.o
-
-mrproper: clean
- @rm -f $(EXEC)
-
-
-
+++ /dev/null
-
-#include <stdio.h>
-#include <unistd.h>
-#include <arpa/inet.h>
-
-#include <protocol.h>
-#include <attr.h>
-
-
-int main (void)
-{
- char buffer[1500];
- struct ng_packet np;
- int err = 0, s, len;
- struct sockaddr_in local, remote;
- socklen_t slen = sizeof(struct sockaddr_in);
- unsigned char error;
- unsigned short attr_error;
- List *attr;
- ListNode *ln;
- struct attr *at;
-
-
- s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (s < 0) {
- perror("socket");
- err = 1;
- goto end;
- };
-
-
- memset(&local, 0, sizeof(struct sockaddr_in));
- local.sin_family = AF_INET;
- local.sin_addr.s_addr = htonl(INADDR_ANY);
- local.sin_port = htons(SWITCH_PORT);
-
- if (bind(s, (struct sockaddr*)&local, sizeof(struct sockaddr_in)) < 0) {
- perror("bind");
- err = 2;
- goto end;
- }
-
- while (1) {
-
- len = recvfrom(s, buffer, sizeof(buffer), 0, (struct sockaddr*)&remote, &slen);
- if (len < 0) {
- perror("recvfrom");
- err = 3;
- goto end;
- }
-
- printf("---------------------------------\n");
-
- np.buffer = buffer;
- np.maxlen = len;
- initNgPacket(&np);
-
- attr = createEmptyList();
-
- if (ntohs(remote.sin_port) != CLIENT_PORT ||
- len < (int)sizeof(struct ng_header) ||
- !validateNgHeader(np.nh, 0, NULL, NULL, 0) ||
- extractPacketAttributes(&np, attr, 0) < 0) {
- printf("wrong packet\n");
- goto end;
- }
-
- printf("received %d attribute(s)\n", attr->count);
-
- for (ln = attr->first; ln != NULL; ln = ln->next) {
- at = ln->data;
- printf("received attribute code = %04X, length = %d\n", at->attr, at->size);
- }
-
- destroyList(attr, (void(*)(void*))freeAttr);
-
- printf("---------------------------------\n\n");
- }
-
- close(s);
-
-end:
- return err;
-}
-
--- /dev/null
+
+SUBDIRS = man src
+
+++ /dev/null
-
-
-
-all: lib libdoc
-
-
-
-lib:
- @+$(MAKE) -C src
-
-libdoc:
- doxygen ngadmin
-
-
-clean:
- @rm -rf doc
- @+$(MAKE) -C src clean
-
-mrproper: clean
- @+$(MAKE) -C src mrproper
-
--- /dev/null
+
+SUBDIRS = include src
+
+
+if HAVE_DOXYGEN
+
+all-local: doc
+
+
+doc:
+ $(DOXYGEN) ngadmin
+
+
+clean-local:
+ rm -rf $(top_builddir)/lib/doc
+
+endif
+
--- /dev/null
+
+include_HEADERS = ngadmin.h
+
#include <netinet/ether.h>
-#ifdef BUILD_LIB
-#define EXPORT __attribute__((visibility("default")))
-#else
-#define EXPORT
-#endif
-
-
/**
* Maximum size of product string.
* @param iface The network interface to use.
* @return A pointer to a ngadmin structure, or NULL if an error occurred.
*/
-struct ngadmin* ngadmin_init (const char *iface) EXPORT;
+struct ngadmin* ngadmin_init (const char *iface);
/**
* @param nga A pointer to the ngadmin structure.
* @return ERR_OK when everything is well or an error code otherwise.
*/
-int ngadmin_close (struct ngadmin *nga) EXPORT;
+int ngadmin_close (struct ngadmin *nga);
/**
* @param nga A pointer to the ngadmin structure.
* @return ERR_OK when everything is well or an error code otherwise.
*/
-int ngadmin_forceInterface (struct ngadmin *nga) EXPORT;
+int ngadmin_forceInterface (struct ngadmin *nga);
/**
* @param value Enable or disable the systematic use of broadcast packets.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setKeepBroadcasting (struct ngadmin *nga, bool value) EXPORT;
+int ngadmin_setKeepBroadcasting (struct ngadmin *nga, bool value);
/**
* @param value Enable or disable the use of the global broadcast address.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_useGlobalBroadcast (struct ngadmin *nga, bool value) EXPORT;
+int ngadmin_useGlobalBroadcast (struct ngadmin *nga, bool value);
/**
* @param pass The password string to use.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setPassword (struct ngadmin *nga, const char *pass) EXPORT;
+int ngadmin_setPassword (struct ngadmin *nga, const char *pass);
/**
* @param tv A pointer to a timeval structure.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setTimeout (struct ngadmin *nga, const struct timeval *tv) EXPORT;
+int ngadmin_setTimeout (struct ngadmin *nga, const struct timeval *tv);
/**
* @param nga A pointer to the ngadmin structure.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_scan (struct ngadmin *nga) EXPORT;
+int ngadmin_scan (struct ngadmin *nga);
/**
* @param nb A pointer to an integer which will receive the number of switches.
* @return A pointer to an array of switch characteristics.
*/
-const struct swi_attr* ngadmin_getSwitchTab (struct ngadmin *nga, int *nb) EXPORT;
+const struct swi_attr* ngadmin_getSwitchTab (struct ngadmin *nga, int *nb);
/**
* @param nga A pointer to the ngadmin structure.
* @return A pointer the switch characteristics or NULL if you are not logged.
**/
-const struct swi_attr* ngadmin_getCurrentSwitch (struct ngadmin *nga) EXPORT;
+const struct swi_attr* ngadmin_getCurrentSwitch (struct ngadmin *nga);
* @param filename A path to the file of the new firmware to send.
* @return ERR_NOTIMPL
**/
-int ngadmin_upgradeFirmware (struct ngadmin *nga, const char *filename) EXPORT;
+int ngadmin_upgradeFirmware (struct ngadmin *nga, const char *filename);
/**
* @param id The id (position in the switch array) of the switch you want to login to.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_login (struct ngadmin *nga, int id) EXPORT;
+int ngadmin_login (struct ngadmin *nga, int id);
/**
* Must not be NULL. The array size must be ports_count*sizeof(unsigned char).
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getPortsStatus (struct ngadmin *nga, unsigned char *ports) EXPORT;
+int ngadmin_getPortsStatus (struct ngadmin *nga, unsigned char *ports);
/**
* @param name The name string to use. A NULL value clears the name.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setName (struct ngadmin *nga, const char *name) EXPORT;
+int ngadmin_setName (struct ngadmin *nga, const char *name);
/**
* The array size must be ports_count*sizeof(struct port_stats).
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getPortsStatistics (struct ngadmin *nga, struct port_stats *ps) EXPORT;
+int ngadmin_getPortsStatistics (struct ngadmin *nga, struct port_stats *ps);
/**
* @param nga A pointer to the ngadmin structure.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_resetPortsStatistics (struct ngadmin *nga) EXPORT;
+int ngadmin_resetPortsStatistics (struct ngadmin *nga);
/**
* @param pass The new password string to use.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_changePassword (struct ngadmin *nga, const char* pass) EXPORT;
+int ngadmin_changePassword (struct ngadmin *nga, const char* pass);
/**
* @param s A pointer to an integer which will receive 0 or 1.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getStormFilterState (struct ngadmin *nga, int *s) EXPORT;
+int ngadmin_getStormFilterState (struct ngadmin *nga, int *s);
/**
* @param s An integer with value 0 or 1.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setStormFilterState (struct ngadmin *nga, int s) EXPORT;
+int ngadmin_setStormFilterState (struct ngadmin *nga, int s);
/**
* The array size must be ports_count*sizeof(int).
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getStormFilterValues (struct ngadmin *nga, int *ports) EXPORT;
+int ngadmin_getStormFilterValues (struct ngadmin *nga, int *ports);
/**
* The array size must be ports_count*sizeof(int).
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setStormFilterValues (struct ngadmin *nga, const int *ports) EXPORT;
+int ngadmin_setStormFilterValues (struct ngadmin *nga, const int *ports);
/**
* The array size must be ports_count*sizeof(int).
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getBitrateLimits (struct ngadmin *nga, int *ports) EXPORT;
+int ngadmin_getBitrateLimits (struct ngadmin *nga, int *ports);
/**
* The array size must be ports_count*sizeof(int).
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setBitrateLimits (struct ngadmin *nga, const int *ports) EXPORT;
+int ngadmin_setBitrateLimits (struct ngadmin *nga, const int *ports);
/**
* @param s A pointer to an integer. Must not be NULL.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getQOSMode (struct ngadmin *nga, int *s) EXPORT;
+int ngadmin_getQOSMode (struct ngadmin *nga, int *s);
/**
* @param s An integer with the new mode.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setQOSMode (struct ngadmin *nga, int s) EXPORT;
+int ngadmin_setQOSMode (struct ngadmin *nga, int s);
/**
The array size must be ports_count*sizeof(ports).
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getQOSValues (struct ngadmin *nga, char *ports) EXPORT;
+int ngadmin_getQOSValues (struct ngadmin *nga, char *ports);
/**
The array size must be ports_count*sizeof(ports).
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setQOSValues (struct ngadmin *nga, const char *ports) EXPORT;
+int ngadmin_setQOSValues (struct ngadmin *nga, const char *ports);
/**
* @param nga A pointer to the ngadmin structure.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_restart (struct ngadmin *nga) EXPORT;
+int ngadmin_restart (struct ngadmin *nga);
/**
* @param nga A pointer to the ngadmin structure.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_defaults (struct ngadmin *nga) EXPORT;
+int ngadmin_defaults (struct ngadmin *nga);
/**
The array size must be (1+ports_count)*sizeof(char).
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getMirror (struct ngadmin *nga, char *ports) EXPORT;
+int ngadmin_getMirror (struct ngadmin *nga, char *ports);
/**
If it is NULL, port mirroring is disabled.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setMirror (struct ngadmin *nga, const char *ports) EXPORT;
+int ngadmin_setMirror (struct ngadmin *nga, const char *ports);
/**
* @param ic A pointer to an igmp_conf structure. Must not be NULL.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getIGMPConf (struct ngadmin *nga, struct igmp_conf *ic) EXPORT;
+int ngadmin_getIGMPConf (struct ngadmin *nga, struct igmp_conf *ic);
/**
* @param ic A pointer to an igmp_conf structure. Must not be NULL.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setIGMPConf (struct ngadmin *nga, const struct igmp_conf *ic) EXPORT;
+int ngadmin_setIGMPConf (struct ngadmin *nga, const struct igmp_conf *ic);
/**
* @param nb The number of elements in the array.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_cabletest (struct ngadmin *nga, struct cabletest *ct, int nb) EXPORT;
+int ngadmin_cabletest (struct ngadmin *nga, struct cabletest *ct, int nb);
/**
Only non-zero fields of the structure are taken into account.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setNetConf (struct ngadmin *nga, const struct net_conf *nc) EXPORT;
+int ngadmin_setNetConf (struct ngadmin *nga, const struct net_conf *nc);
/**
* @param t A pointer to an integer which will receive the VLAN type. Must not be NULL.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getVLANType (struct ngadmin *nga, int *t) EXPORT;
+int ngadmin_getVLANType (struct ngadmin *nga, int *t);
/**
* @param t An integer which contains the new VLAN type.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setVLANType (struct ngadmin *nga, int t) EXPORT;
+int ngadmin_setVLANType (struct ngadmin *nga, int t);
/**
number of associated VLAN. Must not be NULL.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getVLANPortConf (struct ngadmin *nga, unsigned char *ports) EXPORT;
+int ngadmin_getVLANPortConf (struct ngadmin *nga, unsigned char *ports);
/**
number of associated VLAN. Must not be NULL.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setVLANPortConf (struct ngadmin *nga, const unsigned char *ports) EXPORT;
+int ngadmin_setVLANPortConf (struct ngadmin *nga, const unsigned char *ports);
/**
It will receive the actual number of VLAN written in the arrays.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsigned char *ports, int *nb) EXPORT;
+int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsigned char *ports, int *nb);
/**
configuration. Must not be NULL.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getVLANDotConf (struct ngadmin *nga, unsigned short vlan, unsigned char *ports) EXPORT;
+int ngadmin_getVLANDotConf (struct ngadmin *nga, unsigned short vlan, unsigned char *ports);
/**
configuration. Must not be NULL.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setVLANDotConf (struct ngadmin *nga, unsigned short vlan, const unsigned char *ports) EXPORT;
+int ngadmin_setVLANDotConf (struct ngadmin *nga, unsigned short vlan, const unsigned char *ports);
/**
* @param vlan The VLAN you want to destroy.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_VLANDestroy (struct ngadmin *nga, unsigned short vlan) EXPORT;
+int ngadmin_VLANDestroy (struct ngadmin *nga, unsigned short vlan);
/**
* The array size must be sizeof(unsigned short)*ports_count.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_getAllPVID (struct ngadmin *nga, unsigned short *ports) EXPORT;
+int ngadmin_getAllPVID (struct ngadmin *nga, unsigned short *ports);
/**
* @param vlan The new PVID value.
* @return ERR_OK when everything is well or an error code otherwise.
**/
-int ngadmin_setPVID (struct ngadmin *nga, unsigned char port, unsigned short vlan) EXPORT;
+int ngadmin_setPVID (struct ngadmin *nga, unsigned char port, unsigned short vlan);
#ifdef __cplusplus
+++ /dev/null
-
-CC=gcc
-CFLAGS=-DBUILD_LIB -I../../raw/include/ -I../include/ -W -Wall -Wextra -Os -fno-strict-aliasing -fvisibility=hidden -fPIC
-LDFLAGS=-L../../raw/ -lrawnsdp
-EXEC=../libngadmin.so
-
-SRC=$(wildcard *.c)
-OBJ=$(SRC:.c=.o)
-
-
-ifeq ($(DEBUG), yes)
-CFLAGS+=-g
-LDFLAGS+=-g
-else
-CFLAGS+=-fomit-frame-pointer
-LDFLAGS+=-s
-endif
-
-
-$(EXEC): $(OBJ)
- $(CC) $^ -shared -o $@ $(LDFLAGS)
-
-%.o: %.c
- $(CC) -c $^ -o $@ $(CFLAGS)
-
-
-clean:
- @rm -f *.o
-
-mrproper: clean
- @rm -f $(EXEC)
-
-
--- /dev/null
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libngadmin.pc
+
+lib_LTLIBRARIES = libngadmin.la
+
+libngadmin_la_SOURCES = network.c bitrate.c firmware.c libconf.c mirror.c misc.c \
+ netconf.c ports.c qos.c session.c vlan.c
+libngadmin_la_CPPFLAGS = -I$(top_srcdir)/raw/include/ -I$(top_srcdir)/lib/include/
+libngadmin_la_CFLAGS = -fno-strict-aliasing
+libngadmin_la_LDFLAGS = -export-symbols-regex '^ngadmin_' -version-info 0:0:0
+libngadmin_la_LIBADD = $(top_builddir)/raw/src/librawnsdp.la
+
--- /dev/null
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libngadmin
+Description: Library to manage Netgear switches using NSDP protocol
+Version: @VERSION@
+Requires:
+Libs: -L${libdir} -lngadmin
+Cflags: -I${includedir}
+
+++ /dev/null
-
-
-
-all: lib libdoc
-
-
-
-lib:
- @+$(MAKE) -C src
-
-libdoc:
- doxygen rawnsdp
-
-
-clean:
- @rm -rf doc
- @+$(MAKE) -C src clean
-
-mrproper: clean
- @+$(MAKE) -C src mrproper
-
--- /dev/null
+
+SUBDIRS = include src
+
--- /dev/null
+
+noinst_HEADERS = attr.h list.h protocol.h
+
+++ /dev/null
-
-CC=gcc
-AR=ar
-CFLAGS=-I../include/ -I../../lib/include/ -W -Wall -Wextra -Os -fno-strict-aliasing -fvisibility=hidden -fPIC
-EXEC=../librawnsdp.a
-
-SRC=$(wildcard *.c)
-OBJ=$(SRC:.c=.o)
-
-
-ifeq ($(DEBUG), yes)
-CFLAGS+=-g
-else
-CFLAGS+=-fomit-frame-pointer
-endif
-
-
-$(EXEC): $(OBJ)
- $(AR) rcs $@ $^
-
-%.o: %.c
- $(CC) -c $^ -o $@ $(CFLAGS)
-
-
-clean:
- @rm -f *.o
-
-mrproper: clean
- @rm -f $(EXEC)
-
-
--- /dev/null
+
+noinst_LTLIBRARIES = librawnsdp.la
+
+librawnsdp_la_SOURCES = attr.c list.c protocol.c
+librawnsdp_la_CPPFLAGS = -I$(top_srcdir)/raw/include/ -I$(top_srcdir)/lib/include/
+librawnsdp_la_CFLAGS = -fno-strict-aliasing
+
--- /dev/null
+
+SUBDIRS = man src
+
--- /dev/null
+
+bin_PROGRAMS = ngspy
+
+ngspy_SOURCES = spy.c
+ngspy_CPPFLAGS = -I$(top_srcdir)/raw/include/
+ngspy_LDADD = $(top_builddir)/raw/src/librawnsdp.la
+
--- /dev/null
+
+#include <stdio.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+
+#include <protocol.h>
+#include <attr.h>
+
+
+int main (void)
+{
+ char buffer[1500];
+ struct ng_packet np;
+ int err = 0, s, len;
+ struct sockaddr_in local, remote;
+ socklen_t slen = sizeof(struct sockaddr_in);
+ unsigned char error;
+ unsigned short attr_error;
+ List *attr;
+ ListNode *ln;
+ struct attr *at;
+
+
+ s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (s < 0) {
+ perror("socket");
+ err = 1;
+ goto end;
+ };
+
+
+ memset(&local, 0, sizeof(struct sockaddr_in));
+ local.sin_family = AF_INET;
+ local.sin_addr.s_addr = htonl(INADDR_ANY);
+ local.sin_port = htons(SWITCH_PORT);
+
+ if (bind(s, (struct sockaddr*)&local, sizeof(struct sockaddr_in)) < 0) {
+ perror("bind");
+ err = 2;
+ goto end;
+ }
+
+ while (1) {
+
+ len = recvfrom(s, buffer, sizeof(buffer), 0, (struct sockaddr*)&remote, &slen);
+ if (len < 0) {
+ perror("recvfrom");
+ err = 3;
+ goto end;
+ }
+
+ printf("---------------------------------\n");
+
+ np.buffer = buffer;
+ np.maxlen = len;
+ initNgPacket(&np);
+
+ attr = createEmptyList();
+
+ if (ntohs(remote.sin_port) != CLIENT_PORT ||
+ len < (int)sizeof(struct ng_header) ||
+ !validateNgHeader(np.nh, 0, NULL, NULL, 0) ||
+ extractPacketAttributes(&np, attr, 0) < 0) {
+ printf("wrong packet\n");
+ goto end;
+ }
+
+ printf("received %d attribute(s)\n", attr->count);
+
+ for (ln = attr->first; ln != NULL; ln = ln->next) {
+ at = ln->data;
+ printf("received attribute code = %04X, length = %d\n", at->attr, at->size);
+ }
+
+ destroyList(attr, (void(*)(void*))freeAttr);
+
+ printf("---------------------------------\n\n");
+ }
+
+ close(s);
+
+end:
+ return err;
+}
+