PingOptions.Ttl 属性

定义

获取或设置在放弃 Ping 数据之前可以转发该数据的路由节点数。

public:
 property int Ttl { int get(); void set(int value); };
public int Ttl { get; set; }
member this.Ttl : int with get, set
Public Property Ttl As Integer

属性值

一个 Int32 值,指定 Ping 数据包可被转发的次数。 默认值为 128。

例外

为设置操作指定的值小于或等于零。

示例

下面的代码示例演示如何使用 PingOptions 构造函数设置此属性的值,然后显示值。

// Set options for transmission:
// The data can go through 64 gateways or routers
// before it is destroyed, and the data packet
// cannot be fragmented.
PingOptions ^ options = gcnew PingOptions( 64,true );
Console::WriteLine( "Time to live: {0}", options->Ttl );
Console::WriteLine( "Don't fragment: {0}", options->DontFragment );
// Set options for transmission:
// The data can go through 64 gateways or routers
// before it is destroyed, and the data packet
// cannot be fragmented.
PingOptions options = new PingOptions (64, true);

Console.WriteLine ("Time to live: {0}", options.Ttl);
Console.WriteLine ("Don't fragment: {0}", options.DontFragment);

注解

当网关和路由器通过网络传输数据包时,它们会递减数据包标头中找到的当前生存时间 (TTL) 值。 如果 TTL 值达到零,则数据包被视为无法送达并被丢弃。 如果要测试用于传输数据的路由器和网关的数量,此选项非常有用。

适用于