From: darkcoven Date: Fri, 18 Oct 2013 21:20:37 +0000 (+0200) Subject: Cli: add command to show network configuration details X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=10b0f3e7cdf394f36dafe222fe1d722f0875b4ce;p=ngadmin Cli: add command to show network configuration details --- diff --git a/cli/man/ngcli.1 b/cli/man/ngcli.1 index 55422ef..6c3d863 100644 --- a/cli/man/ngcli.1 +++ b/cli/man/ngcli.1 @@ -180,6 +180,10 @@ Set the switch name to \fIname\fR. Show the switch name. . .TP +\fBnetconf show +Show the network configuration. +. +.TP \fBnetconf set\fR [ dhcp yes|no ] [ ip \fIip\fR ] [ mask\fI mask\fR ] \ [ gw\fI gw\fR ] Set various network related options. \fIip\fR, \fImask\fR and \fIgw\fR must be diff --git a/cli/src/com_netconf.c b/cli/src/com_netconf.c index d44b83a..31b09ef 100644 --- a/cli/src/com_netconf.c +++ b/cli/src/com_netconf.c @@ -2,6 +2,34 @@ #include "commands.h" +int do_netconf_show (int argc, const char **argv UNUSED, struct ngadmin *nga) +{ + const struct swi_attr *sa; + const struct net_conf *nc; + + + 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; + } + nc = &sa->nc; + + printf("DHCP\t : %s\n", nc->dhcp ? "yes" : "no"); + printf("IP\t : %s\n", inet_ntoa(nc->ip)); + printf("Netmask\t : %s\n", inet_ntoa(nc->netmask)); + printf("Gateway\t : %s\n", inet_ntoa(nc->gw)); + + + return 0; +} + + int do_netconf_set (int argc, const char **argv, struct ngadmin *nga) { int i, k, ret = 0; diff --git a/cli/src/commands.c b/cli/src/commands.c index 2d37ea8..7662c72 100644 --- a/cli/src/commands.c +++ b/cli/src/commands.c @@ -50,6 +50,7 @@ int do_name_clear (int argc, const char **argv, struct ngadmin *nga); /* netconf */ +int do_netconf_show (int argc, const char **argv, struct ngadmin *nga); int do_netconf_set (int argc, const char **argv, struct ngadmin *nga); @@ -145,6 +146,7 @@ COM_ROOT_START(commands) COM_END COM_START(netconf) + COM_TERM(show, do_netconf_show) COM_TERM(set, do_netconf_set) COM_END diff --git a/cli/src/common.c b/cli/src/common.c index 7d35301..74df335 100644 --- a/cli/src/common.c +++ b/cli/src/common.c @@ -110,12 +110,10 @@ void displaySwitchTab (const struct swi_attr *sa, int nb) return; } - printf("Num\tMac\t\t\tProduct\t\tName\t\t\tIP/mask\t\t\tDHCP\tPorts\tFirmware\n"); + printf("Num\tMac\t\t\tProduct\t\tName\t\t\tIP\t\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); - } + for (i = 0; i < nb; i++) + printf("%i\t%s\t%s\t%s\t\t%s\t%i\t%s\n", i, ether_ntoa(&sa[i].mac), sa[i].product, sa[i].name, inet_ntoa(sa[i].nc.ip), sa[i].ports, sa[i].firmware); printf("\nfound %i switch(es)\n", nb); }