socket.setTTL(ttl)


设置 IP_TTL 套接字选项。虽然 TTL 通常代表“生存时间”,在此上下文中它指定了一个数据包允许经过的 IP 跳数。每个转发数据包的路由或网关都会将 TTL 减 1。如果某个路由将 TTL 减至 0,该数据包将不会被转发。更改 TTL 值通常用于网络探测或组播时。

【Sets the IP_TTL socket option. While TTL generally stands for "Time to Live", in this context it specifies the number of IP hops that a packet is allowed to travel through. Each router or gateway that forwards a packet decrements the TTL. If the TTL is decremented to 0 by a router, it will not be forwarded. Changing TTL values is typically done for network probes or when multicasting.】

ttl 参数可以介于 1 到 255 之间。大多数系统的默认值是 64。

【The ttl argument may be between 1 and 255. The default on most systems is 64.】

如果在未绑定的套接字上调用此方法,会抛出 EBADF 异常。

【This method throws EBADF if called on an unbound socket.】