#include "commands.h"
-bool do_mirror_disable (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga)
+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 false;
+ return 1;
}
-
i = ngadmin_setMirror(nga, NULL);
printErrCode(i);
- return true;
+ return 0;
}
-bool do_mirror_set (int nb, const char **com, struct ngadmin *nga)
+int do_mirror_set (int argc, const char **argv, struct ngadmin *nga)
{
const struct swi_attr *sa;
char *ports = NULL;
- bool ret = true;
- int i, k = 0;
+ int i, k = 0, ret = 0;
- if (nb < 3) {
- printf("Usage: mirror set <destination port> clone <port1> [<port2> ...]\n");
+ 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 = false;
+ ret = 1;
goto end;
}
ports = malloc((sa->ports + 1) * sizeof(char));
memset(ports, 0, sa->ports + 1);
- ports[0] = strtol(com[k++], NULL, 0);
- if (ports[0] < 1 || ports[0] > sa->ports || strcasecmp(com[k++], "clone") != 0) {
+ 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 = false;
+ ret = 1;
goto end;
}
- while (k < nb) {
- i = strtol(com[k++], NULL, 0);
+ while (k < argc) {
+ i = strtol(argv[k++], NULL, 0);
if (i < 1 || i > sa->ports) {
printf("port out of range\n");
- ret = false;
+ ret = 1;
goto end;
} else if (i == ports[0]) {
printf("destination port cannot be in port list\n");
- ret = false;
+ ret = 1;
goto end;
}
ports[i] = 1;
}
-bool do_mirror_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga)
+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 false;
+ return 1;
}
-
ports = malloc((sa->ports + 1) * sizeof(char));
i = ngadmin_getMirror(nga, ports);
if (i != ERR_OK) {
end:
free(ports);
- return true;
+ return 0;
}