socket.setTTL(ttl)


设置 IP_TTL 套接字选项。虽然 TTL 通常代表 "生存时间",但在此上下文中,它指定了允许数据包通过的 IP 跃点数。转发数据包的每个路由或网关都会递减 TTL。如果 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.