check-proxy: Changed to check-net 12/34212/3
authorMunkyu Im <munkyu.im@samsung.com>
Thu, 22 Jan 2015 05:37:34 +0000 (14:37 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 22 Jan 2015 06:16:29 +0000 (22:16 -0800)
Add network interface information.
The below commands are added.
--proxy: lists host proxy information.
--interface-all: lists information of host ethernet adapters.
--bridge: lists information of host bridge.

Change-Id: I0d3992fd22053e00d8c845e22805860aaf36ab6b
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
.gitignore
tizen/src/Makefile
tizen/src/util/check_net.c [moved from tizen/src/util/check_proxy.c with 81% similarity]
tizen/src/util/check_net.h [moved from tizen/src/util/check_proxy.h with 86% similarity]
tizen/src/util/check_net_darwin.c [moved from tizen/src/util/check_proxy_darwin.c with 93% similarity]
tizen/src/util/check_net_linux.c [moved from tizen/src/util/check_proxy_linux.c with 94% similarity]
tizen/src/util/check_net_win32.c [moved from tizen/src/util/check_proxy_win32.c with 58% similarity]

index 3aa9649..4368027 100644 (file)
@@ -129,5 +129,5 @@ check-cam
 check-cam.exe
 check-gl
 check-gl.exe
-check-proxy
-check-proxy.exe
+check-net
+check-net.exe
index 97058f1..675ff44 100644 (file)
@@ -17,7 +17,7 @@ ifneq ($(wildcard ../../config-host.mak),)
 include ../../config-host.mak
 
 TARGET_EXE += util/check-cam$(EXESUF)
-TARGET_EXE += util/check-proxy$(EXESUF)
+TARGET_EXE += util/check-net$(EXESUF)
 ifdef CONFIG_YAGL
 TARGET_EXE += util/check-gl$(EXESUF)
 endif
@@ -35,28 +35,28 @@ qemu_clean:
 qemu_distclean:
        cd ../../ && $(MAKE) distclean
 
-# Building check-proxy
-CHECK_PROXY_OBJS = util/check_proxy.o
-CHECK_PROXY_CFLAGS = -c $(GLIB_CFLAGS) $(CURL_CFLAGS)
-CHECK_PROXY_LDFLAGS =
-CHECK_PROXY_TARGET = util/check-proxy$(EXESUF)
+# Building check-net
+CHECK_NET_OBJS = util/check_net.o
+CHECK_NET_CFLAGS = -c $(GLIB_CFLAGS) $(CURL_CFLAGS)
+CHECK_NET_LDFLAGS =
+CHECK_NET_TARGET = util/check-net$(EXESUF)
 ifdef CONFIG_LINUX
-CHECK_PROXY_OBJS += util/check_proxy_linux.o
-CHECK_PROXY_LDFLAGS += ${CURL_LIBS} `pkg-config --libs glib-2.0`
+CHECK_NET_OBJS += util/check_net_linux.o
+CHECK_NET_LDFLAGS += ${CURL_LIBS} `pkg-config --libs glib-2.0`
 endif
 ifdef CONFIG_WIN32
-CHECK_PROXY_OBJS += util/check_proxy_win32.o
-CHECK_PROXY_LDFLAGS += ${CURL_LIBS} `pkg-config --libs glib-2.0`
+CHECK_NET_OBJS += util/check_net_win32.o
+CHECK_NET_LDFLAGS += -liphlpapi -lws2_32 ${CURL_LIBS} `pkg-config --libs glib-2.0`
 endif
 ifdef CONFIG_DARWIN
-CHECK_PROXY_OBJS += util/check_proxy_darwin.o
-CHECK_PROXY_LDFLAGS += -mmacosx-version-min=10.4 ${CURL_LIBS} -framework CoreFoundation -framework SystemConfiguration `pkg-config --libs glib-2.0`
+CHECK_NET_OBJS += util/check_net_darwin.o
+CHECK_NET_LDFLAGS += -mmacosx-version-min=10.4 ${CURL_LIBS} -framework CoreFoundation -framework SystemConfiguration `pkg-config --libs glib-2.0`
 endif
 
-util/check-proxy$(EXESUF): $(CHECK_PROXY_OBJS)
-       $(CC) $(CHECK_PROXY_OBJS) $(CHECK_PROXY_LDFLAGS) -o $@
-$(CHECK_PROXY_OBJS): %.o: %.c
-       $(CC) $< $(CHECK_PROXY_CFLAGS) -o $@
+util/check-net$(EXESUF): $(CHECK_NET_OBJS)
+       $(CC) $(CHECK_NET_OBJS) $(CHECK_NET_LDFLAGS) -o $@
+$(CHECK_NET_OBJS): %.o: %.c
+       $(CC) $< $(CHECK_NET_CFLAGS) -o $@
 
 # Building check-gl
 CHECK_GL_OBJS = util/check_gl.o util/check_gl_core.o
@@ -134,7 +134,7 @@ build_info:
 
 
 clean: qemu_clean
-       rm -f util/check-hax$(EXESUF) util/check-cam$(EXESUF) util/check-gl$(EXESUF) util/check-proxy$(EXESUF)
+       rm -f util/check-hax$(EXESUF) util/check-cam$(EXESUF) util/check-gl$(EXESUF) util/check-net$(EXESUF)
 distclean: clean qemu_distclean
 
 install: all
@@ -182,10 +182,10 @@ ifdef CONFIG_USE_SHM
 endif
 endif
 
-# check capabilities of OpenGL, Webcam and proxy
+# check capabilities of OpenGL, Webcam and net
        cp -pP util/check-gl$(EXESUF) $(EMUL_DIR)/bin
        cp -pP util/check-cam$(EXESUF) $(EMUL_DIR)/bin
-       cp -pP util/check-proxy$(EXESUF) $(EMUL_DIR)/bin
+       cp -pP util/check-net$(EXESUF) $(EMUL_DIR)/bin
 
 # Enable HW Virtualization on Linux
 ifdef CONFIG_LINUX
@@ -275,8 +275,8 @@ ifdef CONFIG_USE_SHM
 endif
 endif
 
-# check capabilities of OpenGL, Webcam and proxy
-       cp -pP util/check-proxy$(EXESUF) $(DIBS_COMMON_DIR)/bin
+# check capabilities of OpenGL, Webcam and net
+       cp -pP util/check-net$(EXESUF) $(DIBS_COMMON_DIR)/bin
        cp -pP util/check-gl$(EXESUF) $(DIBS_COMMON_DIR)/bin
        cp -pP util/check-cam$(EXESUF) $(DIBS_COMMON_DIR)/bin
 
similarity index 81%
rename from tizen/src/util/check_proxy.c
rename to tizen/src/util/check_net.c
index 5f59c68..0ac369d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Check proxy
+ * Check Network status
  *
  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -27,7 +27,7 @@
  *
  */
 
-#include "check_proxy.h"
+#include "check_net.h"
 
 #include <curl/curl.h>
 #include <string.h>
@@ -88,5 +88,17 @@ inline void remove_string(char *src, char *dst, const char *toremove)
 
 void main(int argc, char *argv[])
 {
-    get_host_proxy_os();
+    if (argc != 2) {
+        fprintf(stderr, " Usage: check-net --proxy\n");
+        fprintf(stderr, "        check-net --interface-all\n");
+        fprintf(stderr, "        check-net --bridge\n");
+        exit(1);
+    }
+    if (strcmp(argv[1], ARG_PROXY) == 0) {
+        get_host_proxy_os();
+    } else if (strcmp(argv[1], ARG_INTERFACE_ALL) == 0) {
+        get_host_interface_all_os();
+    } else if (strcmp(argv[1], ARG_BRIDGE) == 0) {
+        get_host_bridge_os();
+    }
 }
similarity index 86%
rename from tizen/src/util/check_proxy.h
rename to tizen/src/util/check_net.h
index a1e9604..dccbb62 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Check proxy
+ * Check Network status
  *
  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -27,8 +27,8 @@
  *
  */
 
-#ifndef __CHECK_PROXY_H__
-#define __CHECK_PROXY_H__
+#ifndef __CHECK_NET_H__
+#define __CHECK_NET_H__
 
 #include <string.h>
 #include <stddef.h>
 #define GCONFTOOL 0
 #define GSETTINGS 1
 
+#define ARG_PROXY   "--proxy"
+#define ARG_INTERFACE_ALL   "--interface-all"
+#define ARG_BRIDGE   "--bridge"
+#define PATH_IFCONFIG "/sbin/ifconfig"
+
 extern const char *pac_tempfile;
 
 void get_host_proxy_os(void);
+void get_host_interface_all_os(void);
+void get_host_bridge_os(void);
 
 void download_url(char *);
 size_t write_data(void *, size_t, size_t, FILE *);
similarity index 93%
rename from tizen/src/util/check_proxy_darwin.c
rename to tizen/src/util/check_net_darwin.c
index 25ff02b..14f0a58 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Check proxy
+ * Check Network status
  *
  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -27,7 +27,7 @@
  *
  */
 
-#include "check_proxy.h"
+#include "check_net.h"
 #include <SystemConfiguration/SystemConfiguration.h>
 
 static CFDictionaryRef proxySettings;
@@ -193,3 +193,22 @@ void get_host_proxy_os(void)
     }
 }
 
