@Override
    public void write(ByteBuffer buffer) throws IOException {
        // Write to vpn.
        UdpHeader header = mTemplateHeader.copy();
        ByteBuffer headerBuffer = header.buffer();
        int headLength = header.getIpHeader().getHeaderLength() + header.getHeaderLength();
        byte[] packet = new byte[headLength + buffer.remaining()];
        headerBuffer.get(packet, 0, headLength);
        buffer.get(packet, headLength, packet.length - headLength);

        IpHeader ipHeader = new IpHeader(packet, 0);
        ipHeader.setTotalLength((short) packet.length);

        UdpHeader udpHeader = new UdpHeader(ipHeader, packet, ipHeader.getHeaderLength());
        udpHeader.setTotalLength((short) (packet.length - ipHeader.getHeaderLength()));

        ipHeader.updateChecksum();
        udpHeader.updateChecksum();

        mOutput.write(packet, 0, packet.length);

        mSession.receiveDataSize += packet.length;
    }
UDP protocol virtual gateway tunnel wraps {@link UdpRemoteTunnel} and itself as client and
server.

@author Megatron King
@since 2018-11-25 20:16
netbare-core/src/main/java/com/github/megatronking/netbare/tunnel/UdpVATunnel.java