title: Android VpnService Configuration
body: <p>I am trying to use the VpnService from android to setup a simple tun device on the client side and on the receiving side I have a c++ server running. </p>
  
  <p>I am having a lot of problems with the VpnService. This is what I need, 
  I need ALL packets outbound from the Android phone to be routed to the tun device, and in the program I route it through a Datagram channel to the server. When I send a string, it works fine, but when I send other data through this Datagram channel, i don't see any UDP packets in Wireshark :\</p>
  
  <p>Also, I am new to Java and Datagram channels. Here Is my code</p>
  
  <pre><code>//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();
  </code></pre>
  
  <p>What exactly are the above configurations doing? Isn't a tun device supposed to have ONE IP(from my experience from doing it on linux), then what is ""192.168.56.0", 32". Also when i try to add a route "0.0.0.0", 0 the whole android phone hangs and restarts :\</p>
  
  <pre><code>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 &gt; 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 &gt; 0) {
  
                      out.write(packet.array(), 0, length);
  
                      packet.clear();
  
                      // If we were sending, switch to receiving.
                  }
                  Thread.sleep(200);
              }
  </code></pre>
  
  <p>This is the part where I take it from interface and put it on the other. </p>