android: Use helper to parse IP addresses where appropriate
authorTobias Brunner <tobias@strongswan.org>
Tue, 5 Mar 2019 18:02:05 +0000 (19:02 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 5 Mar 2019 18:02:05 +0000 (19:02 +0100)
src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java
src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileDetailActivity.java
src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileImportActivity.java
src/frontends/android/app/src/main/java/org/strongswan/android/utils/IPRange.java

index a43095f..3672480 100644 (file)
@@ -58,6 +58,7 @@ import org.strongswan.android.utils.Constants;
 import org.strongswan.android.utils.IPRange;
 import org.strongswan.android.utils.IPRangeSet;
 import org.strongswan.android.utils.SettingsWriter;
+import org.strongswan.android.utils.Utils;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -1117,7 +1118,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
                                {
                                        try
                                        {
-                                               mDnsServers.add(InetAddress.getByName(server));
+                                               mDnsServers.add(Utils.parseInetAddress(server));
                                                recordAddressFamily(server);
                                                mDnsServersConfigured = true;
                                        }
@@ -1156,7 +1157,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
 
                        try
                        {
-                               mDnsServers.add(InetAddress.getByName(address));
+                               mDnsServers.add(Utils.parseInetAddress(address));
                                recordAddressFamily(address);
                        }
                        catch (UnknownHostException e)
@@ -1341,7 +1342,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
 
                private boolean isIPv6(String address) throws UnknownHostException
                {
-                       InetAddress addr = InetAddress.getByName(address);
+                       InetAddress addr = Utils.parseInetAddress(address);
                        if (addr instanceof Inet4Address)
                        {
                                return false;
index ce7877e..e096587 100644 (file)
@@ -72,7 +72,6 @@ import org.strongswan.android.utils.Constants;
 import org.strongswan.android.utils.IPRangeSet;
 import org.strongswan.android.utils.Utils;
 
-import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
@@ -915,7 +914,7 @@ public class VpnProfileDetailActivity extends AppCompatActivity
                {
                        try
                        {
-                               InetAddress.getByName(addr);
+                               Utils.parseInetAddress(addr);
                        }
                        catch (UnknownHostException e)
                        {
index f1c5746..221840b 100644 (file)
@@ -65,7 +65,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.InetAddress;
 import java.net.URL;
 import java.net.UnknownHostException;
 import java.security.KeyStore;
@@ -634,7 +633,7 @@ public class VpnProfileImportActivity extends AppCompatActivity
                        {
                                try
                                {
-                                       InetAddress.getByName(addr);
+                                       Utils.parseInetAddress(addr);
                                }
                                catch (UnknownHostException e)
                                {
index 6c0aa65..e839770 100644 (file)
@@ -76,7 +76,7 @@ public class IPRange implements Comparable<IPRange>
 
        public IPRange(String from, String to) throws UnknownHostException
        {
-               this(InetAddress.getByName(from), InetAddress.getByName(to));
+               this(Utils.parseInetAddress(from), Utils.parseInetAddress(to));
        }
 
        public IPRange(InetAddress from, InetAddress to)
@@ -106,7 +106,7 @@ public class IPRange implements Comparable<IPRange>
 
        public IPRange(String base, int prefix) throws UnknownHostException
        {
-               this(InetAddress.getByName(base), prefix);
+               this(Utils.parseInetAddress(base), prefix);
        }
 
        public IPRange(InetAddress base, int prefix)