PingReply.Options 属性

定义

获取用于将答复传输到 Internet 控制消息协议 (ICMP) 回送请求的选项。Gets the options used to transmit the reply to an Internet Control Message Protocol (ICMP) echo request.

public:
 property System::Net::NetworkInformation::PingOptions ^ Options { System::Net::NetworkInformation::PingOptions ^ get(); };
public System.Net.NetworkInformation.PingOptions? Options { get; }
public System.Net.NetworkInformation.PingOptions Options { get; }
member this.Options : System.Net.NetworkInformation.PingOptions
Public ReadOnly Property Options As PingOptions

属性值

PingOptions

如果 PingOptionsStatus,则为一个包含生存时间 (TTL) 和用于传输答复的分段指令的 Success 对象;否则为 nullA PingOptions object that contains the Time to Live (TTL) and the fragmentation directive used for transmitting the reply if Status is Success; otherwise, null.

示例

下面的代码示例同步发送 ICMP 回送请求,并显示此属性返回的对象中存储的值 PingOptionsThe following code example sends an ICMP echo request synchronously and displays the values stored in the PingOptions object returned by this property.

void LocalPing()
{
   
   // Ping's the local machine.
   Ping ^ pingSender = gcnew Ping;
   IPAddress^ address = IPAddress::Loopback;
   PingReply ^ reply = pingSender->Send( address );
   if ( reply->Status == IPStatus::Success )
   {
      Console::WriteLine( "Address: {0}", reply->Address->ToString() );
      Console::WriteLine( "RoundTrip time: {0}", reply->RoundtripTime );
      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 );
   }
   else
   {
      Console::WriteLine( reply->Status );
   }
}


public static void LocalPing ()
{
    // Ping's the local machine.
    Ping pingSender = new Ping ();
    IPAddress address = IPAddress.Loopback;
    PingReply reply = pingSender.Send (address);

    if (reply.Status == IPStatus.Success)
    {
        Console.WriteLine ("Address: {0}", reply.Address.ToString ());
        Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
        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);
    }
    else
    {
        Console.WriteLine (reply.Status);
    }
}

注解

TTL 定义节点在其源和目标之间传输时可以转发数据包的次数。The TTL defines the number of times nodes can forward a packet as it travels between its source and destination. 如果正向的数量(也称为 "跃点")超过了为 TTL 指定的值,则认为数据包不可传递并且被丢弃。If the number of forwards, also known as hops, exceeds the value specified for the TTL, the packet is deemed undeliverable and is discarded.

DontFragmentICMP echo 请求中指定的值控制数据包的碎片。The DontFragment value specified in the ICMP echo request controls packet fragmentation. 如果 DontFragment 为, true 并且数据包大小超过数据包所使用的网络路径的最大传输单位,则丢弃数据包并 PacketTooBig 返回错误。If DontFragment is true and the packet size exceeds the maximum transmission unit of the network path taken by the packet, the packet is discarded and the PacketTooBig error is returned.

适用于