Android VpnService Package Blocks

Edit: - I can start internet using vpn. The other problems are that I am now receiving packets in my service in this code snippet of my VpnService . But I can not think about the correct way to block a specific site. I've tried name resolution using InnetAddress but not giving the expected result:

   **@Override
    public void run()
    {
        Log.i(TAG, "Started");
        FileChannel vpnInput = new FileInputStream(vpnFileDescriptor).getChannel();
        FileChannel vpnOutput = new FileOutputStream(vpnFileDescriptor).getChannel();
        try
        {
            ByteBuffer bufferToNetwork = null;
            boolean dataSent = true;
            boolean dataReceived;
            while (!Thread.interrupted())
            {
                if (dataSent)
                    bufferToNetwork = ByteBufferPool.acquire();
                int readBytes = vpnInput.read(bufferToNetwork);
                if (readBytes > 0)
                {
                    dataSent = true;
                    bufferToNetwork.flip();
                    Packet packet = new Packet(bufferToNetwork);
                    Log.e("loggg packet",packet.toString());
                    if (packet.isUDP())
                    {
                        deviceToNetworkUDPQueue.offer(packet);
                    }
                    else if (packet.isTCP())
                    {
                        deviceToNetworkTCPQueue.offer(packet);
                    }
                    else
                    {
                        Log.w(TAG, "Unknown packet type");
                        dataSent = false;
                    }
                }
                else
                {
                    dataSent = false;
                }
                ByteBuffer bufferFromNetwork = networkToDeviceQueue.poll();
                if (bufferFromNetwork != null)
                {
                    bufferFromNetwork.flip();
                    vpnOutput.write(bufferFromNetwork);
                    dataReceived = true;
                    ByteBufferPool.release(bufferFromNetwork);
                }
                else
                {
                    dataReceived = false;
                }
                if (!dataSent && !dataReceived)
                    Thread.sleep(10);
            }
        }
        catch (InterruptedException e)
        {
            Log.i(TAG, "Stopping");
        }
        catch (IOException e)
        {
            Log.w(TAG, e.toString(), e);
        }
        finally
        {
            closeResources(vpnInput, vpnOutput);
        }
    }**

      

I get the package in this format:

Packet{ip4Header=IP4Header{version=4, totalLength=40, protocol=TCP,     headerChecksum=14192, sourceAddress=10.0.8.1, destinationAddress=216.58.196.100},   tcpHeader=TCPHeader{sourcePort=39217, destinationPort=443,  sequenceNumber=800911985, acknowledgementNumber=823271551, headerLength=20,     window=29596, checksum=32492, flags= ACK}, payloadSize=0}

      

I am using THIS CODE to run and cannot block packages.

Apps like greyshirts no root firewall and mobiwool no root firewall works great and they are also vpn based. Any suggestion is greatly appreciated.

+3


source to share





All Articles