当前位置: 首页>>代码示例>>Java>>正文


Java VpnService.Builder方法代码示例

本文整理汇总了Java中android.net.VpnService.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java VpnService.Builder方法的具体用法?Java VpnService.Builder怎么用?Java VpnService.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.VpnService的用法示例。


在下文中一共展示了VpnService.Builder方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newDNSServer

import android.net.VpnService; //导入方法依赖的package包/类
void newDNSServer(VpnService.Builder builder, String format, byte[] ipv6Template, InetAddress addr) throws UnknownHostException {
    // Optimally we'd allow either one, but the forwarder checks if upstream size is empty, so
    // we really need to acquire both an ipv6 and an ipv4 subnet.
    if (addr instanceof Inet6Address && ipv6Template == null) {
        Log.i(TAG, "newDNSServer: Ignoring DNS server " + addr);
    } else if (addr instanceof Inet4Address && format == null) {
        Log.i(TAG, "newDNSServer: Ignoring DNS server " + addr);
    } else if (addr instanceof Inet4Address) {
        upstreamDnsServers.add(addr);
        String alias = String.format(format, upstreamDnsServers.size() + 1);
        Log.i(TAG, "configure: Adding DNS Server " + addr + " as " + alias);
        builder.addDnsServer(alias);
        builder.addRoute(alias, 32);
        vpnWatchDog.setTarget(InetAddress.getByName(alias));
    } else if (addr instanceof Inet6Address) {
        upstreamDnsServers.add(addr);
        ipv6Template[ipv6Template.length - 1] = (byte) (upstreamDnsServers.size() + 1);
        InetAddress i6addr = Inet6Address.getByAddress(ipv6Template);
        Log.i(TAG, "configure: Adding DNS Server " + addr + " as " + i6addr);
        builder.addDnsServer(i6addr);
        vpnWatchDog.setTarget(i6addr);
    }
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:24,代码来源:AdVpnThread.java

示例2: addDefaultRoutes

import android.net.VpnService; //导入方法依赖的package包/类
private void addDefaultRoutes(VpnService.Builder b, LibOpenConnect.IPInfo ip, ArrayList<String> subnets) {
	boolean ip4def = true, ip6def = true;

	for (String s : subnets) {
		if (s.contains(":")) {
			ip6def = false;
		} else {
			ip4def = false;
		}
	}

	if (ip4def && ip.addr != null) {
		b.addRoute("0.0.0.0", 0);
		log("ROUTE: 0.0.0.0/0");
	}

	if (ip6def && ip.netmask6 != null) {
		b.addRoute("::", 0);
		log("ROUTE: ::/0");
	}
}
 
开发者ID:cernekee,项目名称:ics-openconnect,代码行数:22,代码来源:OpenConnectManagementThread.java

示例3: configure

import android.net.VpnService; //导入方法依赖的package包/类
private void configure(String parameters) throws Exception {
    // If the old interface has exactly the same parameters, use it!
    if (mInterface != null) {
        Log.i(TAG, "Using the previous interface");
        return;
    }

    // Configure a builder while parsing the parameters.
    VpnService.Builder builder = new VpnService.Builder();

    builder.addAddress(mTunAddress, mTunPrefixLen);
    Log.i(TAG, "set tunnel address: " + mTunAddress + "/" + mTunPrefixLen);
    builder.setMtu(mMTU);
    // add US routes
    builder.addRoute("0.0.0.0", 0);
    builder.addDnsServer("8.8.8.8");

    // Close the old interface since the parameters have been changed.
    try {
        mInterface.close();
    } catch (Exception e) {
        // ignore
    }

    // Create a new interface using the builder and save the parameters.
    mInterface = builder.setSession(mServerAddress)
            .setConfigureIntent(mConfigureIntent)
            .establish();
    //mParameters = parameters;
    Log.i(TAG, "New interface: " + parameters);
}
 
开发者ID:boytm,项目名称:minivtun-android,代码行数:32,代码来源:MinivtunService.java

示例4: onCreate

import android.net.VpnService; //导入方法依赖的package包/类
@Override
public void onCreate() {
	super.onCreate();
	builder = new VpnService.Builder();
	builder.addAddress(VPN_ADDRESS, 32);
	builder.addRoute(VPN_ROUTE, 0);
	builder.establish();
}
 
开发者ID:comp500,项目名称:SSLSocks,代码行数:9,代码来源:StunnelVpnService.java

示例5: addSubnetRoutes

import android.net.VpnService; //导入方法依赖的package包/类
private void addSubnetRoutes(VpnService.Builder b, LibOpenConnect.IPInfo ip, ArrayList<String> subnets) {
	for (String s : subnets) {
		s = s.trim();
		try {
			if (s.contains(":")) {
				String ss[] = s.split("/");
				if (ss.length == 1) {
					b.addRoute(ss[0], 128);
				} else {
					b.addRoute(ss[0], Integer.parseInt(ss[1]));
				}
				log("ROUTE: " + s);
			} else {
				CIDRIP cdr;
				if (!s.contains("/")) {
					cdr = new CIDRIP(s + "/32");
				} else {
					cdr = new CIDRIP(s);
				}
				b.addRoute(cdr.mIp, cdr.len);
				log("ROUTE: " + cdr.mIp + "/" + cdr.len);
			}
		} catch (Exception e) {
			log("ROUTE: skipping invalid route '" + s + "'");
		}
	}
}
 
开发者ID:cernekee,项目名称:ics-openconnect,代码行数:28,代码来源:OpenConnectManagementThread.java

示例6: setMtu

import android.net.VpnService; //导入方法依赖的package包/类
@Override
public VpnService.Builder setMtu(int mtu) {
    this.mtu = mtu;
    super.setMtu(mtu);
    return this;
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:7,代码来源:ServiceSinkhole.java

示例7: getVpnServiceBuilder

import android.net.VpnService; //导入方法依赖的package包/类
public Builder getVpnServiceBuilder() {
	VpnService.Builder b = new VpnService.Builder();
	b.setSession(profile.mName);
	b.setConfigureIntent(getMainActivityIntent());
	return b;
}
 
开发者ID:cernekee,项目名称:ics-openconnect,代码行数:7,代码来源:OpenVpnService.java


注:本文中的android.net.VpnService.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。