Helper function added that retrieves a local IP address
This commit is contained in:
@@ -17,9 +17,13 @@
|
|||||||
|
|
||||||
package org.strongswan.android.logic;
|
package org.strongswan.android.logic;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
import java.security.cert.CertificateEncodingException;
|
import java.security.cert.CertificateEncodingException;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
import org.strongswan.android.data.VpnProfile;
|
import org.strongswan.android.data.VpnProfile;
|
||||||
import org.strongswan.android.data.VpnProfileDataSource;
|
import org.strongswan.android.data.VpnProfileDataSource;
|
||||||
@@ -399,6 +403,39 @@ public class CharonVpnService extends VpnService implements Runnable
|
|||||||
*/
|
*/
|
||||||
public native void deinitializeCharon();
|
public native void deinitializeCharon();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function that retrieves a local IPv4 address.
|
||||||
|
*
|
||||||
|
* @return string representation of an IPv4 address, or null if none found
|
||||||
|
*/
|
||||||
|
private static String getLocalIPv4Address()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
|
||||||
|
while (en.hasMoreElements())
|
||||||
|
{
|
||||||
|
NetworkInterface intf = en.nextElement();
|
||||||
|
|
||||||
|
Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();
|
||||||
|
while (enumIpAddr.hasMoreElements())
|
||||||
|
{
|
||||||
|
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||||
|
if (!inetAddress.isLoopbackAddress() && inetAddress.getAddress().length == 4)
|
||||||
|
{
|
||||||
|
return inetAddress.getHostAddress().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SocketException ex)
|
||||||
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The libraries are extracted to /data/data/org.strongswan.android/...
|
* The libraries are extracted to /data/data/org.strongswan.android/...
|
||||||
* during installation.
|
* during installation.
|
||||||
|
|||||||
Reference in New Issue
Block a user