I am trying to use the built-in VpnService in Android to capture traffic and send it to a remote server. I am trying to use Netty, but it seems that I have come to an impasse.
In order to send data from the phone to the server I need to call Protect() on the socket otherwise all the data I transmit will just be looped back into the VpnService. However I am not sure if it's possible to get a hold of a Socket object or its filedescriptor when using Netty4.
you need to extends NioSocketChannel and override doConnect method:
public class ProtectedNioSocketChannel extends NioSocketChannel {
@Override
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
SocketChannel ch = javaChannel();
if(!VpnServiceHelper.protect(ch.socket())){
Log.i(Tag, "Can't protect Socket");
return false;
}
return super.doConnect(remoteAddress, localAddress);
}
and:
Bootstrap b = new Bootstrap();
b.group(localChannel.eventLoop())
.channel(ProtectedNioSocketChannel.class)
.handler(new ProxyRemoteHandler(localChannel, session))
.option(ChannelOption.AUTO_READ, false);
ChannelFuture f = b.connect(address);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.