net: support getting host ip from check-net
authorMunkyu Im <munkyu.im@samsung.com>
Fri, 8 May 2015 13:27:28 +0000 (22:27 +0900)
committerMunkyu Im <munkyu.im@samsung.com>
Fri, 8 May 2015 13:27:28 +0000 (22:27 +0900)
check-net support new command "--host-ip".
can get host interface and ip macosx and ubuntu.
change bridge name on ubuntu.

Change-Id: I5985e04be02d5837cba56d0576124ec5981f4d0d
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
tizen/src/util/check_net.c
tizen/src/util/check_net.h
tizen/src/util/check_net_darwin.c
tizen/src/util/check_net_linux.c
tizen/src/util/check_net_win32.c

index 0ac369d1ce9915bc2895409fe2008d855e7f8f5a..8a784fbe5e94e8487bfc246b73380d1bfd3eaa4e 100644 (file)
@@ -92,6 +92,7 @@ void main(int argc, char *argv[])
         fprintf(stderr, " Usage: check-net --proxy\n");
         fprintf(stderr, "        check-net --interface-all\n");
         fprintf(stderr, "        check-net --bridge\n");
+        fprintf(stderr, "        check-net --host-ip\n");
         exit(1);
     }
     if (strcmp(argv[1], ARG_PROXY) == 0) {
@@ -100,5 +101,7 @@ void main(int argc, char *argv[])
         get_host_interface_all_os();
     } else if (strcmp(argv[1], ARG_BRIDGE) == 0) {
         get_host_bridge_os();
+    } else if (strcmp(argv[1], ARG_HOST_IP) == 0) {
+        get_host_ip_os();
     }
 }
index dccbb625d8064805eff70ff4c055c4e3e2982b9f..e519408a6eb73719c90559a92eb967505aa39370 100644 (file)
@@ -65,6 +65,7 @@
 #define ARG_PROXY   "--proxy"
 #define ARG_INTERFACE_ALL   "--interface-all"
 #define ARG_BRIDGE   "--bridge"
+#define ARG_HOST_IP   "--host-ip"
 #define PATH_IFCONFIG "/sbin/ifconfig"
 
 extern const char *pac_tempfile;
@@ -76,6 +77,7 @@ void get_host_bridge_os(void);
 void download_url(char *);
 size_t write_data(void *, size_t, size_t, FILE *);
 void remove_string(char *, char *, const char *);
+void get_host_ip_os(void);
 
 #endif
 
index fd8a6b7f81ffd91597a27c3e973bdcb2b87aeb5f..6384b5cee7ef82b62783fc71fda801acbd656302 100644 (file)
  */
 
 #include "check_net.h"
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <ifaddrs.h>
 #include <SystemConfiguration/SystemConfiguration.h>
 
 static CFDictionaryRef proxySettings;
@@ -212,3 +216,23 @@ void get_host_bridge_os(void)
         exit(1);
     }
 }
+
+void get_host_ip_os(void)
+{
+    struct ifaddrs *ifap, *ifa;
+    struct sockaddr_in *sa;
+    char *addr;
+
+    getifaddrs(&ifap);
+    for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+        if (ifa->ifa_addr->sa_family == AF_INET) {
+            sa = (struct sockaddr_in *) ifa->ifa_addr;
+            addr = inet_ntoa(sa->sin_addr);
+            fprintf(stdout, "Interface:%s Address:%s\n", ifa->ifa_name, addr);
+        }
+    }
+
+    freeifaddrs(ifap);
+
+    exit(0);
+}
index 23f42df7922926cb48a6d368341ab2ab71782723..f0d8e41c0311db79d48e5b22e8723eb2a071d272 100644 (file)
 
 #include "check_net.h"
 #include <unistd.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <ifaddrs.h>
 
 static int gproxytool = GSETTINGS;
 static const char* gproxycmds[][2] = {
@@ -249,9 +253,29 @@ void get_host_interface_all_os(void)
 void get_host_bridge_os(void)
 {
     if (access(PATH_IFCONFIG, F_OK) != -1) {
-        system("/sbin/ifconfig br-tizen-vm-1");
+        system("/sbin/ifconfig bridge1");
     } else {
         fprintf(stderr, "ifconfig does not exist!\n");
         exit(1);
     }
 }
+
+void get_host_ip_os(void)
+{
+    struct ifaddrs *ifap, *ifa;
+    struct sockaddr_in *sa;
+    char *addr;
+
+    getifaddrs(&ifap);
+    for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+        if (ifa->ifa_addr->sa_family == AF_INET) {
+            sa = (struct sockaddr_in *) ifa->ifa_addr;
+            addr = inet_ntoa(sa->sin_addr);
+            fprintf(stdout, "Interface:%s Address:%s\n", ifa->ifa_name, addr);
+        }
+    }
+
+    freeifaddrs(ifap);
+
+    exit(0);
+}
index 8b16f962684b9973747fe88adbd000243ccdfa57..965383275b843239a9cd064c1c7e23dd60ebdc75 100644 (file)
@@ -351,3 +351,8 @@ void get_host_bridge_os(void)
 {
     get_host_interface(BRIDGE_ONLY);
 }
+
+void get_host_ip_os(void)
+{
+    fprintf(stderr, "not supported now\n");
+}