Revision: 36c325e95878
Branch: default
Author: rjmatthews62
Date: Thu Jun 27 19:15:45 2013
Log: Fix to force localhost to be ipv4
http://code.google.com/p/android-scripting/source/detail?r=36c325e95878
Modified:
/android/ScriptingLayerForAndroid/AndroidManifest.xml
/android/Utils/src/com/googlecode/android_scripting/SimpleServer.java
=======================================
--- /android/ScriptingLayerForAndroid/AndroidManifest.xml Sun Dec 9
16:04:59 2012
+++ /android/ScriptingLayerForAndroid/AndroidManifest.xml Thu Jun 27
19:15:45 2013
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"
package="com.googlecode.android_scripting" android:installLocation="auto"
- android:versionCode="601" android:versionName="6x01">
+ android:versionCode="602" android:versionName="6x02">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission
android:name="net.dinglisch.android.tasker.PERMISSION_RUN_TASKS" />
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
=======================================
--- /android/Utils/src/com/googlecode/android_scripting/SimpleServer.java
Sat Apr 28 02:02:27 2012
+++ /android/Utils/src/com/googlecode/android_scripting/SimpleServer.java
Thu Jun 27 19:15:45 2013
@@ -116,6 +116,29 @@
public int getNumberOfConnections() {
return mConnectionThreads.size();
}
+
+ public static InetAddress getPrivateInetAddress() throws
UnknownHostException, SocketException {
+
+ InetAddress candidate = null;
+ Enumeration<NetworkInterface> nets =
NetworkInterface.getNetworkInterfaces();
+ for (NetworkInterface netint : Collections.list(nets)) {
+ if (!netint.isLoopback() || !netint.isUp()) { // Ignore if localhost
or not active
+ continue;
+ }
+ Enumeration<InetAddress> addresses = netint.getInetAddresses();
+ for (InetAddress address : Collections.list(addresses)) {
+ if (address instanceof Inet4Address) {
+ Log.d("local address " + address);
+ return address; // Prefer ipv4
+ }
+ candidate = address; // Probably an ipv6
+ }
+ }
+ if (candidate != null) {
+ return candidate; // return ipv6 address if no suitable ipv6
+ }
+ return InetAddress.getLocalHost(); // No damn matches. Give up, return
local host.
+ }
public static InetAddress getPublicInetAddress() throws
UnknownHostException, SocketException {
@@ -150,7 +173,8 @@
public InetSocketAddress startLocal(int port) {
InetAddress address;
try {
- address = InetAddress.getLocalHost();
+ // address = InetAddress.getLocalHost();
+ address = getPrivateInetAddress();
mServer = new ServerSocket(port, 5 /* backlog */, address);
} catch (Exception e) {
Log.e("Failed to start server.", e);