+void get_host_interface_all_os(void)
+{
+    if (access(PATH_IFCONFIG, F_OK) != -1) {
+        system("/sbin/ifconfig -a");
+    } else {
+        fprintf(stderr, "ifconfig does not exist!\n");
+        exit(1);
+    }
+}
+
+void get_host_bridge_os(void)
+{
+    if (access(PATH_IFCONFIG, F_OK) != -1) {
+        system("/sbin/ifconfig br-tizen-vm-1");
+    } else {
+        fprintf(stderr, "ifconfig does not exist!\n");
+        exit(1);
+    }
+}
similarity index 94%
rename from tizen/src/util/check_proxy_linux.c
rename to tizen/src/util/check_net_linux.c
index e36b142..23f42df 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Check proxy
+ * Check Network status
  *
  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -27,7 +27,8 @@
  *
  */
 
-#include "check_proxy.h"
+#include "check_net.h"
+#include <unistd.h>
 
 static int gproxytool = GSETTINGS;
 static const char* gproxycmds[][2] = {
@@ -234,3 +235,23 @@ void get_host_proxy_os(void)
     }
     pclose(output);
 }
+
+void get_host_interface_all_os(void)
+{
+    if (access(PATH_IFCONFIG, F_OK) != -1) {
+        system("/sbin/ifconfig -a");
+    } else {
+        fprintf(stderr, "ifconfig does not exist!\n");
+        exit(1);
+    }
+}
+
+void get_host_bridge_os(void)
+{
+    if (access(PATH_IFCONFIG, F_OK) != -1) {
+        system("/sbin/ifconfig br-tizen-vm-1");
+    } else {
+        fprintf(stderr, "ifconfig does not exist!\n");
+        exit(1);
+    }
+}
similarity index 58%
rename from tizen/src/util/check_proxy_win32.c
rename to tizen/src/util/check_net_win32.c
index 117384f..1ab7efb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Check proxy
+ * Check Network status
  *
  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * - S-Core Co., Ltd
  *
  */
