check-* is moved to emulator-supplements. So it is useless now.
Change-Id: I52a0fbe884a37d1fd570dff3febd029e3afad869
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
#include "emulator.h"
#include "emul_state.h"
#include "emulator_options.h"
-#include "util/check_gl.h"
#include "util/error_handler.h"
#include "util/osutil.h"
#include "util/sdb.h"
#sdb
obj-y += sdb.o
-# check gl
-obj-y += check_gl_core.o
-obj-$(CONFIG_LINUX) += check_gl_glx.o
-obj-$(CONFIG_WIN32) += check_gl_wgl.o
-obj-$(CONFIG_DARWIN) += check_gl_cgl.o
-
# hotplug
obj-y += device_hotplug.o
+++ /dev/null
-/*
- * check the availability of a host webcam.
- *
- * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Jinhyung Jo <jinhyung.jo@samsung.com>
- * Sangho Park <sangho1206.park@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include <stdio.h>
-
-#ifdef _WIN32
-/* Windows implement */
-#include <windows.h>
-#define CINTERFACE
-#define COBJMACROS
-#include "ocidl.h"
-#include "errors.h" /* for VFW_E_XXXX */
-#include "mmsystem.h" /* for MAKEFOURCC macro */
-#include "hw/pci/maru_camera_win32.h"
-
-/*
- * COM Interface implementations
- *
- */
-
-#define SAFE_RELEASE(x) \
- do { \
- if (x) { \
- (x)->lpVtbl->Release(x); \
- x = NULL; \
- } \
- } while (0)
-
-static int check_cam(void)
-{
- int ret = 0;
- char *device_name = NULL;
- HRESULT hr = E_FAIL;
- ICreateDevEnum *pCreateDevEnum = NULL;
- IGraphBuilder *pGB = NULL;
- ICaptureGraphBuilder2 *pCGB = NULL;
- IEnumMoniker *pEnumMK = NULL;
- IMoniker *pMoniKer = NULL;
-
- hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
- if (FAILED(hr)) {
- fprintf(stdout, "[Webcam] failed to CoInitailizeEx\n");
- return ret;
- }
-
- hr = CoCreateInstance(&CLSID_FilterGraph, NULL,
- CLSCTX_INPROC,
- &IID_IGraphBuilder,
- (void **)&pGB);
- if (FAILED(hr)) {
- fprintf(stdout, "[Webcam] Failed to create GraphBuilder, 0x%x\n", hr);
- CoUninitialize();
- return ret;
- }
-
- hr = CoCreateInstance(&CLSID_CaptureGraphBuilder2, NULL,
- CLSCTX_INPROC,
- &IID_ICaptureGraphBuilder2,
- (void **)&pCGB);
- if (FAILED(hr)) {
- fprintf(stdout,
- "[Webcam] Failed to create CaptureGraphBuilder2, 0x%x\n", hr);
- SAFE_RELEASE(pGB);
- CoUninitialize();
- return ret;
- }
-
- hr = pCGB->lpVtbl->SetFiltergraph(pCGB, pGB);
- if (FAILED(hr)) {
- fprintf(stdout, "[Webcam] Failed to SetFiltergraph, 0x%x\n", hr);
- SAFE_RELEASE(pCGB);
- SAFE_RELEASE(pGB);
- CoUninitialize();
- return ret;
- }
-
- hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL,
- CLSCTX_INPROC,
- &IID_ICreateDevEnum,
- (void **)&pCreateDevEnum);
- if (FAILED(hr)) {
- fprintf(stdout,
- "[Webcam] failed to create instance of CLSID_SystemDeviceEnum\n");
- SAFE_RELEASE(pCGB);
- SAFE_RELEASE(pGB);
- CoUninitialize();
- return ret;
- }
-
- hr = pCreateDevEnum->lpVtbl->CreateClassEnumerator(pCreateDevEnum,
- &CLSID_VideoInputDeviceCategory, &pEnumMK, 0);
- if (FAILED(hr)) {
- fprintf(stdout, "[Webcam] failed to create class enumerator\n");
- SAFE_RELEASE(pCreateDevEnum);
- SAFE_RELEASE(pCGB);
- SAFE_RELEASE(pGB);
- CoUninitialize();
- return ret;
- }
-
- if (!pEnumMK) {
- fprintf(stdout, "[Webcam] class enumerator is NULL!!\n");
- SAFE_RELEASE(pCreateDevEnum);
- SAFE_RELEASE(pCGB);
- SAFE_RELEASE(pGB);
- CoUninitialize();
- return ret;
- }
-
- pEnumMK->lpVtbl->Reset(pEnumMK);
- hr = pEnumMK->lpVtbl->Next(pEnumMK, 1, &pMoniKer, NULL);
- if (FAILED(hr) || (hr == S_FALSE)) {
- fprintf(stdout, "[Webcam] enum moniker returns a invalid value.\n");
- SAFE_RELEASE(pEnumMK);
- SAFE_RELEASE(pCreateDevEnum);
- SAFE_RELEASE(pCGB);
- SAFE_RELEASE(pGB);
- CoUninitialize();
- return ret;
- }
-
- IPropertyBag *pBag = NULL;
- hr = pMoniKer->lpVtbl->BindToStorage(pMoniKer, 0, 0,
- &IID_IPropertyBag,
- (void **)&pBag);
- if (FAILED(hr)) {
- fprintf(stdout, "[Webcam] failed to bind to storage.\n");
- SAFE_RELEASE(pEnumMK);
- SAFE_RELEASE(pCreateDevEnum);
- SAFE_RELEASE(pCGB);
- SAFE_RELEASE(pGB);
- CoUninitialize();
- return ret;
- } else {
- VARIANT var;
- var.vt = VT_BSTR;
- hr = pBag->lpVtbl->Read(pBag, L"FriendlyName", &var, NULL);
- if (hr == S_OK) {
- ret = 1;
- fprintf(stdout, "[Webcam] Check success\n");
- } else {
- fprintf(stdout, "[Webcam] failed to find to webcam device.\n");
- }
- SysFreeString(var.bstrVal);
- SAFE_RELEASE(pBag);
- }
- SAFE_RELEASE(pMoniKer);
- SAFE_RELEASE(pCGB);
- SAFE_RELEASE(pGB);
- SAFE_RELEASE(pEnumMK);
- SAFE_RELEASE(pCreateDevEnum);
- CoUninitialize();
-
- return ret;
-}
-
-
-#elif __linux
-
-/* Linux implement */
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <linux/videodev2.h>
-
-static int check_cam(void)
-{
- int tmp_fd;
- struct stat st;
- struct v4l2_fmtdesc format;
- struct v4l2_frmsizeenum size;
- struct v4l2_capability cap;
- char dev_name[] = "/dev/video0";
- int ret = 0;
-
- if (stat(dev_name, &st) < 0) {
- fprintf(stdout, "[Webcam] <WARNING> Cannot identify '%s': %d\n",
- dev_name, errno);
- } else {
- if (!S_ISCHR(st.st_mode)) {
- fprintf(stdout, "[Webcam] <WARNING>%s is no character device\n",
- dev_name);
- }
- }
-
- tmp_fd = open(dev_name, O_RDWR | O_NONBLOCK, 0);
- if (tmp_fd < 0) {
- fprintf(stdout, "[Webcam] Camera device open failed: %s\n", dev_name);
- return ret;
- }
- if (ioctl(tmp_fd, VIDIOC_QUERYCAP, &cap) < 0) {
- fprintf(stdout, "[Webcam] Could not qeury video capabilities\n");
- close(tmp_fd);
- return ret;
- }
- if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) ||
- !(cap.capabilities & V4L2_CAP_STREAMING)) {
- fprintf(stdout, "[Webcam] Not supported video driver\n");
- close(tmp_fd);
- return ret;
- }
- fprintf(stdout, "[Webcam] Check success\n");
- close(tmp_fd);
-
- return 1;
-}
-
-#elif __APPLE__
-/* MacOS, Now, not implemented. */
-static int check_cam(void)
-{
- fprintf(stdout, "[Webcam] Not implemented.\n");
- return 1;
-}
-
-#else
-/* Unsupported OS */
-static int check_cam(void)
-{
- fprintf(stdout, "[Webcam] Unsupported OS. Not available.\n");
- return 0;
-}
-#endif /* end of the if statement */
-
-int main(int argc, char** argv)
-{
- return check_cam();
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2011 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * Stanislav Vorobiov <s.vorobiov@samsung.com>
- * Jinhyung Jo <jinhyung.jo@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include "check_gl.h"
-
-int main(int argc, char *argv[])
-{
- return check_gl();
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * Stanislav Vorobiov <s.vorobiov@samsung.com>
- * Jinhyung Jo <jinhyung.jo@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#ifndef __CHECK_GL_H__
-#define __CHECK_GL_H__
-
-struct gl_context;
-
-typedef enum
-{
- gl_info = 0,
- gl_warn = 1,
- gl_error = 2
-} gl_log_level;
-
-typedef enum
-{
- gl_2 = 0,
- gl_3_1 = 1,
- gl_3_2 = 2
-} gl_version;
-
-int check_gl(void);
-
-void check_gl_log(gl_log_level level, const char *format, ...);
-
-int check_gl_init(void);
-
-void check_gl_cleanup(void);
-
-struct gl_context *check_gl_context_create(struct gl_context *share_ctx,
- gl_version version);
-
-int check_gl_make_current(struct gl_context *ctx);
-
-void check_gl_context_destroy(struct gl_context *ctx);
-
-int check_gl_procaddr(void **func, const char *sym, int opt);
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2011 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * Stanislav Vorobiov <s.vorobiov@samsung.com>
- * Jinhyung Jo <jinhyung.jo@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include "check_gl.h"
-#include <OpenGL/OpenGL.h>
-#include <dlfcn.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#define LIBGL_IMAGE_NAME \
-"/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
-
-#ifndef kCGLPFAOpenGLProfile
-# define kCGLPFAOpenGLProfile 99
-# define kCGLOGLPVersion_3_2_Core 0x3200
-# define kCGLOGLPVersion_Legacy 0x1000
-#endif
-
-struct gl_context
-{
- CGLContextObj base;
-};
-
-static void *handle;
-
-int check_gl_init(void)
-{
- handle = dlopen(LIBGL_IMAGE_NAME, RTLD_NOW | RTLD_GLOBAL);
-
- if (!handle) {
- check_gl_log(gl_error, "%s", dlerror());
- return 0;
- }
-
- return 1;
-}
-
-void check_gl_cleanup(void)
-{
-}
-
-struct gl_context *check_gl_context_create(struct gl_context *share_ctx,
- gl_version version)
-{
- static const CGLPixelFormatAttribute pixel_format_legacy_attrs[] =
- {
- kCGLPFAAccelerated,
- kCGLPFAMinimumPolicy,
- kCGLPFAColorSize, 32,
- kCGLPFAAlphaSize, 8,
- kCGLPFADepthSize, 24,
- kCGLPFAStencilSize, 8,
- kCGLPFAPBuffer,
- 0
- };
-
- static const CGLPixelFormatAttribute pixel_format_3_2_core_attrs[] =
- {
- kCGLPFAAccelerated,
- kCGLPFAMinimumPolicy,
- kCGLPFAColorSize, 32,
- kCGLPFAAlphaSize, 8,
- kCGLPFADepthSize, 24,
- kCGLPFAStencilSize, 8,
- kCGLPFAOpenGLProfile, kCGLOGLPVersion_3_2_Core,
- 0
- };
- CGLError error;
- CGLPixelFormatObj pixel_format;
- int n;
- CGLContextObj base = NULL;
- struct gl_context *ctx;
-
- switch (version) {
- case gl_2:
- error = CGLChoosePixelFormat(pixel_format_legacy_attrs,
- &pixel_format,
- &n);
-
- if (error || !pixel_format) {
- break;
- }
-
- error = CGLCreateContext(pixel_format,
- (share_ctx ? share_ctx->base : NULL),
- &base);
-
- CGLDestroyPixelFormat(pixel_format);
-
- if (error) {
- base = NULL;
- }
-
- break;
- case gl_3_1:
- break;
- case gl_3_2:
- error = CGLChoosePixelFormat(pixel_format_3_2_core_attrs,
- &pixel_format,
- &n);
-
- if (error || !pixel_format) {
- break;
- }
-
- error = CGLCreateContext(pixel_format,
- (share_ctx ? share_ctx->base : NULL),
- &base);
-
- CGLDestroyPixelFormat(pixel_format);
-
- if (error) {
- base = NULL;
- }
-
- break;
- default:
- assert(0);
- return NULL;
- }
-
- if (!base) {
- return NULL;
- }
-
- ctx = malloc(sizeof(*ctx));
-
- if (!ctx) {
- CGLDestroyContext(base);
- return NULL;
- }
-
- ctx->base = base;
-
- return ctx;
-}
-
-int check_gl_make_current(struct gl_context *ctx)
-{
- return !CGLSetCurrentContext(ctx ? ctx->base : NULL);
-}
-
-void check_gl_context_destroy(struct gl_context *ctx)
-{
- CGLDestroyContext(ctx->base);
- free(ctx);
-}
-
-int check_gl_procaddr(void **func, const char *sym, int opt)
-{
- *func = dlsym(handle, sym);
-
- if (!*func && !opt) {
- check_gl_log(gl_error, "Unable to find symbol \"%s\"", sym);
- return 0;
- }
-
- return 1;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * Stanislav Vorobiov <s.vorobiov@samsung.com>
- * Jinhyung Jo <jinhyung.jo@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include "check_gl.h"
-#include <GL/gl.h>
-#include <GL/glext.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-
-static const char *log_level_str[gl_error + 1] =
-{
- "INFO",
- "WARN",
- "ERROR"
-};
-
-static const char *gl_version_str[gl_3_2 + 1] =
-{
- "2.1",
- "3.1",
- "3.2"
-};
-
-static const char *gl_3_2_check_funcs[] =
-{
- "glGenTransformFeedbacks",
- "glBindTransformFeedback",
- "glPauseTransformFeedback",
- "glResumeTransformFeedback",
- "glDeleteTransformFeedbacks",
- "glVertexAttribDivisor"
-};
-
-void check_gl_log(gl_log_level level, const char *format, ...)
-{
- va_list args;
-
- fprintf(stderr, "%-5s", log_level_str[level]);
-
- va_start(args, format);
- fprintf(stderr, " - ");
- vfprintf(stderr, format, args);
- va_end(args);
-
- fprintf(stderr, "\n");
-}
-
-static const GLubyte *(GLAPIENTRY *get_string)(GLenum);
-static const GLubyte *(GLAPIENTRY *get_stringi)(GLenum, GLuint);
-static void (GLAPIENTRY *get_integerv)(GLenum, GLint*);
-static void (GLAPIENTRY *dummy)(void);
-
-#if defined(__linux__) && !defined(__APPLE__)
-static struct gl_context *check_gl_version(gl_version version, int *isGallium)
-#else
-static struct gl_context *check_gl_version(gl_version version)
-#endif
-{
- struct gl_context *ctx = NULL;
- int hw = 1;
-
- ctx = check_gl_context_create(NULL, version);
-
- if (!ctx) {
- goto fail;
- }
-
- if (!check_gl_make_current(ctx)) {
- goto fail;
- }
-
- if ((strstr((const char*)get_string(GL_RENDERER), "Software") != NULL)) {
- check_gl_log(gl_warn,
- "Host OpenGL %s - software",
- gl_version_str[version]);
- hw = 0;
- } else if (strncmp((const char*)get_string(GL_VERSION),
- "1.4", strlen("1.4")) == 0) {
- /*
- * Handle LIBGL_ALWAYS_INDIRECT=1 case.
- */
- check_gl_log(gl_warn,
- "Host OpenGL %s - NOT supported",
- gl_version_str[version]);
- hw = 0;
- } else {
- check_gl_log(gl_info,
- "Host OpenGL %s - supported",
- gl_version_str[version]);
- }
-
- check_gl_log(gl_info, "+ GL_VENDOR = %s", (const char*)get_string(GL_VENDOR));
- check_gl_log(gl_info, "+ GL_RENDERER = %s", (const char*)get_string(GL_RENDERER));
- check_gl_log(gl_info, "+ GL_VERSION = %s", (const char*)get_string(GL_VERSION));
-
-#if defined(__linux__) && !defined(__APPLE__)
- if ((strstr((const char *)get_string(GL_RENDERER), "Gallium") != NULL)) {
- *isGallium = 1;
- } else {
- *isGallium = 0;
- }
-#endif
-
- if (!hw) {
- check_gl_context_destroy(ctx);
- ctx = NULL;
- }
-
- check_gl_make_current(NULL);
-
- return ctx;
-
-fail:
- if (ctx) {
- check_gl_context_destroy(ctx);
- }
-
- check_gl_log(gl_info,
- "Host OpenGL %s - NOT supported",
- gl_version_str[version]);
-
- return NULL;
-}
-
-int check_gl(void)
-{
- int res = 1;
- struct gl_context *ctx_2 = NULL;
- struct gl_context *ctx_3_1 = NULL;
- struct gl_context *ctx_3_2 = NULL;
- int have_es3 = 0;
- int have_es3_compatibility = 0;
- int have_es1 = 0;
-#if defined(__linux__) && !defined(__APPLE__)
- int isGallium_2 = 0;
- int isGallium_3_1 = 0;
- int isGallium_3_2 = 0;
-#endif
-
- if (!check_gl_init()) {
- return 1;
- }
-
- if (!check_gl_procaddr((void**)&get_string, "glGetString", 0) ||
- !check_gl_procaddr((void**)&get_stringi, "glGetStringi", 1) ||
- !check_gl_procaddr((void**)&get_integerv, "glGetIntegerv", 0)) {
- goto out;
- }
-
-#if defined(__linux__) && !defined(__APPLE__)
- ctx_2 = check_gl_version(gl_2, &isGallium_2);
- ctx_3_1 = check_gl_version(gl_3_1, &isGallium_3_1);
- ctx_3_2 = check_gl_version(gl_3_2, &isGallium_3_2);
-
- if (isGallium_2 || isGallium_3_1 || isGallium_3_2) {
- check_gl_log(gl_error, "Host has Gallium GL driver!");
- res = 2;
- goto out;
- }
-#else
- ctx_2 = check_gl_version(gl_2);
- ctx_3_1 = check_gl_version(gl_3_1);
- ctx_3_2 = check_gl_version(gl_3_2);
-#endif
-
- if (!ctx_2 && !ctx_3_1 && !ctx_3_2) {
- check_gl_log(gl_info, "Host does not have hardware GL acceleration!");
- goto out;
- }
-
- have_es1 = (ctx_2 != NULL);
-
- if (ctx_3_2) {
- unsigned int i;
- int found_all = 1;
-
- for (i = 0;
- i < sizeof(gl_3_2_check_funcs)/sizeof(gl_3_2_check_funcs[0]);
- ++i) {
- if (!check_gl_procaddr((void**)&dummy, gl_3_2_check_funcs[i], 1) ||
- !dummy) {
- found_all = 0;
- break;
- }
- }
-
- if (found_all) {
- have_es3 = 1;
- }
- }
-
- /*
- * Check if GL_ARB_ES3_compatibility is supported within
- * OpenGL 3.1 context.
- */
-
- if (ctx_3_1 && get_stringi && check_gl_make_current(ctx_3_1)) {
- GLint i, num_extensions = 0;
-
- get_integerv(GL_NUM_EXTENSIONS, &num_extensions);
-
- for (i = 0; i < num_extensions; ++i) {
- const char *tmp;
-
- tmp = (const char*)get_stringi(GL_EXTENSIONS, i);
-
- if (strcmp(tmp, "GL_ARB_ES3_compatibility") == 0) {
- have_es3 = 1;
- have_es3_compatibility = 1;
- break;
- }
- }
-
- check_gl_make_current(NULL);
- }
-
- /*
- * Check if OpenGL 2.1 contexts can be shared with OpenGL 3.x contexts
- */
-
- if (ctx_2 && have_es3) {
- struct gl_context *ctx = NULL;
-
- ctx = check_gl_context_create(((ctx_3_1 && have_es3_compatibility) ? ctx_3_1
- : ctx_3_2),
- gl_2);
-
- if (ctx) {
- if (check_gl_make_current(ctx)) {
- check_gl_make_current(NULL);
- } else {
- have_es1 = 0;
- }
- check_gl_context_destroy(ctx);
- } else {
- have_es1 = 0;
- }
- }
-
- if (have_es1) {
- check_gl_log(gl_info, "Guest OpenGL ES v1_CM - supported");
- } else {
- check_gl_log(gl_warn, "Guest OpenGL ES v1_CM - NOT supported");
- }
- check_gl_log(gl_info, "Guest OpenGL ES 2.0 - supported");
- if (have_es3) {
- check_gl_log(gl_info, "Guest OpenGL ES 3.0 - supported");
- } else {
- check_gl_log(gl_warn, "Guest OpenGL ES 3.0 - NOT supported");
- }
-
- check_gl_log(gl_info, "Host has hardware GL acceleration!");
-
- res = 0;
-
-out:
- if (ctx_2) {
- check_gl_context_destroy(ctx_2);
- }
-
- if (ctx_3_1) {
- check_gl_context_destroy(ctx_3_1);
- }
-
- if (ctx_3_2) {
- check_gl_context_destroy(ctx_3_2);
- }
-
- check_gl_cleanup();
-
- return res;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * Stanislav Vorobiov <s.vorobiov@samsung.com>
- * Jinhyung Jo <jinhyung.jo@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include "check_gl.h"
-#include <GL/glx.h>
-#include <stdlib.h>
-#include <dlfcn.h>
-#include <assert.h>
-
-#ifndef GLX_VERSION_1_4
-#error GL/glx.h must be equal to or greater than GLX 1.4
-#endif
-
-#define GLX_GET_PROC(func, sym) \
- do { \
- *(void**)(&func) = (void*)get_proc_address((const GLubyte*)#sym); \
- if (!func) { \
- check_gl_log(gl_error, "%s", dlerror()); \
- return 0; \
- } \
- } while (0)
-
-struct gl_context
-{
- GLXContext base;
- GLXPbuffer sfc;
-};
-
-typedef void (*PFNGLXDESTROYCONTEXTPROC)(Display *dpy, GLXContext ctx);
-
-static void *handle;
-static Display *x_dpy;
-static GLXFBConfig x_config;
-static PFNGLXGETPROCADDRESSPROC get_proc_address;
-static PFNGLXCHOOSEFBCONFIGPROC choose_fb_config;
-static PFNGLXCREATEPBUFFERPROC create_pbuffer;
-static PFNGLXDESTROYPBUFFERPROC destroy_pbuffer;
-static PFNGLXCREATENEWCONTEXTPROC create_context;
-static PFNGLXDESTROYCONTEXTPROC destroy_context;
-static PFNGLXMAKECONTEXTCURRENTPROC make_current;
-
-/* GLX_ARB_create_context */
-static PFNGLXCREATECONTEXTATTRIBSARBPROC create_context_attribs;
-
-static int check_gl_error_handler(Display *dpy, XErrorEvent *e)
-{
- return 0;
-}
-
-int check_gl_init(void)
-{
- static const int config_attribs[] =
- {
- GLX_DOUBLEBUFFER, True,
- GLX_RED_SIZE, 8,
- GLX_GREEN_SIZE, 8,
- GLX_BLUE_SIZE, 8,
- GLX_ALPHA_SIZE, 8,
- GLX_BUFFER_SIZE, 32,
- GLX_DEPTH_SIZE, 24,
- GLX_STENCIL_SIZE, 8,
- GLX_RENDER_TYPE, GLX_RGBA_BIT,
- GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
- None
- };
- int n = 0;
- GLXFBConfig *configs;
-
- x_dpy = XOpenDisplay(NULL);
-
- if (!x_dpy) {
- check_gl_log(gl_error, "Unable to open X display");
- return 0;
- }
-
- XSetErrorHandler(check_gl_error_handler);
-
- handle = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL);
-
- if (!handle) {
- check_gl_log(gl_error, "%s", dlerror());
- goto fail;
- }
-
- get_proc_address = dlsym(handle, "glXGetProcAddress");
-
- if (!get_proc_address) {
- get_proc_address = dlsym(handle, "glXGetProcAddressARB");
- }
-
- if (!get_proc_address) {
- check_gl_log(gl_error, "%s", dlerror());
- goto fail;
- }
-
- GLX_GET_PROC(choose_fb_config, glXChooseFBConfig);
- GLX_GET_PROC(create_pbuffer, glXCreatePbuffer);
- GLX_GET_PROC(destroy_pbuffer, glXDestroyPbuffer);
- GLX_GET_PROC(create_context, glXCreateNewContext);
- GLX_GET_PROC(destroy_context, glXDestroyContext);
- GLX_GET_PROC(make_current, glXMakeContextCurrent);
- GLX_GET_PROC(create_context_attribs, glXCreateContextAttribsARB);
-
- configs = choose_fb_config(x_dpy,
- DefaultScreen(x_dpy),
- config_attribs,
- &n);
-
- if (!configs || (n <= 0)) {
- check_gl_log(gl_error, "Unable to find suitable FB config");
- goto fail;
- }
-
- x_config = configs[0];
-
- XFree(configs);
-
- return 1;
-
-fail:
- XCloseDisplay(x_dpy);
-
- return 0;
-}
-
-void check_gl_cleanup(void)
-{
- XCloseDisplay(x_dpy);
-}
-
-struct gl_context *check_gl_context_create(struct gl_context *share_ctx,
- gl_version version)
-{
- static const int ctx_attribs_3_1[] =
- {
- GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
- GLX_CONTEXT_MINOR_VERSION_ARB, 1,
- GLX_RENDER_TYPE, GLX_RGBA_TYPE,
- GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
- None
- };
- static const int ctx_attribs_3_2[] =
- {
- GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
- GLX_CONTEXT_MINOR_VERSION_ARB, 2,
- GLX_RENDER_TYPE, GLX_RGBA_TYPE,
- GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
- None
- };
- static const int surface_attribs[] =
- {
- GLX_PBUFFER_WIDTH, 1,
- GLX_PBUFFER_HEIGHT, 1,
- GLX_LARGEST_PBUFFER, False,
- None
- };
- GLXContext base;
- GLXPbuffer sfc;
- struct gl_context *ctx;
-
- switch (version) {
- case gl_2:
- base = create_context(x_dpy,
- x_config,
- GLX_RGBA_TYPE,
- (share_ctx ? share_ctx->base : NULL),
- True);
- break;
- case gl_3_1:
- base = create_context_attribs(x_dpy,
- x_config,
- (share_ctx ? share_ctx->base : NULL),
- True,
- ctx_attribs_3_1);
- break;
- case gl_3_2:
- base = create_context_attribs(x_dpy,
- x_config,
- (share_ctx ? share_ctx->base : NULL),
- True,
- ctx_attribs_3_2);
- break;
- default:
- assert(0);
- return NULL;
- }
-
- if (!base) {
- return NULL;
- }
-
- sfc = create_pbuffer(x_dpy,
- x_config,
- surface_attribs);
-
- if (!sfc) {
- destroy_context(x_dpy, base);
- return NULL;
- }
-
- ctx = malloc(sizeof(*ctx));
-
- if (!ctx) {
- destroy_pbuffer(x_dpy, sfc);
- destroy_context(x_dpy, base);
- return NULL;
- }
-
- ctx->base = base;
- ctx->sfc = sfc;
-
- return ctx;
-}
-
-int check_gl_make_current(struct gl_context *ctx)
-{
- return make_current(x_dpy,
- (ctx ? ctx->sfc : None),
- (ctx ? ctx->sfc : None),
- (ctx ? ctx->base : NULL));
-}
-
-void check_gl_context_destroy(struct gl_context *ctx)
-{
- destroy_pbuffer(x_dpy, ctx->sfc);
- destroy_context(x_dpy, ctx->base);
- free(ctx);
-}
-
-int check_gl_procaddr(void **func, const char *sym, int opt)
-{
- *func = (void*)get_proc_address((const GLubyte*)sym);
-
- if (!*func) {
- *func = dlsym(handle, sym);
- }
-
- if (!*func && !opt) {
- check_gl_log(gl_error, "Unable to find symbol \"%s\"", sym);
- return 0;
- }
-
- return 1;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * Stanislav Vorobiov <s.vorobiov@samsung.com>
- * Jinhyung Jo <jinhyung.jo@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include "check_gl.h"
-#include <windows.h>
-#include <wingdi.h>
-#include <GL/gl.h>
-#include <GL/wglext.h>
-#include <assert.h>
-#include <stdlib.h>
-
-#define WGL_GET_PROC(func, sym) \
- do { \
- *(void**)(&func) = (void*)GetProcAddress(handle, #sym); \
- if (!func) { \
- check_gl_log(gl_error, "Unable to load %s symbol", #sym); \
- goto fail; \
- } \
- } while (0)
-
-#define WGL_GET_EXT_PROC(func, ext, sym) \
- do { \
- if ((strstr(ext_str, #ext " ") == NULL)) { \
- check_gl_log(gl_error, "Extension %s not supported", #ext); \
- goto fail; \
- } \
- *(void**)(&func) = (void*)get_proc_address((LPCSTR)#sym); \
- if (!func) { \
- check_gl_log(gl_error, "Unable to load %s symbol", #sym); \
- goto fail; \
- } \
- } while (0)
-
-struct gl_context
-{
- HGLRC base;
- HPBUFFERARB sfc;
- HDC sfc_dc;
-};
-
-typedef HGLRC (WINAPI *PFNWGLCREATECONTEXTPROC)(HDC hdl);
-typedef BOOL (WINAPI *PFNWGLDELETECONTEXTPROC)(HGLRC hdl);
-typedef PROC (WINAPI *PFNWGLGETPROCADDRESSPROC)(LPCSTR sym);
-typedef BOOL (WINAPI *PFNWGLMAKECURRENTPROC)(HDC dev_ctx, HGLRC rend_ctx);
-typedef BOOL (WINAPI *PFNWGLSHARELISTSPROC)(HGLRC ctx1, HGLRC ctx2);
-
-static HINSTANCE handle = NULL;
-static HWND init_win = NULL;
-static HDC init_dc = NULL;
-static HGLRC init_ctx = NULL;
-static HWND win = NULL;
-static HDC dc = NULL;
-static int config_id = 0;
-static struct gl_context *current = NULL;
-static PFNWGLCREATECONTEXTPROC create_context;
-static PFNWGLDELETECONTEXTPROC delete_context;
-static PFNWGLGETPROCADDRESSPROC get_proc_address;
-static PFNWGLMAKECURRENTPROC make_current;
-static PFNWGLSHARELISTSPROC share_lists;
-
-/* WGL extensions */
-static PFNWGLGETEXTENSIONSSTRINGEXTPROC get_extensions_string_ext;
-static PFNWGLGETEXTENSIONSSTRINGARBPROC get_extensions_string_arb;
-static PFNWGLCHOOSEPIXELFORMATARBPROC choose_pixel_format;
-static PFNWGLCREATEPBUFFERARBPROC create_pbuffer;
-static PFNWGLGETPBUFFERDCARBPROC get_pbuffer_dc;
-static PFNWGLRELEASEPBUFFERDCARBPROC release_pbuffer_dc;
-static PFNWGLDESTROYPBUFFERARBPROC destroy_pbuffer;
-
-/* WGL_ARB_create_context */
-static PFNWGLCREATECONTEXTATTRIBSARBPROC create_context_attribs;
-
-int check_gl_init(void)
-{
- WNDCLASSEXA win_class;
- PIXELFORMATDESCRIPTOR init_pixfmt =
- {
- .nSize = sizeof(PIXELFORMATDESCRIPTOR),
- .nVersion = 1,
- .dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
- .iPixelType = PFD_TYPE_RGBA,
- .cColorBits = 32,
- .cDepthBits = 24,
- .cStencilBits = 8,
- .iLayerType = PFD_MAIN_PLANE,
- };
- int init_config_id = 0;
- const char *ext_str = NULL;
- const int config_attribs[] =
- {
- WGL_SUPPORT_OPENGL_ARB, TRUE,
- WGL_DOUBLE_BUFFER_ARB, TRUE,
- WGL_DRAW_TO_PBUFFER_ARB, TRUE,
- WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
- WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
- WGL_RED_BITS_ARB, 8,
- WGL_GREEN_BITS_ARB, 8,
- WGL_BLUE_BITS_ARB, 8,
- WGL_ALPHA_BITS_ARB, 8,
- WGL_COLOR_BITS_ARB, 32,
- WGL_DEPTH_BITS_ARB, 24,
- WGL_STENCIL_BITS_ARB, 8,
- 0,
- };
- UINT n = 0;
- PIXELFORMATDESCRIPTOR pixfmt;
-
- win_class.cbSize = sizeof(WNDCLASSEXA);
- win_class.style = 0;
- win_class.lpfnWndProc = &DefWindowProcA;
- win_class.cbClsExtra = 0;
- win_class.cbWndExtra = 0;
- win_class.hInstance = NULL;
- win_class.hIcon = NULL;
- win_class.hCursor = NULL;
- win_class.hbrBackground = NULL;
- win_class.lpszMenuName = NULL;
- win_class.lpszClassName = "CheckGLWinClass";
- win_class.hIconSm = NULL;
-
- if (!RegisterClassExA(&win_class)) {
- check_gl_log(gl_error, "Unable to register window class");
- return 0;
- }
-
- handle = LoadLibraryA("opengl32");
-
- if (!handle) {
- check_gl_log(gl_error, "Unable to load opengl32.dll");
- goto fail;
- }
-
- WGL_GET_PROC(create_context, wglCreateContext);
- WGL_GET_PROC(delete_context, wglDeleteContext);
- WGL_GET_PROC(get_proc_address, wglGetProcAddress);
- WGL_GET_PROC(make_current, wglMakeCurrent);
- WGL_GET_PROC(share_lists, wglShareLists);
-
- init_win = CreateWindow("CheckGLWinClass", "CheckGLWin",
- WS_DISABLED | WS_POPUP,
- 0, 0, 1, 1, NULL, NULL, 0, 0);
-
- if (!init_win) {
- check_gl_log(gl_error, "Unable to create window");
- goto fail;
- }
-
- init_dc = GetDC(init_win);
-
- if (!init_dc) {
- check_gl_log(gl_error, "Unable to get window DC");
- goto fail;
- }
-
- init_config_id = ChoosePixelFormat(init_dc, &init_pixfmt);
-
- if (!init_config_id) {
- check_gl_log(gl_error, "ChoosePixelFormat failed");
- goto fail;
- }
-
- if (!SetPixelFormat(init_dc, init_config_id, &init_pixfmt)) {
- check_gl_log(gl_error, "SetPixelFormat failed");
- goto fail;
- }
-
- init_ctx = create_context(init_dc);
- if (!init_ctx) {
- check_gl_log(gl_error, "wglCreateContext failed");
- goto fail;
- }
-
- if (!make_current(init_dc, init_ctx)) {
- check_gl_log(gl_error, "wglMakeCurrent failed");
- goto fail;
- }
-
- /*
- * WGL extensions couldn't be queried by glGetString(), we need to use
- * wglGetExtensionsStringARB or wglGetExtensionsStringEXT for this, which
- * themselves are extensions
- */
- get_extensions_string_arb = (PFNWGLGETEXTENSIONSSTRINGARBPROC)
- get_proc_address((LPCSTR)"wglGetExtensionsStringARB");
- get_extensions_string_ext = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)
- get_proc_address((LPCSTR)"wglGetExtensionsStringEXT");
-
- if (get_extensions_string_arb) {
- ext_str = get_extensions_string_arb(init_dc);
- } else if (get_extensions_string_ext) {
- ext_str = get_extensions_string_ext();
- }
-
- if (!ext_str) {
- check_gl_log(gl_error, "Unable to obtain WGL extension string");
- goto fail;
- }
-
- WGL_GET_EXT_PROC(create_pbuffer, WGL_ARB_pbuffer, wglCreatePbufferARB);
- WGL_GET_EXT_PROC(get_pbuffer_dc, WGL_ARB_pbuffer, wglGetPbufferDCARB);
- WGL_GET_EXT_PROC(release_pbuffer_dc, WGL_ARB_pbuffer, wglReleasePbufferDCARB);
- WGL_GET_EXT_PROC(destroy_pbuffer, WGL_ARB_pbuffer, wglDestroyPbufferARB);
- WGL_GET_EXT_PROC(choose_pixel_format, WGL_ARB_pixel_format, wglChoosePixelFormatARB);
- WGL_GET_EXT_PROC(create_context_attribs, WGL_ARB_create_context, wglCreateContextAttribsARB);
-
- make_current(NULL, NULL);
-
- win = CreateWindow("CheckGLWinClass", "CheckGLWin2",
- WS_DISABLED | WS_POPUP,
- 0, 0, 1, 1, NULL, NULL, 0, 0);
-
- if (!win) {
- check_gl_log(gl_error, "Unable to create window");
- goto fail;
- }
-
- dc = GetDC(win);
-
- if (!dc) {
- check_gl_log(gl_error, "Unable to get window DC");
- goto fail;
- }
-
- if (!choose_pixel_format(dc,
- config_attribs,
- NULL,
- 1,
- &config_id,
- &n) || (n == 0)) {
- check_gl_log(gl_error, "wglChoosePixelFormat failed");
- goto fail;
- }
-
- if (!DescribePixelFormat(dc,
- config_id,
- sizeof(PIXELFORMATDESCRIPTOR),
- &pixfmt)) {
- check_gl_log(gl_error, "DescribePixelFormat failed");
- goto fail;
- }
-
- if (!SetPixelFormat(dc,
- config_id,
- &pixfmt)) {
- check_gl_log(gl_error, "SetPixelFormat failed");
- goto fail;
- }
-
- return 1;
-
-fail:
- if (dc) {
- ReleaseDC(win, dc);
- }
- if (win) {
- DestroyWindow(win);
- }
- if (init_ctx) {
- make_current(NULL, NULL);
- delete_context(init_ctx);
- }
- if (init_dc) {
- ReleaseDC(init_win, init_dc);
- }
- if (init_win) {
- DestroyWindow(init_win);
- }
- if (handle) {
- FreeLibrary(handle);
- }
-
- UnregisterClassA((LPCTSTR)"CheckGLWinClass", NULL);
-
- return 0;
-}
-
-void check_gl_cleanup(void)
-{
- ReleaseDC(win, dc);
- DestroyWindow(win);
- delete_context(init_ctx);
- ReleaseDC(init_win, init_dc);
- DestroyWindow(init_win);
-
- UnregisterClassA((LPCTSTR)"CheckGLWinClass", NULL);
-}
-
-struct gl_context *check_gl_context_create(struct gl_context *share_ctx,
- gl_version version)
-{
- static const int ctx_attribs_3_1[] =
- {
- WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
- WGL_CONTEXT_MINOR_VERSION_ARB, 1,
- WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
- 0
- };
- static const int ctx_attribs_3_2[] =
- {
- WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
- WGL_CONTEXT_MINOR_VERSION_ARB, 2,
- WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
- 0
- };
- static const int surface_attribs[] =
- {
- WGL_PBUFFER_LARGEST_ARB, FALSE,
- WGL_TEXTURE_TARGET_ARB, WGL_NO_TEXTURE_ARB,
- WGL_TEXTURE_FORMAT_ARB, WGL_NO_TEXTURE_ARB,
- 0
- };
- HGLRC base;
- HPBUFFERARB sfc;
- HDC sfc_dc;
- struct gl_context *ctx;
-
- switch (version) {
- case gl_2:
- base = create_context(dc);
- if (share_ctx && !share_lists(share_ctx->base, base)) {
- delete_context(base);
- base = NULL;
- }
- break;
- case gl_3_1:
- base = create_context_attribs(dc,
- (share_ctx ? share_ctx->base : NULL),
- ctx_attribs_3_1);
- break;
- case gl_3_2:
- base = create_context_attribs(dc,
- (share_ctx ? share_ctx->base : NULL),
- ctx_attribs_3_2);
- break;
- default:
- assert(0);
- return NULL;
- }
-
- if (!base) {
- return NULL;
- }
-
- sfc = create_pbuffer(dc,
- config_id, 1, 1,
- surface_attribs);
-
- if (!sfc) {
- delete_context(base);
- return NULL;
- }
-
- sfc_dc = get_pbuffer_dc(sfc);
-
- if (!sfc_dc) {
- destroy_pbuffer(sfc);
- delete_context(base);
- return NULL;
- }
-
- ctx = malloc(sizeof(*ctx));
-
- if (!ctx) {
- release_pbuffer_dc(sfc, sfc_dc);
- destroy_pbuffer(sfc);
- delete_context(base);
- return NULL;
- }
-
- ctx->base = base;
- ctx->sfc = sfc;
- ctx->sfc_dc = sfc_dc;
-
- return ctx;
-}
-
-int check_gl_make_current(struct gl_context *ctx)
-{
- current = ctx;
- return make_current((ctx ? ctx->sfc_dc : NULL),
- (ctx ? ctx->base : NULL));
-}
-
-void check_gl_context_destroy(struct gl_context *ctx)
-{
- release_pbuffer_dc(ctx->sfc, ctx->sfc_dc);
- destroy_pbuffer(ctx->sfc);
- delete_context(ctx->base);
- free(ctx);
-}
-
-int check_gl_procaddr(void **func, const char *sym, int opt)
-{
- if (!make_current(init_dc, init_ctx)) {
- return 0;
- }
-
- *func = (void*)get_proc_address((LPCSTR)sym);
-
- if (!*func) {
- *func = GetProcAddress(handle, sym);
- }
-
- make_current((current ? current->sfc_dc : NULL),
- (current ? current->base : NULL));
-
- if (!*func && !opt) {
- check_gl_log(gl_error, "Unable to find symbol \"%s\"", sym);
- return 0;
- }
-
- return 1;
-}
+++ /dev/null
-/*
- * check if hax is available. reference:target-i386/hax-all.c
- *
- * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * SeokYeon Hwang <syeon.hwang@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- * Hyunjun Son
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#ifdef _WIN32
-#include <stdint.h>
-#include <errno.h>
-#include <windows.h>
-#include <winioctl.h>
-#endif
-
-#ifdef __APPLE__
-#include <stdint.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <stdarg.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#endif
-
-
-
-#define HAX_MAX_VCPU 0x10
-
-#define HAX_CAP_STATUS_NOTWORKING 0x0
-#define HAX_CAP_WORKSTATUS_MASK 0x1
-#define HAX_CAP_FAILREASON_VT 0x1
-#define HAX_CAP_FAILREASON_NX 0x2
-
-#define HAX_CAP_MEMQUOTA 0x2
-#define HAX_CAP_UG 0x4
-
-#ifdef __APPLE__
-#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo)
-typedef int hax_fd;
-#endif
-
-#ifdef _WIN32
-#define HAX_DEVICE_TYPE 0x4000
-#define HAX_IOCTL_CAPABILITY CTL_CODE(HAX_DEVICE_TYPE, 0x910, METHOD_BUFFERED, FILE_ANY_ACCESS)
-typedef HANDLE hax_fd;
-#endif
-
-#define RET_SUPPORT_HAX_AND_UG 0
-#define RET_NO_SUPPORT_UG 1
-#define RET_NO_SUPPORT_HAX 2
-
-struct hax_vm {
- hax_fd fd;
- int id;
- struct hax_vcpu_state *vcpus[HAX_MAX_VCPU];
-};
-
-struct hax_state {
- hax_fd fd; /* the global hax device interface */
- uint32_t version;
- struct hax_vm *vm;
- uint64_t mem_quota;
-};
-
-struct hax_capabilityinfo {
- /* bit 0: 1 - working
- * 0 - not working, possibly because NT/NX disabled
- * bit 1: 1 - memory limitation working
- * 0 - no memory limitation
- */
- uint16_t wstatus;
- /* valid when not working
- * bit 0: VT not enabeld
- * bit 1: NX not enabled*/
- uint16_t winfo;
- uint32_t pad;
- uint64_t mem_quota;
-};
-#ifdef _WIN32
-static inline int hax_invalid_fd(hax_fd fd)
-{
- return (fd == INVALID_HANDLE_VALUE);
-}
-#endif
-#ifdef __APPLE__
-static inline int hax_invalid_fd(hax_fd fd)
-{
- return fd <= 0;
-}
-#endif
-
-
-static hax_fd hax_mod_open(void);
-static int hax_open_device(hax_fd *fd);
-static int hax_get_capability(struct hax_state *hax);
-static int hax_capability(struct hax_state *hax, struct hax_capabilityinfo *cap);
-
-static int check_hax(void)
-{
- struct hax_state hax;
- memset(&hax, 0, sizeof(struct hax_state));
-
- hax.fd = hax_mod_open();
-
- int ret_fd = hax_invalid_fd(hax.fd);
- if (ret_fd) {
- fprintf(stderr, "No support HAX!! Invalid fd: %d\n", hax.fd);
- return RET_NO_SUPPORT_HAX;
- }
-
- int ret_cap = hax_get_capability(&hax);
-
- if (ret_cap) {
- fprintf(stderr, "Not capable: %d\n", ret_cap);
- return ((ret_cap == 1) ? RET_NO_SUPPORT_UG : RET_NO_SUPPORT_HAX);
- }
-
- fprintf(stdout, "Support HAX and UG feature\n");
- return RET_SUPPORT_HAX_AND_UG;
-}
-
-#ifdef _WIN32
-static int hax_open_device(hax_fd *fd)
-{
- uint32_t errNum = 0;
- HANDLE hDevice;
-
- if (!fd) {
- fprintf(stderr, "hax_fd is NULL\n");
- return -2;
- }
-
- hDevice = CreateFile("\\\\.\\HAX", GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
-
- if (hDevice == INVALID_HANDLE_VALUE) {
- fprintf(stderr, "Failed to open the HAX device!\n");
- errNum = GetLastError();
- if (errNum == ERROR_FILE_NOT_FOUND)
- return -1;
- return -2;
- }
- *fd = hDevice;
- fprintf(stdout, "device fd:%d\n", *fd);
- return 0;
-}
-
-static hax_fd hax_mod_open(void)
-{
- int ret;
- hax_fd fd;
-
- ret = hax_open_device(&fd);
- if (ret != 0) {
- fprintf(stderr, "Open HAX device failed\n");
- fd = INVALID_HANDLE_VALUE;
- }
-
- return fd;
-}
-#else
-static hax_fd hax_mod_open(void)
-{
- int fd = open("/dev/HAX", O_RDWR);
-
- if (fd == -1) {
- fprintf(stderr, "Failed to open the hax module\n");
- }
-
- return fd;
-}
-#endif
-
-static int hax_get_capability(struct hax_state *hax)
-{
- int ret;
- struct hax_capabilityinfo capinfo, *cap = &capinfo;
-
- ret = hax_capability(hax, cap);
- if (ret) {
- return ret;
- }
-
- if (((cap->wstatus & HAX_CAP_WORKSTATUS_MASK) == HAX_CAP_STATUS_NOTWORKING)) {
- if (cap->winfo & HAX_CAP_FAILREASON_VT)
- fprintf(stderr, "VTX feature is not enabled. which will cause HAX driver not working.\n");
- else if (cap->winfo & HAX_CAP_FAILREASON_NX)
- fprintf(stderr, "NX feature is not enabled, which will cause HAX driver not working.\n");
- return -ENXIO;
- }
-
- if (!(cap->winfo & HAX_CAP_UG)) {
- fprintf(stderr, "UG feature is not supported.\n");
- ret = 1;
- }
-
- if (cap->wstatus & HAX_CAP_MEMQUOTA) {
- if (cap->mem_quota < hax->mem_quota) {
- fprintf(stderr, "The memory needed by this VM exceeds the driver limit.\n");
- return -ENOSPC;
- }
- }
-
- return ret;
-}
-#ifdef _WIN32
-static int hax_capability(struct hax_state *hax, struct hax_capabilityinfo *cap)
-{
- int ret;
- HANDLE hDevice = hax->fd; //handle to hax module
- DWORD dSize = 0;
- DWORD err = 0;
-
- if (hax_invalid_fd(hDevice)) {
- fprintf(stderr, "Invalid fd for hax device!\n");
- return -ENODEV;
- }
-
- ret = DeviceIoControl(hDevice, HAX_IOCTL_CAPABILITY, NULL, 0, cap, sizeof(*cap), &dSize, (LPOVERLAPPED) NULL);
- if (!ret) {
- err = GetLastError();
- if (err == ERROR_INSUFFICIENT_BUFFER || err == ERROR_MORE_DATA)
- fprintf(stderr, "hax capability is too long to hold.\n");
- fprintf(stderr, "Failed to get Hax capability:%d\n", err);
- return -EFAULT;
- }
-
- return 0;
-}
-#endif
-
-#ifdef __APPLE__
-int hax_capability(struct hax_state *hax, struct hax_capabilityinfo *cap)
-{
- int ret;
-
- ret = ioctl(hax->fd, HAX_IOCTL_CAPABILITY, cap);
- if (ret == -1) {
- fprintf(stderr, "Failed to get HAX capability\n");
- return -errno;
- }
-
- return 0;
-}
-#endif
-
-int main(int argc, char* argv[])
-{
- return check_hax();
-}
+++ /dev/null
-/*
- * Check Network status
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * MunKyu Im <munkyu.im@samsung.com>
- * Sangho Park <sangho1206.park@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include "check_net.h"
-
-#include <curl/curl.h>
-#include <string.h>
-
-const char *pac_tempfile = ".autoproxy";
-
-inline size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
-{
- size_t written;
- written = fwrite(ptr, size, nmemb, stream);
- return written;
-}
-
-void download_url(char *url)
-{
- CURL *curl;
- FILE *fp;
- CURLcode res;
-
- curl = curl_easy_init();
- if (curl) {
- fp = fopen(pac_tempfile, "wb");
- if(fp == NULL) {
- fprintf(stderr, "failed to fopen(): %s\n", pac_tempfile);
- return;
- }
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
- /* just in case network does not work */
- curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 3000);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
-
- res = curl_easy_perform(curl);
- if (res != 0) {
- fprintf(stderr, "Fail to download pac file: %s\n", url);
- }
-
- curl_easy_cleanup(curl);
- fclose(fp);
- }
-
- return;
-}
-
-inline void remove_string(char *src, char *dst, const char *toremove)
-{
- int len = strlen(toremove);
- int i, j;
- int max_len = strlen(src);
-
- for(i = len, j = 0; i < max_len; i++)
- {
- dst[j++] = src[i];
- }
-
- dst[j] = '\0';
-}
-
-int main(int argc, char *argv[])
-{
- if (argc != 2) {
- 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");
- return 1;
- }
- if (strcmp(argv[1], ARG_PROXY) == 0) {
- get_host_proxy_os();
- } else if (strcmp(argv[1], ARG_INTERFACE_ALL) == 0) {
- return get_host_interface_all_os();
- } else if (strcmp(argv[1], ARG_BRIDGE) == 0) {
- return get_host_bridge_os();
- } else if (strcmp(argv[1], ARG_HOST_IP) == 0) {
- get_host_ip_os();
- }
- return 0;
-}
+++ /dev/null
-/*
- * Check Network status
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * MunKyu Im <munkyu.im@samsung.com>
- * Sangho Park <sangho1206.park@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#ifndef __CHECK_NET_H__
-#define __CHECK_NET_H__
-
-#include <string.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <glib/gprintf.h>
-
-#define HTTP_PROTOCOL "http="
-#define HTTP_PREFIX "http://"
-#define HTTPS_PROTOCOL "https="
-#define FTP_PROTOCOL "ftp="
-#define SOCKS_PROTOCOL "socks="
-#define DIRECT "DIRECT"
-#define PROXY "PROXY"
-#define MAXPORTLEN 6
-#define DEFAULTBUFLEN 512
-
-#define GNOME_PROXY_MODE 0
-#define GNOME_PROXY_AUTOCONFIG_URL 1
-#define GNOME_PROXY_HTTP_HOST 2
-#define GNOME_PROXY_HTTP_PORT 3
-#define GNOME_PROXY_HTTPS_HOST 4
-#define GNOME_PROXY_HTTPS_PORT 5
-#define GNOME_PROXY_FTP_HOST 6
-#define GNOME_PROXY_FTP_PORT 7
-#define GNOME_PROXY_SOCKS_HOST 8
-#define GNOME_PROXY_SOCKS_PORT 9
-#define GCONFTOOL 0
-#define GSETTINGS 1
-
-#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;
-
-void get_host_proxy_os(void);
-int get_host_interface_all_os(void);
-int 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
-
+++ /dev/null
-/*
- * Check Network status
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * MunKyu Im <munkyu.im@samsung.com>
- * Sangho Park <sangho1206.park@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#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;
-
-static char *cfstring_to_cstring(CFStringRef str) {
- if (str == NULL) {
- return NULL;
- }
-
- CFIndex length = CFStringGetLength(str);
- CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
- char *buffer = (char *)malloc(maxSize);
- if (CFStringGetCString(str, buffer, maxSize, kCFStringEncodingUTF8)) {
- return buffer;
- }
- return NULL;
-}
-
-static int cfnumber_to_int(CFNumberRef num) {
- if (!num) {
- return 0;
- }
-
- int value;
- CFNumberGetValue(num, kCFNumberIntType, &value);
- return value;
-}
-
-
-static int get_auto_proxy(void)
-{
- char type[DEFAULTBUFLEN];
- char proxy[DEFAULTBUFLEN];
- char line[DEFAULTBUFLEN];
- FILE *fp_pacfile;
- char *p = NULL;
-
- CFStringRef pacURL = (CFStringRef)CFDictionaryGetValue(proxySettings,
- kSCPropNetProxiesProxyAutoConfigURLString);
- if (pacURL) {
- char url[DEFAULTBUFLEN] = {};
- CFStringGetCString(pacURL, url, sizeof url, kCFStringEncodingASCII);
- fprintf(stderr, "pac address: %s\n", (char*)url);
- download_url(url);
- }
-
- fp_pacfile = fopen(pac_tempfile, "r");
- if (fp_pacfile != NULL) {
- while (fgets(line, DEFAULTBUFLEN, fp_pacfile) != NULL) {
- if ((strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) {
- fprintf(stderr, "line found %s", line);
- sscanf(line, "%*[^\"]\"%s %s", type, proxy);
- }
- }
-
- if (g_str_has_prefix(type, DIRECT)) {
- fprintf(stdout, "Proxy addresses are not in use. Host OS uses direct connection.");
- fclose(fp_pacfile);
- } else if (g_str_has_prefix(type, PROXY)) {
- p = strtok(proxy, "\";");
- if (p != NULL) {
- fprintf(stdout, "MODE:Auto\n");
- fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", p, p, p, p);
- }
- fclose(fp_pacfile);
- } else {
- fprintf(stderr, "pac file is not wrong! It could be the wrong pac address or pac file format\n");
- fclose(fp_pacfile);
- }
- } else {
- fprintf(stderr, "fail to get pacfile fp\n");
- fprintf(stdout, "MODE:None\n");
- return -1;
- }
-
- remove(pac_tempfile);
- return 0;
-}
-
-static void get_proxy(void)
-{
- char *hostname;
- int port;
- CFNumberRef isEnable;
- CFStringRef proxyHostname;
- CFNumberRef proxyPort;
- CFDictionaryRef proxySettings;
- proxySettings = SCDynamicStoreCopyProxies(NULL);
- char http_proxy[DEFAULTBUFLEN] = {0,};
- char https_proxy[DEFAULTBUFLEN] = {0,};
- char ftp_proxy[DEFAULTBUFLEN] = {0,};
- char socks_proxy[DEFAULTBUFLEN] = {0,};
-
- isEnable = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPEnable);
- if (cfnumber_to_int(isEnable)) {
- // Get proxy hostname
- proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPProxy);
- hostname = cfstring_to_cstring(proxyHostname);
- // Get proxy port
- proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPPort);
- port = cfnumber_to_int(proxyPort);
- // Save hostname & port
- snprintf(http_proxy, DEFAULTBUFLEN, "%s:%d", hostname, port);
-
- free(hostname);
- }
-
- isEnable = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSEnable);
- if (cfnumber_to_int(isEnable)) {
- // Get proxy hostname
- proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSProxy);
- hostname = cfstring_to_cstring(proxyHostname);
- // Get proxy port
- proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesHTTPSPort);
- port = cfnumber_to_int(proxyPort);
- // Save hostname & port
- snprintf(https_proxy, DEFAULTBUFLEN, "%s:%d", hostname, port);
-
- free(hostname);
- }
-
- isEnable = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPEnable);
- if (cfnumber_to_int(isEnable)) {
- // Get proxy hostname
- proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPProxy);
- hostname = cfstring_to_cstring(proxyHostname);
- // Get proxy port
- proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesFTPPort);
- port = cfnumber_to_int(proxyPort);
- // Save hostname & port
- snprintf(ftp_proxy, DEFAULTBUFLEN, "%s:%d", hostname, port);
-
- free(hostname);
- }
-
- isEnable = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSEnable);
- if (cfnumber_to_int(isEnable)) {
- // Get proxy hostname
- proxyHostname = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSProxy);
- hostname = cfstring_to_cstring(proxyHostname);
- // Get proxy port
- proxyPort = CFDictionaryGetValue(proxySettings, kSCPropNetProxiesSOCKSPort);
- port = cfnumber_to_int(proxyPort);
- // Save hostname & port
- snprintf(socks_proxy, DEFAULTBUFLEN, "%s:%d", hostname, port);
-
- free(hostname);
- }
-
- fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", http_proxy, https_proxy, ftp_proxy, socks_proxy);
- CFRelease(proxySettings);
-}
-
-void get_host_proxy_os(void)
-{
- proxySettings = SCDynamicStoreCopyProxies(NULL);
- if (proxySettings) {
- if (get_auto_proxy() < 0) {
- fprintf(stdout, "MODE:Manual\n");
- get_proxy();
- }
- }
-}
-
-int get_host_interface_all_os(void)
-{
- if (access(PATH_IFCONFIG, F_OK) != -1) {
- system("/sbin/ifconfig -a");
- return 0;
- } else {
- fprintf(stderr, "ifconfig does not exist!\n");
- return 1;
- }
-}
-
-int get_host_bridge_os(void)
-{
- if (access(PATH_IFCONFIG, F_OK) != -1) {
- system("/sbin/ifconfig bridge1");
- return 0;
- } else {
- fprintf(stderr, "ifconfig does not exist!\n");
- return 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);
-}
+++ /dev/null
-/*
- * Check Network status
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * MunKyu Im <munkyu.im@samsung.com>
- * Sangho Park <sangho1206.park@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#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] = {
- { "gconftool-2 -g /system/proxy/mode" , "gsettings get org.gnome.system.proxy mode" },
- { "gconftool-2 -g /system/proxy/autoconfig_url", "gsettings get org.gnome.system.proxy autoconfig-url" },
- { "gconftool-2 -g /system/http_proxy/host", "gsettings get org.gnome.system.proxy.http host" },
- { "gconftool-2 -g /system/http_proxy/port", "gsettings get org.gnome.system.proxy.http port"},
- { "gconftool-2 -g /system/proxy/secure_host", "gsettings get org.gnome.system.proxy.https host" },
- { "gconftool-2 -g /system/proxy/secure_port", "gsettings get org.gnome.system.proxy.https port" },
- { "gconftool-2 -g /system/proxy/ftp_host", "gsettings get org.gnome.system.proxy.ftp host" },
- { "gconftool-2 -g /system/proxy/ftp_port", "gsettings get org.gnome.system.proxy.ftp port" },
- { "gconftool-2 -g /system/proxy/socks_host", "gsettings get org.gnome.system.proxy.socks host" },
- { "gconftool-2 -g /system/proxy/socks_port", "gsettings get org.gnome.system.proxy.socks port" },
-};
-
-static void process_string(char *buf)
-{
- char tmp_buf[DEFAULTBUFLEN];
-
- /* remove single quotes of strings gotten by gsettings */
- if (gproxytool == GSETTINGS) {
- remove_string(buf, tmp_buf, "\'");
- memset(buf, 0, DEFAULTBUFLEN);
- strncpy(buf, tmp_buf, strlen(tmp_buf)-1);
- }
-}
-
-static int get_auto_proxy(void)
-{
- char type[DEFAULTBUFLEN];
- char proxy[DEFAULTBUFLEN];
- char line[DEFAULTBUFLEN];
- FILE *fp_pacfile;
- char *p = NULL;
- FILE *output;
- char buf[DEFAULTBUFLEN];
-
- output = popen(gproxycmds[GNOME_PROXY_AUTOCONFIG_URL][gproxytool], "r");
- if (fscanf(output, "%s", buf) > 0) {
- process_string(buf);
- fprintf(stdout, "pac address: %s\n", buf);
- download_url(buf);
- }
-
- pclose(output);
- fp_pacfile = fopen(pac_tempfile, "r");
- if (fp_pacfile != NULL) {
- while (fgets(line, DEFAULTBUFLEN, fp_pacfile) != NULL) {
- if ((strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) {
- fprintf(stderr, "line found %s", line);
- sscanf(line, "%*[^\"]\"%s %s", type, proxy);
- }
- }
-
- if (g_str_has_prefix(type, DIRECT)) {
- fprintf(stdout, "Proxy addresses are not in use. Host OS uses direct connection.");
- fclose(fp_pacfile);
- } else if (g_str_has_prefix(type, PROXY)) {
- fprintf(stderr, "auto proxy is set to proxy mode\n");
- fprintf(stderr, "type: %s, proxy: %s\n", type, proxy);
-
- p = strtok(proxy, "\";");
- if (p != NULL) {
- fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", p, p, p, p);
- }
- fclose(fp_pacfile);
- } else {
- fprintf(stderr, "pac file is not wrong! It could be the wrong pac address or pac file format\n");
- fclose(fp_pacfile);
- }
- } else {
- fprintf(stderr, "fail to get pacfile fp\n");
- return -1;
- }
-
- if (remove(pac_tempfile) < 0) {
- fprintf(stderr, "fail to remove the temporary pacfile\n");
- }
-
- return 0;
-}
-
-static void get_proxy(void)
-{
- char buf[DEFAULTBUFLEN] = {0,};
- char buf_port[MAXPORTLEN] = {0,};
- char buf_proxy[DEFAULTBUFLEN] = {0,};
- char *buf_proxy_bak;
- char http_proxy[DEFAULTBUFLEN] = {0,};
- char https_proxy[DEFAULTBUFLEN] = {0,};
- char ftp_proxy[DEFAULTBUFLEN] = {0,};
- char socks_proxy[DEFAULTBUFLEN] = {0,};
- char *proxy;
- FILE *output;
- int MAXPROXYLEN = DEFAULTBUFLEN + MAXPORTLEN;
-
- output = popen(gproxycmds[GNOME_PROXY_HTTP_HOST][gproxytool], "r");
- if (fscanf(output, "%s", buf) > 0) {
- process_string(buf);
- snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
- }
- pclose(output);
-
- output = popen(gproxycmds[GNOME_PROXY_HTTP_PORT][gproxytool], "r");
- if (fscanf(output, "%s", buf_port) <= 0) {
- //for abnormal case: if can't find the key of http port, get from environment value.
- buf_proxy_bak = getenv("http_proxy");
- fprintf(stderr, "http_proxy from env: %s\n", buf_proxy_bak);
- if (buf_proxy_bak != NULL) {
- proxy = malloc(DEFAULTBUFLEN);
- remove_string(buf_proxy_bak, proxy, HTTP_PREFIX);
- strncpy(http_proxy, proxy, strlen(proxy)-1);
- free(proxy);
- }
- else {
- fprintf(stderr, "http_proxy is not set on env.\n");
- pclose(output);
- return;
- }
-
- }
- else {
- snprintf(http_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf_port);
- memset(buf_proxy, 0, DEFAULTBUFLEN);
- }
- pclose(output);
-
- memset(buf, 0, DEFAULTBUFLEN);
-
- output = popen(gproxycmds[GNOME_PROXY_HTTPS_HOST][gproxytool], "r");
- if (fscanf(output, "%s", buf) > 0) {
- process_string(buf);
- snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
- }
- pclose(output);
-
- output = popen(gproxycmds[GNOME_PROXY_HTTPS_PORT][gproxytool], "r");
- if(fscanf(output, "%s", buf) > 0) {
- snprintf(https_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
- }
- pclose(output);
- memset(buf, 0, DEFAULTBUFLEN);
- memset(buf_proxy, 0, DEFAULTBUFLEN);
-
- output = popen(gproxycmds[GNOME_PROXY_FTP_HOST][gproxytool], "r");
- if (fscanf(output, "%s", buf) > 0) {
- process_string(buf);
- snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
- }
- pclose(output);
-
- output = popen(gproxycmds[GNOME_PROXY_FTP_PORT][gproxytool], "r");
- if (fscanf(output, "%s", buf) > 0) {
- snprintf(ftp_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
- }
- pclose(output);
- memset(buf, 0, DEFAULTBUFLEN);
- memset(buf_proxy, 0, DEFAULTBUFLEN);
-
- output = popen(gproxycmds[GNOME_PROXY_SOCKS_HOST][gproxytool], "r");
- if (fscanf(output, "%s", buf) > 0) {
- process_string(buf);
- snprintf(buf_proxy, DEFAULTBUFLEN, "%s", buf);
- }
- pclose(output);
-
- output = popen(gproxycmds[GNOME_PROXY_SOCKS_PORT][gproxytool], "r");
- if (fscanf(output, "%s", buf) > 0) {
- snprintf(socks_proxy, MAXPROXYLEN, "%s:%s", buf_proxy, buf);
- }
-
- fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", http_proxy, https_proxy, ftp_proxy, socks_proxy);
- pclose(output);
-}
-
-
-void get_host_proxy_os(void)
-{
- char buf[DEFAULTBUFLEN];
- FILE *output;
- int ret;
-
- output = popen(gproxycmds[GNOME_PROXY_MODE][gproxytool], "r");
- ret = fscanf(output, "%s", buf);
- if (ret <= 0) {
- pclose(output);
- fprintf(stderr, "Try to use gsettings to get proxy\n");
- gproxytool = GSETTINGS;
- output = popen(gproxycmds[GNOME_PROXY_MODE][gproxytool], "r");
- ret = fscanf(output, "%s", buf);
- }
- if (ret > 0) {
- process_string(buf);
- //priority : auto > manual > none
- if (strcmp(buf, "auto") == 0) {
- fprintf(stdout, "MODE:Auto\n");
- get_auto_proxy();
- } else if (strcmp(buf, "manual") == 0) {
- fprintf(stdout, "MODE:Manual\n");
- get_proxy();
- } else if (strcmp(buf, "none") == 0) {
- fprintf(stdout, "MODE:None\n");
- }
- }
- pclose(output);
-}
-
-int get_host_interface_all_os(void)
-{
- if (access(PATH_IFCONFIG, F_OK) != -1) {
- system("/sbin/ifconfig -a");
- return 0;
- } else {
- fprintf(stderr, "ifconfig does not exist!\n");
- return 1;
- }
-}
-
-int get_host_bridge_os(void)
-{
- if (access(PATH_IFCONFIG, F_OK) != -1) {
- system("/sbin/ifconfig bridge1");
- return 0;
- } else {
- fprintf(stderr, "ifconfig does not exist!\n");
- return 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);
-}
+++ /dev/null
-/*
- * Check Network status
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact:
- * MunKyu Im <munkyu.im@samsung.com>
- * Sangho Park <sangho1206.park@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-#define _WIN32_WINNT 0x0601
-#include <winsock2.h>
-#include <iphlpapi.h>
-#include "check_net.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";
-
-static int get_auto_proxy(BYTE *url)
-{
- char type[DEFAULTBUFLEN];
- char proxy[DEFAULTBUFLEN];
- char line[DEFAULTBUFLEN];
- FILE *fp_pacfile;
- char *p = NULL;
-
- fprintf(stdout, "MODE:Auto\n");
- fprintf(stdout, "pac address: %s\n", (char *)url);
- download_url((char *)url);
-
- fp_pacfile = fopen(pactempfile, "r");
- if (fp_pacfile != NULL) {
- while (fgets(line, DEFAULTBUFLEN, fp_pacfile) != NULL) {
- if ( (strstr(line, "return") != NULL) && (strstr(line, "if") == NULL)) {
- fprintf(stderr, "line found %s", line);
- sscanf(line, "%*[^\"]\"%s %s", type, proxy);
- }
- }
-
- if (g_str_has_prefix(type, DIRECT)) {
- fprintf(stdout, "Proxy addresses are not in use. Host OS uses direct connection.");
- fclose(fp_pacfile);
- } else if (g_str_has_prefix(type, PROXY)) {
- fprintf(stderr, "auto proxy is set to proxy mode\n");
- fprintf(stderr, "type: %s, proxy: %s\n", type, proxy);
- p = strtok(proxy, "\";");
- if (p != NULL) {
- fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", p, p, p, p);
- }
- fclose(fp_pacfile);
- } else {
- fprintf(stderr, "pac file is not wrong! It could be the wrong pac address or pac file format\n");
- fclose(fp_pacfile);
- }
- } else {
- fprintf(stderr, "fail to get pacfile fp\n");
- return -1;
- }
-
- remove(pactempfile);
-
- return 0;
-}
-
-void get_host_proxy_os(void)
-{
- HKEY hKey;
- int nRet;
- LONG lRet;
- BYTE *proxyenable, *proxyserver;
- char *p;
- BYTE *url = NULL;
- char http_proxy[DEFAULTBUFLEN] = {0,};
- char https_proxy[DEFAULTBUFLEN] = {0,};
- char ftp_proxy[DEFAULTBUFLEN] = {0,};
- char socks_proxy[DEFAULTBUFLEN] = {0,};
-
- DWORD dwLength = 0;
- nRet = RegOpenKeyEx(HKEY_CURRENT_USER,
- "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
- 0, KEY_QUERY_VALUE, &hKey);
- if (nRet != ERROR_SUCCESS) {
- fprintf(stderr, "Failed to open registry from %s\n",
- "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
- return;
- }
- //check auto proxy key exists
- lRet = RegQueryValueEx(hKey, "AutoConfigURL", 0, NULL, NULL, &dwLength);
- if (lRet != ERROR_SUCCESS && dwLength == 0) {
- fprintf(stderr, "Failed to query value from %s\n",
- "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\AutoConfigURL");
- } else {
- //if exists
- url = (BYTE *)malloc(dwLength);
- if (url == NULL) {
- fprintf(stderr, "Failed to allocate a buffer\n");
- } else {
- memset(url, 0x00, dwLength);
- lRet = RegQueryValueEx(hKey, "AutoConfigURL", 0, NULL, url, &dwLength);
- if (lRet == ERROR_SUCCESS && dwLength != 0) {
- get_auto_proxy(url);
- free(url);
- RegCloseKey(hKey);
- return;
- }
- }
- free(url);
- }
- //check manual proxy key exists
- lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, NULL, &dwLength);
- if (lRet != ERROR_SUCCESS && dwLength == 0) {
- fprintf(stderr, "Failed to query value from %s\n",
- "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable");
- RegCloseKey(hKey);
- return;
- }
- proxyenable = (BYTE*)malloc(dwLength);
- if (proxyenable == NULL) {
- fprintf(stderr, "Failed to allocate a buffer\n");
- RegCloseKey(hKey);
- return;
- }
-
- lRet = RegQueryValueEx(hKey, "ProxyEnable", 0, NULL, proxyenable, &dwLength);
- if (lRet != ERROR_SUCCESS) {
- free(proxyenable);
- fprintf(stderr, "Failed to query value from %s\n",
- "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyEnable");
- RegCloseKey(hKey);
- return;
- }
- if (*(char *)proxyenable == 0) {
- fprintf(stdout, "MODE:None\n");
- free(proxyenable);
- RegCloseKey(hKey);
- return;
- }
-
- dwLength = 0;
- lRet = RegQueryValueEx(hKey, "ProxyServer", 0, NULL, NULL, &dwLength);
- if (lRet != ERROR_SUCCESS && dwLength == 0) {
- fprintf(stderr, "Failed to query value from from %s\n",
- "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
- RegCloseKey(hKey);
- return;
- }
-
- proxyserver = (BYTE*)malloc(dwLength);
- if (proxyserver == NULL) {
- fprintf(stderr, "Failed to allocate a buffer\n");
- RegCloseKey(hKey);
- return;
- }
-
- memset(proxyserver, 0x00, dwLength);
- lRet = RegQueryValueEx(hKey, "ProxyServer", 0, NULL, proxyserver, &dwLength);
- if (lRet != ERROR_SUCCESS) {
- free(proxyserver);
- fprintf(stderr, "Failed to query value from from %s\n",
- "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
- RegCloseKey(hKey);
- return;
- }
-
- //fprintf(stdout, "proxy value: %s\n", (char *)proxyserver);
-
- fprintf(stdout, "MODE:Manual\n");
- for (p = strtok((char *)proxyserver, ";"); p; p = strtok(NULL, ";")) {
- if (strstr(p, HTTP_PROTOCOL)) {
- remove_string(p, http_proxy, HTTP_PROTOCOL);
- } else if (strstr(p, HTTPS_PROTOCOL)) {
- remove_string(p, https_proxy, HTTPS_PROTOCOL);
- } else if (strstr(p, FTP_PROTOCOL)) {
- remove_string(p, ftp_proxy, FTP_PROTOCOL);
- } else if (strstr(p, SOCKS_PROTOCOL)) {
- remove_string(p, socks_proxy, SOCKS_PROTOCOL);
- } else {
- fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", p, p, p, p);
- free(p);
- free(proxyserver);
- RegCloseKey(hKey);
- return;
- }
- }
- free(p);
- fprintf(stdout, "http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s", http_proxy, https_proxy, ftp_proxy, socks_proxy);
- free(proxyserver);
- 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 int 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");
- return 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");
- return 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");
- return 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);
- return 1;
- }
- if (pAdapterInfo)
- FREE(pAdapterInfo);
- return 0;
-}
-
-int get_host_interface_all_os(void)
-{
- return get_host_interface(ALL_INTERFACE);
-}
-
-int get_host_bridge_os(void)
-{
- return get_host_interface(BRIDGE_ONLY);
-}
-
-void get_host_ip_os(void)
-{
- fprintf(stderr, "not supported now\n");
-}