【发布时间】:2015-04-26 06:32:36
【问题描述】:
我正在尝试为 android 实施无根防火墙。我已经解决了关于 SO 的所有相关问题,但没有找到答案:
在这里我正在配置我的 vpn。
private void configure() {
// 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.
Builder builder = new Builder();
builder.setMtu(1500);
builder.addAddress("192.168.178.90", 24);
//builder.addAddress("10.0.2.0", 32);
//builder.addDnsServer("8.8.8.8");
builder.addRoute("0.0.0.0", 0); // to intercept packets
try {
mInterface.close();
} catch (Exception e) {
// ignore
}
mInterface = builder.establish();
}
然后我尝试将数据发送到目标地址
byte[] data= new byte[pdata.data.capacity()];
pdata.data.get(data);
Socket s = new Socket(pdata.destAddr,pdata.destPort);
if(shouldBeBlocked(pdata.destAddr)) {
sendResult("blocked: "+ pdata.destAddr.toString()+":"+pdata.destPort);
} else {
sendResult(pdata.destAddr.toString()+":"+pdata.destPort);
if (protect(s)) {
...
但线程在 Socket 的构造函数上冻结,然后像这样 rasinig IOException:
java.net.ConnectException: failed to connect to /173.194.71.100 (port 443): connect failed: ETIMEDOUT (Connection timed out)
【问题讨论】:
-
您是否检查过您是否在目标端接收到任何数据?你能用wireshark之类的东西来查看数据包丢失的地方或超时的来源吗?
-
@MattKo
ConnectException在我可以发送任何数据之前被抛出。这是Socket s = new Socket(pdata.destAddr,pdata.destPort);行
标签: java android sockets vpn firewall