]> git.sur5r.net Git - gsconf/blobdiff - shell.c
Fixed vlan bug, gotta rewrite that section soon
[gsconf] / shell.c
diff --git a/shell.c b/shell.c
index 284acc0528ff39baf070facf15116127a7ea74d8..da91eb96aee2873730b9a4893567e1666be89bfa 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -77,10 +77,17 @@ void shell_set(char ** argv, int elem) {
         }
 }
 
+char * copyString(char * data) {
+        char * ret = (char * )malloc(strlen(data) + 1);
+        memcpy(ret, data, strlen(data) + 1);
+        ret[strlen(data)] = 0;
+        return ret;
+}
+
 void password(void) {
         if (settings.password == NULL) {
                printf("\033[91mWarning: As the protocol of the switch wants it that way, all configuration packets are send as broadcasts, meaning everyone on this net can sniff your password!\033[0m\n");
-                settings.password = getpass("Password: ");
+                settings.password = copyString(getpass("Password: "));
         }
 }
 
@@ -97,6 +104,27 @@ int shell (void) {
         struct gs105e_discovered * ddev;
         
         char * dev = "nodev";
+        
+        n = gs105e_discover();
+        printf("Discovered \033[92m%i\033[0m devices\n", n);
+
+        ddev = gs105e_devs;
+
+        printf("ID\tName\t\tMAC\t\tIP\n");
+
+        while (ddev != NULL) {
+                printf("%i\t%s\t\t%X:%X:%X:%X:%X:%X\t%u.%u.%u.%u\n", ddev->id, ddev->name, ddev->mac[0]&0xff, ddev->mac[1]&0xff, ddev->mac[2]&0xff, ddev->mac[3]&0xff, ddev->mac[4]&0xff, ddev->mac[5]&0xff, ddev->ip[0]&0xff, ddev->ip[1]&0xff, ddev->ip[2]&0xff, ddev->ip[3]&0xff);
+                ddev = ddev->next;
+        }
+
+        if (n == 1) {
+                printf("only one switch, selecting 1\n");
+
+                memcpy(settings.mac, gs105e_devs->mac, 6);
+                gs105e_queryAll();
+                dev = gs105e_devs->name;
+        }
+        
         while (1) {
                 printf("\033[96mgs (\033[93m%s\033[96m)# \033[0m", dev);
                 cmd[0] = 0;
@@ -188,6 +216,10 @@ int shell (void) {
                         shell_port(argv, elem);
                 }
                 
+                if (strncmp(argv[0], "sys", 3) == 0) {
+                        shell_sys(argv, elem);
+                }
+