@Override
    public void forward(byte[] packet, int len, OutputStream output) {
        IpHeader ipHeader = new IpHeader(packet, 0);
        UdpHeader udpHeader = new UdpHeader(ipHeader, packet, ipHeader.getHeaderLength());

        // Src IP & Port
        int localIp = ipHeader.getSourceIp();
        short localPort = udpHeader.getSourcePort();

        // Dest IP & Port
        int remoteIp = ipHeader.getDestinationIp();
        short remotePort = udpHeader.getDestinationPort();

        // UDP data size
        int udpDataSize = ipHeader.getDataLength() - udpHeader.getHeaderLength();

        NetBareLog.v("ip: %s:%d -> %s:%d", NetBareUtils.convertIp(localIp),
                NetBareUtils.convertPort(localPort), NetBareUtils.convertIp(remoteIp),
                NetBareUtils.convertPort(remotePort));
        NetBareLog.v("udp: %s, size: %d", udpHeader.toString(), udpDataSize);

        Session session = mSessionProvider.ensureQuery(Protocol.UDP, localPort, remotePort, remoteIp);
        session.packetIndex++;

        try {
            mProxyServer.send(udpHeader, output);
            session.sendDataSize += udpDataSize;
        } catch (IOException e) {
            NetBareLog.e(e.getMessage());
        }
    }
Unlike TCP proxy server, UDP doesn't need handshake, we can forward packets to it directly.

@author Megatron King
@since 2018-10-09 01:30
netbare-core/src/main/java/com/github/megatronking/netbare/proxy/UdpProxyServerForwarder.java