# 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 Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `FAMILY_IPV4`
  IPv4, as reported by `getFamily()`.
  `static final int`
  `FAMILY_IPV6`
  IPv6, as reported by `getFamily()`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `byte[]`
  `getData()`
  The bytes this packet lives in, which extend beyond it.
  `int`
  `getFamily()`
  `FAMILY_IPV4` or `FAMILY_IPV6`.
  `int`
  `getLength()`
  How many bytes this packet occupies.
  `int`
  `getOffset()`
  Where this packet starts in `getData()`.
  `byte[]`
  `toByteArray()`
  A copy of just this packet, for keeping past `onPacket`.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### FAMILY_IPV4

    public static final int FAMILY_IPV4
    IPv4, as reported by `getFamily()`.
    See Also:
      - Constant Field Values

  - ### FAMILY_IPV6

    public static final int FAMILY_IPV6
    IPv6, as reported by `getFamily()`.
    See Also:
      - Constant Field Values

- ## 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`.