5 int do_netconf_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
7 const struct swi_attr *sa;
8 const struct net_conf *nc;
12 printf("this command takes no argument\n");
16 sa = ngadmin_getCurrentSwitch(nga);
18 printf("must be logged\n");
23 printf("DHCP\t : %s\n", nc->dhcp ? "yes" : "no");
24 printf("IP\t : %s\n", inet_ntoa(nc->ip));
25 printf("Netmask\t : %s\n", inet_ntoa(nc->netmask));
26 printf("Gateway\t : %s\n", inet_ntoa(nc->gw));
33 int do_netconf_set (int argc, const char **argv, struct ngadmin *nga)
36 const struct swi_attr *sa;
41 printf("usage: netconf set [dhcp yes|no] [ip <ip>] [mask <mask>] [gw <gw>]\n");
45 sa = ngadmin_getCurrentSwitch(nga);
47 printf("must be logged\n");
51 memcpy(&nc, &sa->nc, sizeof(struct net_conf));
53 for (k = 0; k < argc - 1; k += 2) {
54 if (strcasecmp(argv[k], "dhcp") == 0) {
55 if (strcasecmp(argv[k + 1], "yes") == 0) {
57 } else if (strcasecmp(argv[k + 1], "no") == 0) {
60 printf("Incorrect DHCP value\n");
64 } else if (strcasecmp(argv[k], "ip") == 0) {
65 if (inet_aton(argv[k + 1], &nc.ip) == 0) {
66 printf("Incorrect IP value\n");
70 } else if (strcasecmp(argv[k], "mask") == 0) {
71 /* TODO: check if it is a correct mask */
72 if (inet_aton(argv[k + 1], &nc.netmask) == 0) {
73 printf("Incorrect mask value\n");
77 } else if (strcasecmp(argv[k], "gw") == 0) {
78 if (inet_aton(argv[k + 1], &nc.gw) == 0) {
79 printf("Incorrect gateway value\n");
86 i = ngadmin_setNetConf(nga, &nc);