From 47d55b2f23e30e89a662e8b33358ec4e8c28a43d Mon Sep 17 00:00:00 2001 From: Iordan Iordanov Date: Sat, 21 Nov 2015 15:43:24 -0500 Subject: [PATCH] Bugfix for ipv6 addresses which the app was trying to parse as if they contain a port. --- eclipse_projects/bVNC/AndroidManifest.xml | 2 +- .../com/iiordanov/bVNC/RemoteCanvasActivity.java | 10 ++++++---- .../bVNC/src/com/iiordanov/bVNC/Utils.java | 13 +++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/eclipse_projects/bVNC/AndroidManifest.xml b/eclipse_projects/bVNC/AndroidManifest.xml index 9b92715db..957066883 100644 --- a/eclipse_projects/bVNC/AndroidManifest.xml +++ b/eclipse_projects/bVNC/AndroidManifest.xml @@ -1,7 +1,7 @@ + android:versionCode="3810" android:versionName="v3.8.1"> diff --git a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/RemoteCanvasActivity.java b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/RemoteCanvasActivity.java index 9d5a46462..7bb70dafc 100644 --- a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/RemoteCanvasActivity.java +++ b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/RemoteCanvasActivity.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; +import java.util.regex.Matcher; import android.app.Activity; import android.app.AlertDialog; @@ -207,14 +208,15 @@ void initialize () { connection.Gen_populate((ContentValues) extras.getParcelable(Constants.CONNECTION)); } - // Parse a HOST:PORT entry + // Parse a HOST:PORT entry but only if not ipv6 address String host = connection.getAddress(); - if (host.indexOf(':') > -1) { + if (!Utils.isValidIpv6Address(host) && host.indexOf(':') > -1) { String p = host.substring(host.indexOf(':') + 1); try { - connection.setPort(Integer.parseInt(p)); + int parsedPort = Integer.parseInt(p); + connection.setPort(parsedPort); + connection.setAddress(host.substring(0, host.indexOf(':'))); } catch (Exception e) {} - connection.setAddress(host.substring(0, host.indexOf(':'))); } if (connection.getPort() == 0) diff --git a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/Utils.java b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/Utils.java index 5072f0a15..04edc71ef 100644 --- a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/Utils.java +++ b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/Utils.java @@ -22,7 +22,6 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -30,6 +29,9 @@ import java.io.Reader; import java.io.Writer; import java.lang.reflect.Field; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.UnknownHostException; import org.xml.sax.SAXException; @@ -50,7 +52,6 @@ import android.view.ViewConfiguration; public class Utils { - public static void showYesNoPrompt(Context _context, String title, String message, OnClickListener onYesListener, OnClickListener onNoListener) { AlertDialog.Builder builder = new AlertDialog.Builder(_context); builder.setTitle(title); @@ -202,4 +203,12 @@ public static void importSettingsFromXml (String file, SQLiteDatabase db) throws Reader reader = new InputStreamReader(new FileInputStream(file)); SqliteElement.importXmlStreamToDb(db, reader, ReplaceStrategy.REPLACE_EXISTING); } + + public static boolean isValidIpv6Address(final String address) { + try { + return InetAddress.getByName(address) instanceof Inet6Address; + } catch (final UnknownHostException ex) { + return false; + } + } }