-
-#include "check_proxy.h"
+#define _WIN32_WINNT 0x0601
+#include "check_net.h"
 #include <windows.h>
+#include <winsock2.h>
+#include <iphlpapi.h>
+
+#define ALL_INTERFACE 0
+#define BRIDGE_ONLY 1
+#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
+#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
+#define WORKING_BUFFER_SIZE 15000
+#define MAX_TRIES 3
 
 static const char *pactempfile = ".autoproxy";
 
@@ -204,3 +213,142 @@ void get_host_proxy_os(void)
     RegCloseKey(hKey);
 }
 
+static print_interface(PIP_ADAPTER_INFO pAdapter, PIP_ADAPTER_ADDRESSES pAddresses)
+{
+    int i;
+    IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = NULL;
+    struct sockaddr_in *pAddr;
+
+    fprintf(stdout, "Adapter Desc: %s\n", pAdapter->Description);
+    fprintf(stdout, "Index: %d\n", pAdapter->Index);
+    fprintf(stdout, "ClassID: %s\n", pAdapter->AdapterName);
+    /*
+       typedef enum  {
+       IfOperStatusUp = 1,
+       IfOperStatusDown,
+       IfOperStatusTesting,
+       IfOperStatusUnknown,
+       IfOperStatusDormant,
+       IfOperStatusNotPresent,
+       IfOperStatusLowerLayerDown
+       } IF_OPER_STATUS;
+     */
+    fprintf(stdout, "Operating Status: %d\n", pAddresses->OperStatus);
+    fprintf(stdout, "Ethernet Address: ");
+    for (i = 0; i < pAdapter->AddressLength; i++) {
+        if (i == (pAdapter->AddressLength - 1))
+            fprintf(stdout, "%.2X\n", (int) pAdapter->Address[i]);
+        else
+            fprintf(stdout, "%.2X-", (int) pAdapter->Address[i]);
+    }
+    if (pAdapter->DhcpEnabled) {
+        fprintf(stdout, "Use DHCP Server: Yes\n");
+        //      fprintf(stdout, "DHCP Server Address: %s\n", pAdapter->DhcpServer.IpAddress.String);
+    } else {
+        fprintf(stdout, "Use DHCP Server: No\n");
+        fprintf(stdout, "IP Address: %s\n", pAdapter->IpAddressList.IpAddress.String);
+        fprintf(stdout, "IP Mask: %s\n", pAdapter->IpAddressList.IpMask.String);
+        fprintf(stdout, "Gateway: %s\n", pAdapter->GatewayList.IpAddress.String);
+
+    }
+
+    pDnServer = pAddresses->FirstDnsServerAddress;
+    if (pDnServer) {
+        pAddr = (struct sockaddr_in*)pDnServer->Address.lpSockaddr;
+        fprintf(stdout, "DNS server address: %s\n", inet_ntoa(pAddr->sin_addr));
+    } else {
+        fprintf(stdout, "DNS server address: No\n");
+    }
+    //  fprintf(stdout, "Friendly name: %wS\n", pAddresses->FriendlyName);
+    fprintf(stdout, "\n");
+}
+
+static void get_host_interface(int value)
+{
+    PIP_ADAPTER_ADDRESSES pAddresses = NULL;
+    PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
+    DWORD dwRetAddressVal = 0;
+    ULONG flags = 0;
+
+    PIP_ADAPTER_INFO pAdapterInfo;
+    PIP_ADAPTER_INFO pCurrAdapter = NULL;
+    DWORD dwRetVal = 0;
+    UINT i;
+    ULONG Iterations = 0;
+
+    ULONG outBufLen = 0;
+    outBufLen = WORKING_BUFFER_SIZE;
+
+    do {
+
+        pAddresses = (IP_ADAPTER_ADDRESSES *) MALLOC(outBufLen);
+        if (pAddresses == NULL) {
+            fprintf(stderr, "Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
+            exit(1);
+        }
+
+        dwRetAddressVal = GetAdaptersAddresses(AF_INET, flags, NULL, pAddresses, &outBufLen);
+
+        if (dwRetAddressVal == ERROR_BUFFER_OVERFLOW) {
+            FREE(pAddresses);
+            pAddresses = NULL;
+        } else {
+            break;
+        }
+
+        Iterations++;
+
+    } while ((dwRetAddressVal == ERROR_BUFFER_OVERFLOW) && (Iterations < MAX_TRIES));
+
+
+    ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
+    pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(sizeof (IP_ADAPTER_INFO));
+    if (pAdapterInfo == NULL) {
+        fprintf(stderr, "Error allocating memory needed to call GetAdaptersinfo\n");
+        exit(1);
+    }
+    if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
+        FREE(pAdapterInfo);
+        pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(ulOutBufLen);
+        if (pAdapterInfo == NULL) {
+            fprintf(stderr, "Error allocating memory needed to call GetAdaptersinfo\n");
+            exit(1);
+        }
+    }
+    dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
+    if (dwRetVal == NO_ERROR && dwRetAddressVal == NO_ERROR) {
+        pCurrAdapter = pAdapterInfo;
+        pCurrAddresses = pAddresses;
+        while (pCurrAdapter && pCurrAddresses) {
+            if (pCurrAdapter->Type == MIB_IF_TYPE_ETHERNET) {
+                if (value == ALL_INTERFACE) {
+                    print_interface(pCurrAdapter, pCurrAddresses);
+                } else if (value == BRIDGE_ONLY) {
+                    if (strcmp(pCurrAdapter->Description, "MAC Bridge Miniport") == 0 || strcmp(pCurrAdapter->Description, "Microsoft Network Adapter Multiplexor Driver") == 0) {
+                        print_interface(pCurrAdapter, pCurrAddresses);
+                        break;
+                    }
+                }
+            }
+            pCurrAdapter = pCurrAdapter->Next;
+            pCurrAddresses = pCurrAddresses->Next;
+        }
+    } else {
+        fprintf(stderr, "GetAdaptersInfo failed with error: %d\n", dwRetVal);
+        exit(1);
+    }
+    if (pAdapterInfo)
+        FREE(pAdapterInfo);
+
+    exit(0);
+}
+
+void get_host_interface_all_os(void)
+{
+    get_host_interface(ALL_INTERFACE);
+}
+
+void get_host_bridge_os(void)
+{
+    get_host_interface(BRIDGE_ONLY);
+}