Sending ICMPv6 Echo Request

1.3k Views Asked by At

How can I send an ICMPv6 Echo Request Message in C#? Further I'd need to appoint the actual bandwidth, RTT, MTU on path using IPv6 (There is no DF flag in IPv6 packet) and the Packet Loss.

1

There are 1 best solutions below

0
On

Have you tried the System.Net.NetworkInformation.Ping class? The Send() method returns a PingReply object which contains status and round-trip time. Not sure if you can pull other information out of it (haven't ever needed to).

Under the hood, Ping uses Windows IP Helper Functions (http://msdn.microsoft.com/en-us/library/windows/desktop/aa366071%28v=VS.85%29.aspx) such as Icmp6SendEcho2. You might be able to get more information than the Ping wrapper class exposes by using those functions directly, e.g.:

[DllImport("iphlpapi.dll", SetLastError = true)]
internal static uint Icmp6SendEcho2(SafeCloseIcmpHandle icmpHandle, SafeWaitHandle Event, IntPtr apcRoutine, IntPtr apcContext, byte[] sourceSocketAddress, byte[] destSocketAddress, [In] SafeLocalFree data, ushort dataSize, ref IPOptions options, SafeLocalFree replyBuffer, uint replySize, uint timeout);

(where 'replyBuffer' is an ICMPV6_ECHO_REPLY struct - http://msdn.microsoft.com/en-us/library/windows/desktop/bb485842%28v=VS.85%29.aspx)

Not sure if there's a way to get MTU or the true total bandwidth, but hopefully this is at least a start!