public final class PacketBuffer

  1. Object
  2. PacketBuffer

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 returns has to be copied, with toByteArray; the buffer itself belongs to the transport again the moment that call ends.

Fields

public static final int FAMILY_IPV4 = 4IPv4, as reported by getFamily.
public static final int FAMILY_IPV6 = 6IPv6, as reported by getFamily.

Methods

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

Inherited methods

Field details

FAMILY_IPV4

public static final int FAMILY_IPV4 = 4
IPv4, as reported by getFamily.

FAMILY_IPV6

public static final int FAMILY_IPV6 = 6
IPv6, as reported by getFamily.

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.