This project is read-only.

Sending packets with timestamp

Sep 22, 2011 at 10:24 PM
Edited Sep 23, 2011 at 2:01 AM

I am trying to send packets using timestamps and running into difficulties getting accurate sub-1ms timing.  I stripped my code down to the sample on sending ping packets as shown:


            // Send Pings to different destination with different parameters
            for (int i = 0; i != 10; ++i)
                // Set IPv4 parameters
                ipV4Layer.Destination = new IpV4Address("2.3.4." + i);
                ipV4Layer.Identification = (ushort)i;

                // Set ICMP parameters
                icmpLayer.SequenceNumber = (ushort)i;
                icmpLayer.Identifier = (ushort)i;

                // Build the packet.  Ticks are 100ns * 10 = us
                deltaTime = DateTime.Now.AddTicks(10 * 800 * i);
                Packet packet = builder.Build(deltaTime);

                // Send down the packet
            IfaceEthernet.sendBuffer(sendbuf, true); //respect the timestamp



If I set the number of microseconds above 1000, I get evenly spaced packets out.  If I set it below 1000 (say 800 like the example above), every other packet gets sent immediately (~8 us delta between).  If I set it to 1500 usec, the packet spacing alternates between 1ms and 2ms.  The user guide talks about getting accurate packet timing, but it doesn't look possible to get timing below 1 ms using TimeDate.

Is there another approach, rather than using AddTicks to get sub-ms timing of packets?  I need around 25 usec timing. 

Using C# 2010 Express.

Thanks in advance for any help.




Sep 23, 2011 at 1:19 AM
Edited Sep 23, 2011 at 1:59 AM

Edited post above
Sep 24, 2011 at 9:20 AM

Hi drcorenlius,


After looking at the code, I've found out that it seems I have a bug in translating DateTime to WinPcap's timestamp.

Thank you for finding this, I hope to have it fix in the next version.