socket.getTypeOfService()


返回此套接字的 IPv4 数据包的当前服务类型 (TOS) 字段或 IPv6 数据包的流量类别 (Traffic Class)。

🌐 Returns the current Type of Service (TOS) field for IPv4 packets or Traffic Class for IPv6 packets for this socket.

setTypeOfService() 可能在套接字连接之前被调用;该值将被缓存,并在套接字建立连接时应用。 getTypeOfService() 即使在连接之前也会返回当前设置的值。

在某些平台(例如 Linux)上,某些 TOS/ECN 位可能会被屏蔽或忽略,并且行为在 IPv4 和 IPv6 或双栈套接字之间可能有所不同。调用者应验证特定平台的语义。

🌐 On some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored, and behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers should verify platform-specific semantics.