在 Linux 上,非特权进程无法发送原始 IP 数据包。
Ping 通过与 ping
实用工具交互来实现功能。 但是,此实用工具不支持为 Internet 控制消息协议 (ICMP) ping 数据包指定自定义有效负载。 .NET 7 添加了此类情况的检查,并在指定自定义有效负载时引发异常。
以前的行为
在以前的版本中,ping 数据包有效负载在非特权 Linux 进程中被无提示忽略(即未发送)。
新行为
从 .NET 7 开始,如果在非特权 Linux 进程中运行时尝试发送自定义 ping 数据包有效负载,则会引发 PlatformNotSupportedException。
已引入的版本
.NET 7
破坏性变更的类型
此项更改可能会影响二进制兼容性。
更改原因
最好通知用户无法执行操作,而不是不提示地删除数据负载。
建议的措施
如果需要 ping 有效负载,请将应用程序作为 root
运行,或使用 cap_net_raw
实用工具授予 setcap
功能。
否则,请使用不接受自定义有效负载的 Ping.SendPingAsync 重载,或传入一个空数组。
受影响的 API
- System.Net.NetworkInformation.Ping.Send(IPAddress, Int32, Byte[], PingOptions)
- System.Net.NetworkInformation.Ping.Send(IPAddress, Int32, Byte[])
- System.Net.NetworkInformation.Ping.Send(String, Int32, Byte[], PingOptions)
- System.Net.NetworkInformation.Ping.Send(String, Int32, Byte[])
- System.Net.NetworkInformation.Ping.SendAsync(IPAddress, Int32, Byte[], PingOptions, Object)
- System.Net.NetworkInformation.Ping.SendAsync(IPAddress, Int32, Byte[], Object)
- System.Net.NetworkInformation.Ping.SendAsync(String, Int32, Byte[], PingOptions, Object)
- System.Net.NetworkInformation.Ping.SendAsync(String, Int32, Byte[], Object)
- System.Net.NetworkInformation.Ping.SendPingAsync(IPAddress, Int32, Byte[], PingOptions)
- System.Net.NetworkInformation.Ping.SendPingAsync(IPAddress, Int32, Byte[])
- System.Net.NetworkInformation.Ping.SendPingAsync(String, Int32, Byte[], PingOptions)
- System.Net.NetworkInformation.Ping.SendPingAsync(String, Int32, Byte[])