public class TapUtil {
+ private static String BRIDGE_NAME = "bridge1";
public static String getDevconPath(String platformVersion) {
return FilePathResources.getEmulatorBinPath(platformVersion)
+ File.separator + "devcon.exe";
public static String getBridgeIpAddr(String tapName) {
String ipAddr = null;
- if (EmulatorManager.isLinux())
- try {
- InterfaceAddress ifAddr = getInterfaceIpInfo(getBridgeFromDevice(tapName));
- if (ifAddr != null)
- ipAddr = ifAddr.getAddress().getHostAddress();
- } catch (VMWorkerException e) {
- EMLogger.getLogger().warning(
- (new StringBuilder())
- .append("Failed to get bridge ip address. ")
- .append(e.getMessage()).toString());
+ if (EmulatorManager.isLinux()) {
+ InterfaceAddress ifAddr = getInterfaceIpInfo(tapName);
+ if (ifAddr != null) {
+ EMLogger.getLogger().info("get " + tapName + "'s IP");
+ ipAddr = ifAddr.getAddress().getHostAddress();
+ } else {
+ EMLogger.getLogger().info("get bridge's IP");
+ InterfaceAddress ifAddrBridge = getInterfaceIpInfo(BRIDGE_NAME);
+ if (ifAddrBridge != null) {
+ ipAddr = ifAddrBridge.getAddress().getHostAddress();
+ }
}
- else if (EmulatorManager.isWin() && isTapInBridge(tapName)) {
+ } else if (EmulatorManager.isWin() && isTapInBridge(tapName)) {
HKEY key = getInterfaceTcpipKey(getBridgeId());
if (key != null) {
try {
package org.tizen.emulator.manager.ui.dialog;
-import java.net.NetworkInterface;
-import java.net.SocketException;
import java.util.ArrayList;
-import java.util.Enumeration;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.swt.SWT;
import org.tizen.emulator.manager.tool.TapUtil;
import org.tizen.emulator.manager.ui.MainDialog;
import org.tizen.emulator.manager.ui.widgets.ImageLabel;
-import org.tizen.emulator.manager.vms.helper.VMWorkerException;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+import org.tizen.emulator.manager.vms.helper.ProcessResult;
public class TapDeviceDialogForLinux {
- public static ArrayList<String> getInterfaceList() {
- ArrayList<String> result = new ArrayList<String>();
-
- // Get intereface list
- ArrayList<String> ifList = new ArrayList<String>();
- Enumeration<NetworkInterface> interfaces;
- try {
- interfaces = NetworkInterface.getNetworkInterfaces();
- if (interfaces != null) {
- while (interfaces.hasMoreElements()) {
- NetworkInterface current = interfaces.nextElement();
-
- if (!current.isUp() || current.isLoopback()
- || current.isVirtual())
- continue;
- ifList.add(current.getName());
- }
+ public static List<String> getInterfaceList() {
+ List<String> result = new ArrayList<String>();
+ //FIXME: support only ethX for base network
+ List<String> cmd = Arrays.asList("/bin/sh", "-c", "/bin/ls /sys/class/net | /bin/grep eth");
+ ProcessResult res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == false) {
+ EMLogger.getLogger().warning(
+ "Get tap list fail. Command returns fail:" + "cmd : "
+ + cmd.toString() + ", return : "
+ + res.getExitValue());
+ return null;
+ } else {
+ for (String line : res.getStdOutMsg()) {
+ result.add(line.trim());
}
- // Except bridges in list
- List<String> brList = TapUtil.getBridgeList();
- for (String str : ifList) {
- if (!brList.contains(str)) {
- result.add(str);
- }
- }
- } catch (SocketException e) {
- EMLogger.getLogger().warning(e.getMessage());
- } catch (VMWorkerException e) {
- EMLogger.getLogger().warning(e.getMessage());
}
-
return result;
}
}
throws VMWorkerException {
boolean isBridge = property.getPropertyValue()
.getAdvancedOptionValue(ItemName.NET_CONNECT_TYPE)
- .equals("Bridge")
- && (EmulatorManager.isLinux() || EmulatorManager.isWin());
+ .equals("Bridge");
// Qemu MAC argument
config.addVariable(VAR_MAC, getMacAddr(isBridge, property));
// Qemu net argument
if (isBridge) {
- String tapName = property.getPropertyValue()
- .getAdvancedOptionValue(ItemName.NET_TAP_DEVICE);
- config.addQemuOption("-net", "tap,ifname=" + tapName + ",script=no,downscript=no");
+ if (EmulatorManager.isWin()) {
+ String tapName = property.getPropertyValue()
+ .getAdvancedOptionValue(ItemName.NET_TAP_DEVICE);
+ config.addQemuOption("-net", "tap,ifname=" + tapName
+ + ",script=no,downscript=no");
+ } else {
+ config.addQemuOption("-net",
+ "tap,script=/etc/emulator-ifup.sh,downscript=no");
+ }
}
}
public void checkArgument(VMProperty property) throws VMLauncherException {
boolean isBridge = property.getPropertyValue()
.getAdvancedOptionValue(ItemName.NET_CONNECT_TYPE)
- .equals("Bridge")
- && (EmulatorManager.isLinux() || EmulatorManager.isWin());
+ .equals("Bridge");
- if (isBridge) {
+ if (isBridge && EmulatorManager.isWin()) {
String tapName = property.getPropertyValue()
.getAdvancedOptionValue(ItemName.NET_TAP_DEVICE);
if (TapUtil.nameNotExist(tapName))