]> git.sur5r.net Git - ngadmin/blob - cli/com_netconf.c
e4838b88d5ba24678b7b3455db48a013cb45d5b6
[ngadmin] / cli / com_netconf.c
1
2 #include "commands.h"
3
4
5
6 bool do_netconf_set (int nb, const char **com, struct ngadmin *nga) {
7  
8  int i, k;
9  const struct swi_attr *sa;
10  struct net_conf nc;
11  bool ret=true;
12  
13  
14  if ( nb==0 ) {
15   printf("Usage: netconf set [dhcp yes|no] [ip <ip>] [mask <mask>] [gw <gw>]\n");
16   return false;
17  }
18  
19  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
20   printf("must be logged\n");
21   return false;
22  }
23  
24  
25  memset(&nc, 0, sizeof(struct net_conf));
26  
27  for (k=0; k<nb; k+=2) {
28   
29   if ( strcasecmp(com[k], "dhcp")==0 ) {
30    if ( strcasecmp(com[k+1], "yes")==0 ) {
31     nc.dhcp=true;
32    } else if ( strcasecmp(com[k+1], "no")==0 ) {
33     nc.dhcp=false;
34    } else {
35     printf("Incorrect DHCP value\n");
36     ret=false;
37     goto end;
38    }
39    
40   } else if ( strcasecmp(com[k], "ip")==0 ) {
41    if ( inet_aton(com[k+1], &nc.ip)==0 ) {
42     printf("Incorrect IP value\n");
43     ret=false;
44     goto end;
45    }
46    
47   } else if ( strcasecmp(com[k], "mask")==0 ) {
48    if ( inet_aton(com[k+1], &nc.netmask)==0 ) { // TODO: check if it is a correct mask
49     printf("Incorrect mask value\n");
50     ret=false;
51     goto end;
52    }
53    
54   } else if ( strcasecmp(com[k], "gw")==0 ) {
55    if ( inet_aton(com[k+1], &nc.gw)==0 ) {
56     printf("Incorrect gateway value\n");
57     ret=false;
58     goto end;
59    }
60    
61   }
62   
63  }
64  
65  
66  i=ngadmin_setNetConf(nga, &nc);
67  if ( i!=ERR_OK ) {
68   printErrCode(i);
69   ret=false;
70  }
71  
72  
73  end:
74  
75  return ret;
76  
77 }
78
79
80