How to write a raw UDP Payload, but still use packetbuilder

Jul 29, 2011 at 11:39 PM

Heya, I am trying to send and create a specific packet that is a UDP Packet with a propriatary payload.

so something like the following:

    EthernetLayer ethernetLayer = new EthernetLayer
    {
        Source = new MacAddress("1:1:1:1:1:1"),
        Destination = EthernetDatagram.BroadcastAddress,     
    };

    // IPv4 Layer
    IpV4Layer ipV4Layer = new IpV4Layer
    {
        Source = new IpV4Address("169.254.10.1"),
        Destination = new IpV4Address("255.255.255.255"),
        Ttl = 64,
        Identification = 0,
        Protocol = IpV4Protocol.Udp,        
    };
    UdpLayer l_UDPLayer = new UdpLayer
    {
        SourcePort = 30001,
        DestinationPort = 30001,
        
    };
    byte[] UDPPayloadBuffer  = { 0xf0,0xf0,0xf0 };
   
    l_UDPLayer.AddPayload(UDPPayloadBuffer,UDPPayloadBuffer.Length);   // <---- does not exist work
    // Create the builder that will build our packets
    PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, l_UDPLayer);    

    // Build the packet
    Packet packet = builder.Build(DateTime.Now);           

    // Send down the packet
    communicator.SendPacket(packet);   

I don't really want to create the whole packet from Raw, so there some  easy way to do this and still be able to use PacketBuilder?

Jul 29, 2011 at 11:50 PM

Nevermind, I figured it out:

byte[] UDPPayloadBuffer  = { 0xf0,0xf0,0xf0 };

    PayloadLayer l_Payload = new PayloadLayer
    {
        Data = new Datagram(UDPPayloadBuffer),
    };
    PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, l_UDPLayer, l_Payload);