Class PacketBuffer

java.lang.Object
com.codename1.vpn.tunnel.PacketBuffer

public final class PacketBuffer extends Object

One IP packet on its way through the tunnel.

These are REUSED

The transport hands the same buffers back round rather than allocating per packet, because a packet loop allocating at line rate is the fastest way to exhaust the memory a tunnel host is given. A packet you want after VpnTunnel.onPacket(PacketBuffer) returns has to be copied, with toByteArray(); the buffer itself belongs to the transport again the moment that call ends.

  • Field Details

  • Method Details

    • getData

      public byte[] getData()

      The bytes this packet lives in, which extend beyond it.

      Read between getOffset() and getOffset() + getLength(); the rest is whatever the previous packet left.

    • getOffset

      public int getOffset()
      Where this packet starts in getData().
    • getLength

      public int getLength()
      How many bytes this packet occupies.
    • getFamily

      public int getFamily()

      FAMILY_IPV4 or FAMILY_IPV6.

      Android does not report it alongside the packet, so there it is read from the header's version nibble; a host that does report it says so directly. Either way it is the same answer, which is why it is a field here rather than something each tunnel works out again.

    • toByteArray

      public byte[] toByteArray()
      A copy of just this packet, for keeping past onPacket.