PingReply.Options 屬性

定義

取得選項,用於傳送對網際網路控制訊息通訊協定 (ICMP) 回應要求的回覆。

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

屬性值

如果 PingOptionsStatus,則為 Success 物件,該物件包含用於傳送回覆的存留時間 (TTL) 及分割指示詞,否則為 null

範例

下列程式代碼範例會同步傳送ICMP回應要求,並顯示此屬性所傳回之物件中 PingOptions 儲存的值。

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 會定義節點可以在其來源和目的地之間移動時轉送封包的次數。 如果轉寄數目也稱為躍點,超過為TTL指定的值,封包會被視為無法傳遞,並捨棄。

DontFragment ICMP 回應要求中指定的值會控制封包片段。 如果 是 DontFragmenttrue 且封包大小超過封包所採用網路路徑的最大傳輸單位,則會捨棄封包並 PacketTooBig 傳回錯誤。

適用於