Sending UDP packet as buffer

Jan 10, 2012 at 8:22 PM
Edited Jan 12, 2012 at 1:53 AM



I am using the Example which sends a Ping 100 times.
Instead of this I would like it to send a UDP packet 100 times.

Could I get some assistence on the code?

Jan 12, 2012 at 1:55 AM
Edited Jan 13, 2012 at 1:00 AM

Here in the example I changed the output to 111.111.111.x

and the source from my own IP.
And it was indeed working in WireShark. I saw outgoing PINGS (ICMP Protocol). But unfortunately not UDP packets.
Could I get some help?

Jan 12, 2012 at 8:46 AM

Try and use UdpLayer instead of IcmpLayer.

Jan 13, 2012 at 1:00 AM
Edited Jan 13, 2012 at 2:48 AM

Thank you, but now I want to change a 100xnormal UDP packet to a buffer so it continues and I can do my testing with wireshark.

I tried this, but it didn't work

Replaced this [Which is working]

               for (int i = 0; i != 100; ++i)
                    // Set IPv4 parameters
                    ipV4Layer.Destination = new IpV4Address("111.111.111." + i);
                    ipV4Layer.Identification = (ushort)i;

                    Udplayer.DestinationPort = 100;
                    Udplayer.SourcePort = 80;

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

                    // Send down the packet
With this [Not working]
long capLength = new FileInfo(args[0]).Length;
                using (PacketSendBuffer sendBuffer = new PacketSendBuffer((uint)capLength))
                    ipV4Layer.Destination = new IpV4Address("");
                    ipV4Layer.Identification = 101;

                    Udplayer.DestinationPort = 100;
                    Udplayer.SourcePort = 80;

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

                    string s = "on";
                    while (s == "on")
When running, this gives an error: Make sure that the maximum index on a list is less than the list size. But I don't know if it just this problem or the buffer is not correct. 
long capLength = new FileInfo(args[0]).Length;
Im not sure if the code above is alright on sending an UDP buffer.
Thanks for the help already sir Brickner.
Jan 14, 2012 at 1:53 PM
Edited Jan 14, 2012 at 1:54 PM

Hi qwerz,


What is the value of capLength?

It should be big enough to hold all the packets you enqueue in this buffer.


Also, you just create the buffer and fill it but you don't actually send the packets.

You should use PacketCommunicator::Transmit() method.


Also, consider not using PacketSendBuffer, until everything works for you.

It adds complications and I'm not sure your performance requirements actually need it.


I hope this helps,



Jan 15, 2012 at 4:53 AM

Thanks, Ill think about the capLength, I didnt knew what it was but now I know.

And yes I forgot to send the packets with the Transmit Method. Ill add this too.

-And if I may ask, What do you mean with "not using PacketSendBuffer"?
Because if I dont use PacketSendBuffer line, it won't be a buffer?
So you actually mean that I should use normal standalone packets instead of buffer?

Well My purpose is to send packets as fast as possible and as many as possible.

-I am aiming on 3-5k Packets per second. Do you think this is achievable without using a buffer (of each 100 packets or so)?

-If not, will using a buffer (with 100packets?) make 3-5k PPS achievable?

-I noticed that the smallest packet is like 80bytes. So a Ping and empty UDP packet is the same size. So there is no difference in speed if I use let's say ping(ICMP) instead of UDP

Thanks, hope you would like to answere these 4 questions. I am learning everyday more about and networking.

Jan 15, 2012 at 3:22 PM

- Yes, that's what I meant. I think that development wise, it seems better to first see that you manage to send the packets you want and then see how to get to the speed you need.

- The buffer might help you with the speed, but I think it might be more dependent on you network device.

- The smallest Ethernet packet is 64 bytes long. Don't see a reason for speed difference between sending UDP and ICMP.


I hope this helps,