protected static Ethernet_Frame createEthernetFrame(RawSocketChannel pnChannel, ProfinetDriverContext driverContext, DceRpc_Packet packet) {
        InetSocketAddress localAddress = (InetSocketAddress) pnChannel.getLocalAddress();
        InetSocketAddress remoteAddress = (InetSocketAddress) pnChannel.getRemoteAddress();

        // Serialize it to a byte-payload
        Random rand = new Random();
        Ethernet_FramePayload_IPv4 udpFrame = new Ethernet_FramePayload_IPv4(
            rand.nextInt(65536),
            true,
            false,
            (short) 64,
            new IpAddress(localAddress.getAddress().getAddress()),
            new IpAddress(remoteAddress.getAddress().getAddress()),
            driverContext.getLocalPort(),
            driverContext.getRemotePortImplicitCommunication(),
            packet
        );
        MacAddress srcAddress = new MacAddress(pnChannel.getLocalMacAddress().getAddress());
        MacAddress dstAddress = new MacAddress(pnChannel.getRemoteMacAddress().getAddress());
        return new Ethernet_Frame(
            dstAddress,
            srcAddress,
            udpFrame);
    }
Simple helper that creates the UDP packet and Ethernet frame to transport the packet.

@param pnChannel     the channel that contains the local and remote address information.
@param driverContext the context that contains the local and remote port information.
@param packet        the actual payload.
@return an Ethernet frame that we can send.
plc4j/drivers/profinet-ng/src/main/java/org/apache/plc4x/java/profinet/packets/PnDcpPacketFactory.java