]> git.sur5r.net Git - openocd/commitdiff
houskeeping
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 17 Dec 2008 13:39:40 +0000 (13:39 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 17 Dec 2008 13:39:40 +0000 (13:39 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@1255 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/ecosboard.c
src/helper/ioutil.c
src/server/telnet_server.c

index d2c11b3561c672bbb5fedaa584ee82faec234e71..019eb0e853c3777a948157684baae91c6679e1d9 100644 (file)
@@ -419,60 +419,6 @@ static int zylinjtag_Jim_Command_reboot(Jim_Interp *interp, int argc,
        return JIM_OK;
 }
 
-static int zylinjtag_Jim_Command_mac(Jim_Interp *interp, int argc,
-               Jim_Obj * const *argv)
-{
-
-       Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
-
-       Jim_AppendString(httpstate.jim_interp, tclOutput, hwaddr, strlen(hwaddr));
-
-       Jim_SetResult(interp, tclOutput);
-
-       return JIM_OK;
-}
-
-static int zylinjtag_Jim_Command_ip(Jim_Interp *interp, int argc,
-               Jim_Obj * const *argv)
-{
-       Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
-
-       struct ifaddrs *ifa = NULL, *ifp = NULL;
-
-       if (getifaddrs(&ifp) < 0)
-       {
-               return JIM_ERR;
-       }
-
-       for (ifa = ifp; ifa; ifa = ifa->ifa_next)
-       {
-               char ip[200];
-               socklen_t salen;
-
-               if (ifa->ifa_addr->sa_family == AF_INET)
-                       salen = sizeof(struct sockaddr_in);
-               else if (ifa->ifa_addr->sa_family == AF_INET6)
-                       salen = sizeof(struct sockaddr_in6);
-               else
-                       continue;
-
-               if (getnameinfo(ifa->ifa_addr, salen, ip, sizeof(ip), NULL, 0,
-                               NI_NUMERICHOST) < 0)
-               {
-                       continue;
-               }
-
-               Jim_AppendString(httpstate.jim_interp, tclOutput, ip, strlen(ip));
-               break;
-
-       }
-
-       freeifaddrs(ifp);
-
-       Jim_SetResult(interp, tclOutput);
-
-       return JIM_OK;
-}
 
 extern Jim_Interp *interp;
 
@@ -506,10 +452,6 @@ static void zylinjtag_startNetwork()
                        zylinjtag_Jim_Command_reboot, NULL, NULL);
        Jim_CreateCommand(httpstate.jim_interp, "threads",
                        zylinjtag_Jim_Command_threads, NULL, NULL);
-       Jim_CreateCommand(httpstate.jim_interp, "mac", zylinjtag_Jim_Command_mac,
-                       NULL, NULL);
-       Jim_CreateCommand(httpstate.jim_interp, "ip", zylinjtag_Jim_Command_ip,
-                       NULL, NULL);
        Jim_CreateCommand(httpstate.jim_interp, "format_jffs2",
                        zylinjtag_Jim_Command_format_jffs2, NULL, NULL);
 
index 101df2d94649f053c4fac7f27a62b96dfa549a88..80e43d4ead5b331ef1fc47ea846b2ec28246657a 100644 (file)
@@ -63,6 +63,8 @@
 #include <string.h>
 
 
+#include <ifaddrs.h>
+
 #include <unistd.h>
 #include <stdio.h>
 
@@ -557,6 +559,120 @@ zylinjtag_Jim_Command_poke(Jim_Interp *interp,
        return JIM_OK;
 }
 
+
+/* not so pretty code to fish out ip number*/
+static int zylinjtag_Jim_Command_ip(Jim_Interp *interp, int argc,
+               Jim_Obj * const *argv)
+{
+       Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
+
+       struct ifaddrs *ifa = NULL, *ifp = NULL;
+
+       if (getifaddrs(&ifp) < 0)
+       {
+               return JIM_ERR;
+       }
+
+       for (ifa = ifp; ifa; ifa = ifa->ifa_next)
+       {
+               char ip[200];
+               socklen_t salen;
+
+               if (ifa->ifa_addr->sa_family == AF_INET)
+                       salen = sizeof(struct sockaddr_in);
+               else if (ifa->ifa_addr->sa_family == AF_INET6)
+                       salen = sizeof(struct sockaddr_in6);
+               else
+                       continue;
+
+               if (getnameinfo(ifa->ifa_addr, salen, ip, sizeof(ip), NULL, 0,
+                               NI_NUMERICHOST) < 0)
+               {
+                       continue;
+               }
+
+               Jim_AppendString(interp, tclOutput, ip, strlen(ip));
+               break;
+
+       }
+
+       freeifaddrs(ifp);
+
+       Jim_SetResult(interp, tclOutput);
+
+       return JIM_OK;
+}
+
+
+/* not so pretty code to fish out eth0 mac address */
+static int zylinjtag_Jim_Command_mac(Jim_Interp *interp, int argc,
+               Jim_Obj * const *argv)
+{
+
+
+       struct ifreq *ifr, *ifend;
+       struct ifreq ifreq;
+       struct ifconf ifc;
+       struct ifreq ifs[5];
+       int SockFD;
+
+       SockFD = socket(AF_INET, SOCK_DGRAM, 0);
+       if (SockFD < 0)
+       {
+               return JIM_ERR;
+       }
+
+       ifc.ifc_len = sizeof(ifs);
+       ifc.ifc_req = ifs;
+       if (ioctl(SockFD, SIOCGIFCONF, &ifc) < 0)
+       {
+               close(SockFD);
+               return JIM_ERR;
+       }
+
+       ifend = ifs + (ifc.ifc_len / sizeof(struct ifreq));
+       for (ifr = ifc.ifc_req; ifr < ifend; ifr++)
+       {
+               //if (ifr->ifr_addr.sa_family == AF_INET)
+               {
+                       if (strcmp("eth0", ifr->ifr_name)!=0)
+                               continue;
+                       strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
+                       if (ioctl(SockFD, SIOCGIFHWADDR, &ifreq) < 0)
+                       {
+                               close(SockFD);
+                               return JIM_ERR;
+                       }
+
+                       close(SockFD);
+
+
+                       Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
+
+                       char buffer[256];
+                       sprintf(buffer, "%02x-%02x-%02x-%02x-%02x-%02x",
+                                       ifreq.ifr_hwaddr.sa_data[0]&0xff,
+                                       ifreq.ifr_hwaddr.sa_data[1]&0xff,
+                                       ifreq.ifr_hwaddr.sa_data[2]&0xff,
+                                       ifreq.ifr_hwaddr.sa_data[3]&0xff,
+                                       ifreq.ifr_hwaddr.sa_data[4]&0xff,
+                                       ifreq.ifr_hwaddr.sa_data[5]&0xff);
+
+                       Jim_AppendString(interp, tclOutput, buffer, strlen(buffer));
+
+                       Jim_SetResult(interp, tclOutput);
+
+                       return JIM_OK;
+               }
+       }
+       close(SockFD);
+
+       return JIM_ERR;
+
+}
+
+
+
 int ioutil_init(struct command_context_s *cmd_ctx)
 {
        register_command(cmd_ctx, NULL, "rm", handle_rm_command, COMMAND_ANY,
@@ -583,6 +699,11 @@ int ioutil_init(struct command_context_s *cmd_ctx)
     Jim_CreateCommand(interp, "poke", zylinjtag_Jim_Command_poke, NULL, NULL);
     Jim_CreateCommand(interp, "ls", zylinjtag_Jim_Command_ls, NULL, NULL);
 
+       Jim_CreateCommand(interp, "mac", zylinjtag_Jim_Command_mac,
+                       NULL, NULL);
+
+       Jim_CreateCommand(interp, "ip", zylinjtag_Jim_Command_ip,
+                       NULL, NULL);
 
     return ERROR_OK;
 }
index dc555214e07c0c6aa9293e917bbe0e5e760dac26..95dfce161563ee73eb1cb42944951df6fcc12c07 100644 (file)
@@ -626,7 +626,7 @@ int telnet_register_commands(command_context_t *command_context)
                                         COMMAND_EXEC, "exit telnet session");
 
        register_command(command_context, NULL, "telnet_port", handle_telnet_port_command,
-                                        COMMAND_CONFIG, "port on which to listen for incoming telnet connections");
+                                        COMMAND_ANY, "port on which to listen for incoming telnet connections");
 
        return ERROR_OK;
 }