2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <sys/ioctl.h>
25 #include <arpa/inet.h>
26 #include <vconf-keys.h>
27 #include <system_info.h>
33 static gboolean netconfig_is_emulated = FALSE;
35 static gboolean __netconfig_emulator_test_emulation_env(void)
40 DBG("Test emulation environment");
42 ret = system_info_get_platform_string("tizen.org/system/model_name", &model);
43 if (ret != SYSTEM_INFO_ERROR_NONE) {
44 ERR("Failed to get system information(%d)", ret);
48 if (model && strncmp(model, "Emulator", strlen("Emulator")) == 0) {
59 static void __netconfig_emulator_set_ip(void)
61 const char EMUL_IFNAME[] = "eth0";
66 sockfd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
68 ERR("Failed to open socket");
72 memset(&ifr, 0, sizeof(struct ifreq));
73 g_strlcpy((char *)ifr.ifr_name, EMUL_IFNAME, 16);
75 if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0) {
76 ERR("Failed to get IP address");
85 inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr), 30);
87 vconf_set_str(VCONFKEY_NETWORK_IP, ip);
90 static void __netconfig_emulator_set_proxy(void)
92 const char HTTP_PROXY[] = "http_proxy";
95 proxy = netconfig_get_env(HTTP_PROXY);
96 DBG("Get system proxy: %s", proxy);
99 vconf_set_str(VCONFKEY_NETWORK_PROXY, proxy);
104 static void __netconfig_emulator_set_network_state(void)
106 vconf_set_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, 1);
107 vconf_set_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_ETHERNET);
108 vconf_set_int(VCONFKEY_DNET_STATE, VCONFKEY_DNET_NORMAL_CONNECTED);
111 static void __netconfig_emulator_config_emul_env(void)
113 __netconfig_emulator_set_ip();
114 __netconfig_emulator_set_proxy();
115 __netconfig_emulator_set_network_state();
118 gboolean emulator_is_emulated(void)
120 return netconfig_is_emulated;
123 void emulator_test_and_start(void)
125 netconfig_is_emulated = __netconfig_emulator_test_emulation_env();
127 DBG("Emulation environment tested: %s", netconfig_is_emulated ? "It's emulated" : "Not emulated");
129 if (netconfig_is_emulated == TRUE)
130 __netconfig_emulator_config_emul_env();