Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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?
Regards
Werner
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
Updated 21-Jul-11 2:48am
v2
Comments
Herman<T>.Instance 21-Jul-11 9:41am    
in a CMD you type ping -6 address to resolve the ip v6. So the question remains how to have the -6 added to the PingOptions.
Herman<T>.Instance 21-Jul-11 9:46am    
at least some information can be found here:
http://www.winsocketdotnetworkprogramming.com/clientserversocketnetworkcommunication8f_1a.html

1 solution

Thanks digimanus, but not enough: To set an option ipv6 i don't know, how to find out, what clients are involved: ipv4 or ipv6?
 
Share this answer
 

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