X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=cli%2Fcom_netconf.c;h=d44b83a161260464f902bb10faa8cd59f63439ec;hb=1b72c10a906e2060054e84943f241614d857e236;hp=e4838b88d5ba24678b7b3455db48a013cb45d5b6;hpb=47fbfc0635ef174f71047d75c328f8e848e6a02d;p=ngadmin diff --git a/cli/com_netconf.c b/cli/com_netconf.c index e4838b8..d44b83a 100644 --- a/cli/com_netconf.c +++ b/cli/com_netconf.c @@ -2,79 +2,68 @@ #include "commands.h" - -bool do_netconf_set (int nb, const char **com, struct ngadmin *nga) { - - int i, k; - const struct swi_attr *sa; - struct net_conf nc; - bool ret=true; - - - if ( nb==0 ) { - printf("Usage: netconf set [dhcp yes|no] [ip ] [mask ] [gw ]\n"); - return false; - } - - if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) { - printf("must be logged\n"); - return false; - } - - - memset(&nc, 0, sizeof(struct net_conf)); - - for (k=0; k] [mask ] [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; } -