List of usage examples for android.net VpnService.Builder addAddress
public boolean addAddress(InetAddress address, int prefixLength)
From source file:de.flyingsnail.ipv6droid.android.VpnThread.java
/** * Setup VpnService.Builder object (in effect, the local tun device) * @param builder the Builder to configure * @param tunnelSpecification the TicTunnel specification of the tunnel to set up. *//*ww w .j a v a 2s . co m*/ private void configureBuilderFromTunnelSpecification(VpnService.Builder builder, TicTunnel tunnelSpecification) { builder.setMtu(tunnelSpecification.getMtu()); builder.setSession(tunnelSpecification.getPopName()); builder.addAddress(tunnelSpecification.getIpv6Endpoint(), tunnelSpecification.getPrefixLength()); try { if (routingConfiguration.isSetDefaultRoute()) builder.addRoute(Inet6Address.getByName("::"), 0); else { String routeDefinition = routingConfiguration.getSpecificRoute(); StringTokenizer tok = new StringTokenizer(routeDefinition, "/"); Inet6Address address = (Inet6Address) Inet6Address.getByName(tok.nextToken()); int prefixLen = 128; if (tok.hasMoreTokens()) prefixLen = Integer.parseInt(tok.nextToken()); builder.addRoute(address, prefixLen); } } catch (UnknownHostException e) { Log.e(TAG, "Could not add requested IPv6 route to builder", e); postToast(ayiyaVpnService.getApplicationContext(), R.id.vpnservice_route_not_added, Toast.LENGTH_SHORT); } // register an intent to call up main activity from system managed dialog. Intent configureIntent = new Intent("android.intent.action.MAIN"); configureIntent.setClass(ayiyaVpnService.getApplicationContext(), MainActivity.class); configureIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); builder.setConfigureIntent( PendingIntent.getActivity(ayiyaVpnService.getApplicationContext(), 0, configureIntent, 0)); Log.i(TAG, "Builder is configured"); }