Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
My research for a ping-solution for my software lead me to msdn and i got the solution at the end of my article. All works fine except a ping between two win7/ipv6-machines: The reply.Options-object is empty(null)!
Does anybody know why?
How do i get the reply.Options?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;
 
namespace TestPing
{
  class Program
  {
  // args[0] can be an IPaddress or host name.
  public static void Main(string[] args)
  {
    Ping pingSender = new Ping();
    PingOptions options = new PingOptions();
    // Use the default Ttl value which is 128,
    // but change the fragmentation behavior.
    options.DontFragment = true;
 
    // Create a buffer of 32 bytes of data to be transmitted.
    string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    byte[] buffer = Encoding.ASCII.GetBytes(data);
    int timeout = 120;
    try
    {
    PingReply reply = pingSender.Send(args[0], timeout, buffer, options);
    Console.WriteLine("reply.Status {0} {1}", args[0], reply.Status.ToString());
    if (reply.Status == IPStatus.Success)
    {
      Console.WriteLine("Address: {0}", reply.Address.ToString());
      Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
   if (reply.Options != null) // reply.Status==Success but reply.Options is empty
            // for a ping from ipv6-adress to ipv6-adresses
      {
      Console.WriteLine("reply.Options:");
      Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
      Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
      }
      Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
    }
    }
    catch(Exception ex)
    {
    Console.WriteLine("Exception {0}", ex.InnerException.Message);
    }
  }
 
 
  }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900