【发布时间】:2015-04-22 23:23:45
【问题描述】:
我正在尝试使用来自 android 的 VpnService 在客户端设置一个简单的 tun 设备,在接收端我有一个 c++ 服务器正在运行。
我在使用 VpnService 时遇到了很多问题。这是我需要的 我需要将所有从 Android 手机出站的数据包路由到 tun 设备,并在程序中通过数据报通道将其路由到服务器。当我发送一个字符串时,它工作正常,但是当我通过这个数据报通道发送其他数据时,我在 Wireshark 中看不到任何 UDP 数据包:\
另外,我是 Java 和 Datagram 频道的新手。这是我的代码
//To establish the tunnel
builder.setSession("MyVPNService")
.addAddress("192.168.56.0", 32)
.addDnsServer("8.8.8.4")
.addRoute("0.0.0.0", 1);
mInterface=builder.establish();
以上配置具体是做什么的? tun设备不应该有一个IP(根据我在linux上的经验),那么什么是“192.168.56.0”,32”。此外,当我尝试添加路线“0.0.0.0”时,0 整个 android 手机都会挂起并重新启动:\
while (true) {
int length;
// Read the outgoing packet from the input stream.
length=in.read(packet_bytes);
//int length = in.read(packet.array());
if (length > 0) {
// Write the outgoing packet to the tunnel.
//packet.limit(length);
//tunnel.send(packe,server);
tunnel.send(packet,server);
packet.put(packet_bytes,0,length);
tunnel.write(packet);
packet.clear();
}
Thread.sleep(200);
// Read the incoming packet from the tunnel.
length = tunnel.read(packet);
if (length > 0) {
out.write(packet.array(), 0, length);
packet.clear();
// If we were sending, switch to receiving.
}
Thread.sleep(200);
}
这是我从界面中取出并放在另一个上的部分。
【问题讨论】:
-
这会有所帮助 [1]:stackoverflow.com/questions/20269283/…
-
面临类似问题?你能解决问题吗?