]> git.sur5r.net Git - gsconf/blobdiff - shell.c
A bunch of fixes for various compiler warnings
[gsconf] / shell.c
diff --git a/shell.c b/shell.c
index 284acc0528ff39baf070facf15116127a7ea74d8..8f32679f4eda10aa26c7dd2bdf0fc02aef4d4ce3 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -67,7 +67,6 @@ void printError(int errCode) {
 
 void shell_set(char ** argv, int elem) {
 
-        int n;
         if (strncmp(argv[1], "name", 4) == 0) {
                 if (elem != 3) {
                         printf("set name [name]\n");
@@ -77,10 +76,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: ");
+               printf("\033[91mWarning: As the protocol of the switch wants it that way, all configuration packets are send as broadcasts. Even though Netgear is 'encrypting' the password it, the encryption used, is one step away from plaintext.\033[0m\n");
+                settings.password = copyString((char *)getpass("Password: "));
         }
 }
 
@@ -97,6 +103,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 +215,14 @@ int shell (void) {
                         shell_port(argv, elem);
                 }
                 
+                if (strncmp(argv[0], "sys", 3) == 0) {
+                        shell_sys(argv, elem);
+                }
+                
+                if (strncmp(argv[0], "help", 4) == 0) {
+                        printf("Available commands: \n");
+                        printf("[discover|select|nodev|ip|vlan|port|sys] \n");
+                }