Custom ping payloads on Linux

On Linux, non-privileged processes can't send raw IP packets. Ping functionality is implemented by interfacing with the ping utility. However, this utility doesn't support specifying a custom payload for the Internet Control Message Protocol (ICMP) ping packets. .NET 7 adds a check for such cases and throws an exception if a custom payload is specified.

Previous behavior

In previous versions, the ping packet payload was silently ignored (that is, it wasn't sent) on non-privileged Linux processes.

New behavior

Starting in .NET 7, a PlatformNotSupportedException is thrown if you attempt to send a custom ping packet payload when running in non-privileged Linux process.

Version introduced

.NET 7

Type of breaking change

This change can affect binary compatibility.

Reason for change

It's better to signal to the user that the operation cannot be performed instead of silently dropping the payload.

If a ping payload is necessary, run the application as root, or grant the cap_net_raw capability using the setcap utility.

Otherwise, use an overload of Ping.SendPingAsync that does not accept a custom payload, or pass in an empty array.

Affected APIs